Re: [U-Boot] [PATCH 3/4] arm64: Non-manual relocation
On Sat, 2013-10-05 at 00:13 +0800, FengHua wrote: > > diff --git a/include/configs/vexpress_aemv8a.h > > b/include/configs/vexpress_aemv8a.h > > index 01c95f5..3932e00 100644 > > --- a/include/configs/vexpress_aemv8a.h > > +++ b/include/configs/vexpress_aemv8a.h > > @@ -10,6 +10,9 @@ > > > > #define DEBUG > > > > +#define CONFIG_REMAKE_ELF > > +#define CONFIG_STATIC_RELA > > + > CONFIG_STATIC_RELA is always needed, How about remove this macro. It's always needed for arm64, but not for all architectures. I don't want to just use CONFIG_ARM64 because in theory another arch could be added that needs it. Eventually this should be moved out of the board config and into a file that defines general arm64 stuff. -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 3/4] arm64: Non-manual relocation
> This turns off CONFIG_NEEDS_MANUAL_RELOC and turns on -pie. > > The bss part of the linker script is changed to be more like arm32, > as the previous arm64 approach was generating bad relocations (even > readelf didn't like them). > > relocate_64.S is made to look more like relocate.S, and then changed to > support RELA style relocations rather than REL. > > Signed-off-by: Scott Wood > --- > arch/arm/config.mk| 2 -- > arch/arm/cpu/armv8/config.mk | 1 - > arch/arm/cpu/armv8/u-boot.lds | 32 +++--- > arch/arm/include/asm/config.h | 5 - > arch/arm/lib/crt0_64.S| 7 ++- > arch/arm/lib/relocate_64.S| 41 > --- > include/configs/vexpress_aemv8a.h | 3 +++ > 7 files changed, 51 insertions(+), 40 deletions(-) > > diff --git a/arch/arm/config.mk b/arch/arm/config.mk > index 95c07ad..96d2d88 100644 > --- a/arch/arm/config.mk > +++ b/arch/arm/config.mk > @@ -74,9 +74,7 @@ endif > endif > > # needed for relocation > -ifndef CONFIG_ARM64 > LDFLAGS_u-boot += -pie > -endif > > # > # FIXME: binutils versions < 2.22 have a bug in the assembler where > diff --git a/arch/arm/cpu/armv8/config.mk b/arch/arm/cpu/armv8/config.mk > index 9f36d59..027a68c 100644 > --- a/arch/arm/cpu/armv8/config.mk > +++ b/arch/arm/cpu/armv8/config.mk > @@ -13,4 +13,3 @@ PLATFORM_NO_UNALIGNED := $(PF_NO_UNALIGNED) > PF_CPPFLAGS_ARMV8 := $(call cc-option, -march=armv8-a) > PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARMV8) > PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED) > -PLATFORM_CPPFLAGS += -fpic > diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds > index 328d477..4c1 100644 > --- a/arch/arm/cpu/armv8/u-boot.lds > +++ b/arch/arm/cpu/armv8/u-boot.lds > @@ -41,25 +41,43 @@ SECTIONS > } > > . = ALIGN(8); > - .reloc : { > - __rel_got_start = .; > - *(.got) > - __rel_got_end = .; > - } > > .image_copy_end : > { > *(.__image_copy_end) > } > > + . = ALIGN(8); > + > + .rel_dyn_start : > + { > + *(.__rel_dyn_start) > + } > + > + .rela.dyn : { > + *(.rela*) > + } > + > + .rel_dyn_end : > + { > + *(.__rel_dyn_end) > + } > + > _end = .; > > . = ALIGN(8); > + > + .bss_start : { > + KEEP(*(.__bss_start)); > + } > + > .bss : { > - __bss_start = .; > *(.bss*) >. = ALIGN(8); > - __bss_end = .; > + } > + > + .bss_end : { > + KEEP(*(.__bss_end)); > } > > /DISCARD/ : { *(.dynsym) } > diff --git a/arch/arm/include/asm/config.h b/arch/arm/include/asm/config.h > index 0ee131d..de4d01e 100644 > --- a/arch/arm/include/asm/config.h > +++ b/arch/arm/include/asm/config.h > @@ -11,11 +11,6 @@ > #define CONFIG_SYS_BOOT_RAMDISK_HIGH > > #ifdef CONFIG_ARM64 > -/* > - * Currently, GOT is used to relocate u-boot and > - * configuration CONFIG_NEEDS_MANUAL_RELOC is needed. > - */ > -#define CONFIG_NEEDS_MANUAL_RELOC > #define CONFIG_PHYS_64BIT > #endif > > diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S > index ddd46eb..7756396 100644 > --- a/arch/arm/lib/crt0_64.S > +++ b/arch/arm/lib/crt0_64.S > @@ -94,11 +94,8 @@ relocation_return: > /* > * Clear BSS section > */ > - ldr x9, [x18, #GD_RELOC_OFF]/* x9 <- gd->reloc_off */ > - ldr x0, =__bss_start > - add x0, x0, x9 /* x0 <- __bss_start in RAM */ > - ldr x1, =__bss_end > - add x1, x1, x9 /* x1 <- __bss_end in RAM */ > + ldr x0, =__bss_start/* this is auto-relocated! */ > + ldr x1, =__bss_end /* this is auto-relocated! */ > mov x2, #0 > clear_loop: > str x2, [x0] > diff --git a/arch/arm/lib/relocate_64.S b/arch/arm/lib/relocate_64.S > index 29c3239..7fba9e2 100644 > --- a/arch/arm/lib/relocate_64.S > +++ b/arch/arm/lib/relocate_64.S > @@ -16,40 +16,41 @@ > * void relocate_code (addr_moni) > * > * This function relocates the monitor code. > - * > - * NOTE: > - * GOT is used and configuration CONFIG_NEEDS_MANUAL_RELOC is needed. > + * x0 holds the destination address. > */ > ENTRY(relocate_code) > /* >* Copy u-boot from flash to RAM >*/ > - ldr x1, =__image_copy_start /* x1 <- copy source */ > - cmp x1, x0 > + ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */ > + subsx9, x0, x1 /* x9 <- relocation offset */ > b.eqrelocate_done /* skip relocation */ > - mov x2, x0 /* x2 <- copy destination */ > - ldr x3, =__image_copy_end /* x3 <- source end address */ > + ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */ > > copy_loop: > ldp x10,
[U-Boot] [PATCH 3/4] arm64: Non-manual relocation
This turns off CONFIG_NEEDS_MANUAL_RELOC and turns on -pie. The bss part of the linker script is changed to be more like arm32, as the previous arm64 approach was generating bad relocations (even readelf didn't like them). relocate_64.S is made to look more like relocate.S, and then changed to support RELA style relocations rather than REL. Signed-off-by: Scott Wood --- arch/arm/config.mk| 2 -- arch/arm/cpu/armv8/config.mk | 1 - arch/arm/cpu/armv8/u-boot.lds | 32 +++--- arch/arm/include/asm/config.h | 5 - arch/arm/lib/crt0_64.S| 7 ++- arch/arm/lib/relocate_64.S| 41 --- include/configs/vexpress_aemv8a.h | 3 +++ 7 files changed, 51 insertions(+), 40 deletions(-) diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 95c07ad..96d2d88 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -74,9 +74,7 @@ endif endif # needed for relocation -ifndef CONFIG_ARM64 LDFLAGS_u-boot += -pie -endif # # FIXME: binutils versions < 2.22 have a bug in the assembler where diff --git a/arch/arm/cpu/armv8/config.mk b/arch/arm/cpu/armv8/config.mk index 9f36d59..027a68c 100644 --- a/arch/arm/cpu/armv8/config.mk +++ b/arch/arm/cpu/armv8/config.mk @@ -13,4 +13,3 @@ PLATFORM_NO_UNALIGNED := $(PF_NO_UNALIGNED) PF_CPPFLAGS_ARMV8 := $(call cc-option, -march=armv8-a) PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARMV8) PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED) -PLATFORM_CPPFLAGS += -fpic diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds index 328d477..4c1 100644 --- a/arch/arm/cpu/armv8/u-boot.lds +++ b/arch/arm/cpu/armv8/u-boot.lds @@ -41,25 +41,43 @@ SECTIONS } . = ALIGN(8); - .reloc : { - __rel_got_start = .; - *(.got) - __rel_got_end = .; - } .image_copy_end : { *(.__image_copy_end) } + . = ALIGN(8); + + .rel_dyn_start : + { + *(.__rel_dyn_start) + } + + .rela.dyn : { + *(.rela*) + } + + .rel_dyn_end : + { + *(.__rel_dyn_end) + } + _end = .; . = ALIGN(8); + + .bss_start : { + KEEP(*(.__bss_start)); + } + .bss : { - __bss_start = .; *(.bss*) . = ALIGN(8); - __bss_end = .; + } + + .bss_end : { + KEEP(*(.__bss_end)); } /DISCARD/ : { *(.dynsym) } diff --git a/arch/arm/include/asm/config.h b/arch/arm/include/asm/config.h index 0ee131d..de4d01e 100644 --- a/arch/arm/include/asm/config.h +++ b/arch/arm/include/asm/config.h @@ -11,11 +11,6 @@ #define CONFIG_SYS_BOOT_RAMDISK_HIGH #ifdef CONFIG_ARM64 -/* - * Currently, GOT is used to relocate u-boot and - * configuration CONFIG_NEEDS_MANUAL_RELOC is needed. - */ -#define CONFIG_NEEDS_MANUAL_RELOC #define CONFIG_PHYS_64BIT #endif diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S index ddd46eb..7756396 100644 --- a/arch/arm/lib/crt0_64.S +++ b/arch/arm/lib/crt0_64.S @@ -94,11 +94,8 @@ relocation_return: /* * Clear BSS section */ - ldr x9, [x18, #GD_RELOC_OFF]/* x9 <- gd->reloc_off */ - ldr x0, =__bss_start - add x0, x0, x9 /* x0 <- __bss_start in RAM */ - ldr x1, =__bss_end - add x1, x1, x9 /* x1 <- __bss_end in RAM */ + ldr x0, =__bss_start/* this is auto-relocated! */ + ldr x1, =__bss_end /* this is auto-relocated! */ mov x2, #0 clear_loop: str x2, [x0] diff --git a/arch/arm/lib/relocate_64.S b/arch/arm/lib/relocate_64.S index 29c3239..7fba9e2 100644 --- a/arch/arm/lib/relocate_64.S +++ b/arch/arm/lib/relocate_64.S @@ -16,40 +16,41 @@ * void relocate_code (addr_moni) * * This function relocates the monitor code. - * - * NOTE: - * GOT is used and configuration CONFIG_NEEDS_MANUAL_RELOC is needed. + * x0 holds the destination address. */ ENTRY(relocate_code) /* * Copy u-boot from flash to RAM */ - ldr x1, =__image_copy_start /* x1 <- copy source */ - cmp x1, x0 + ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */ + subsx9, x0, x1 /* x9 <- relocation offset */ b.eqrelocate_done /* skip relocation */ - mov x2, x0 /* x2 <- copy destination */ - ldr x3, =__image_copy_end /* x3 <- source end address */ + ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */ copy_loop: ldp x10, x11, [x1], #16 /* copy from source address [x1] */ - stp x10, x11, [x2], #16 /* copy to target address [x2] */ - cmp x1, x3 /* until source end address [x3] *