Re: [PATCH v3 3/4] arm64: Add support for larger PIE U-Boot

2020-09-10 Thread Michal Simek



On 09. 09. 20 19:07, Edgar E. Iglesias wrote:
> From: "Edgar E. Iglesias" 
> 
> Linking a U-Boot larger than 1MB fails with PIE enabled:
> u-boot/arch/arm/cpu/armv8/start.S:71:(.text+0x3c): relocation
> truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol `__rel_dyn_end'
> defined in .bss_start section in u-boot.
> 
> This extends the supported range by using adrp & add to load symbols
> early while starting up.
> 
> Signed-off-by: Edgar E. Iglesias 
> ---
>  arch/arm/cpu/armv8/start.S | 6 --
>  arch/arm/lib/crt0_64.S | 8 +++-
>  2 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
> index 85baebc5f7..e5c2856cf5 100644
> --- a/arch/arm/cpu/armv8/start.S
> +++ b/arch/arm/cpu/armv8/start.S
> @@ -84,8 +84,10 @@ pie_fixup:
>   adr x0, _start  /* x0 <- Runtime value of _start */
>   ldr x1, _TEXT_BASE  /* x1 <- Linked value of _start */
>   sub x9, x0, x1  /* x9 <- Run-vs-link offset */
> - adr x2, __rel_dyn_start /* x2 <- Runtime &__rel_dyn_start */
> - adr x3, __rel_dyn_end   /* x3 <- Runtime &__rel_dyn_end */
> + adrpx2, __rel_dyn_start /* x2 <- Runtime &__rel_dyn_start */
> + add x2, x2, #:lo12:__rel_dyn_start
> + adrpx3, __rel_dyn_end   /* x3 <- Runtime &__rel_dyn_end */
> + add x3, x3, #:lo12:__rel_dyn_end
>  pie_fix_loop:
>   ldp x0, x1, [x2], #16   /* (x0, x1) <- (Link location, fixup) */
>   ldr x4, [x2], #8/* x4 <- addend */
> diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
> index 04afa518ac..9d2319c0e8 100644
> --- a/arch/arm/lib/crt0_64.S
> +++ b/arch/arm/lib/crt0_64.S
> @@ -73,7 +73,12 @@ ENTRY(_main)
>  #elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
>   ldr x0, =(CONFIG_SPL_STACK)
>  #elif defined(CONFIG_INIT_SP_RELATIVE)
> +#if CONFIG_POSITION_INDEPENDENT
> + adrpx0, __bss_start /* x0 <- Runtime &__bss_start */
> + add x0, x0, #:lo12:__bss_start
> +#else
>   adr x0, __bss_start
> +#endif
>   add x0, x0, #CONFIG_SYS_INIT_SP_BSS_OFFSET
>  #else
>   ldr x0, =(CONFIG_SYS_INIT_SP_ADDR)
> @@ -102,7 +107,8 @@ ENTRY(_main)
>   adr lr, relocation_return
>  #if CONFIG_POSITION_INDEPENDENT
>   /* Add in link-vs-runtime offset */
> - adr x0, _start  /* x0 <- Runtime value of _start */
> + adrpx0, _start  /* x0 <- Runtime value of _start */
> + add x0, x0, #:lo12:_start
>   ldr x9, _TEXT_BASE  /* x9 <- Linked value of _start */
>   sub x9, x9, x0  /* x9 <- Run-vs-link offset */
>   add lr, lr, x9
> 

Signed-off-by: Michal Simek 
Tested-by: Michal Simek 

Thanks,
Michal


[PATCH v3 3/4] arm64: Add support for larger PIE U-Boot

2020-09-09 Thread Edgar E. Iglesias
From: "Edgar E. Iglesias" 

Linking a U-Boot larger than 1MB fails with PIE enabled:
u-boot/arch/arm/cpu/armv8/start.S:71:(.text+0x3c): relocation
truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol `__rel_dyn_end'
defined in .bss_start section in u-boot.

This extends the supported range by using adrp & add to load symbols
early while starting up.

Signed-off-by: Edgar E. Iglesias 
---
 arch/arm/cpu/armv8/start.S | 6 --
 arch/arm/lib/crt0_64.S | 8 +++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index 85baebc5f7..e5c2856cf5 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -84,8 +84,10 @@ pie_fixup:
adr x0, _start  /* x0 <- Runtime value of _start */
ldr x1, _TEXT_BASE  /* x1 <- Linked value of _start */
sub x9, x0, x1  /* x9 <- Run-vs-link offset */
-   adr x2, __rel_dyn_start /* x2 <- Runtime &__rel_dyn_start */
-   adr x3, __rel_dyn_end   /* x3 <- Runtime &__rel_dyn_end */
+   adrpx2, __rel_dyn_start /* x2 <- Runtime &__rel_dyn_start */
+   add x2, x2, #:lo12:__rel_dyn_start
+   adrpx3, __rel_dyn_end   /* x3 <- Runtime &__rel_dyn_end */
+   add x3, x3, #:lo12:__rel_dyn_end
 pie_fix_loop:
ldp x0, x1, [x2], #16   /* (x0, x1) <- (Link location, fixup) */
ldr x4, [x2], #8/* x4 <- addend */
diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
index 04afa518ac..9d2319c0e8 100644
--- a/arch/arm/lib/crt0_64.S
+++ b/arch/arm/lib/crt0_64.S
@@ -73,7 +73,12 @@ ENTRY(_main)
 #elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
ldr x0, =(CONFIG_SPL_STACK)
 #elif defined(CONFIG_INIT_SP_RELATIVE)
+#if CONFIG_POSITION_INDEPENDENT
+   adrpx0, __bss_start /* x0 <- Runtime &__bss_start */
+   add x0, x0, #:lo12:__bss_start
+#else
adr x0, __bss_start
+#endif
add x0, x0, #CONFIG_SYS_INIT_SP_BSS_OFFSET
 #else
ldr x0, =(CONFIG_SYS_INIT_SP_ADDR)
@@ -102,7 +107,8 @@ ENTRY(_main)
adr lr, relocation_return
 #if CONFIG_POSITION_INDEPENDENT
/* Add in link-vs-runtime offset */
-   adr x0, _start  /* x0 <- Runtime value of _start */
+   adrpx0, _start  /* x0 <- Runtime value of _start */
+   add x0, x0, #:lo12:_start
ldr x9, _TEXT_BASE  /* x9 <- Linked value of _start */
sub x9, x9, x0  /* x9 <- Run-vs-link offset */
add lr, lr, x9
-- 
2.25.1