public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 3/3] arm64: Add support for larger PIE U-boot
Date: Fri, 4 Sep 2020 15:11:27 +0200	[thread overview]
Message-ID: <20200904131127.GR14249@toto> (raw)
In-Reply-To: <a07411ba-9474-f936-fee8-a6b848aba661@xilinx.com>

On Fri, Sep 04, 2020 at 03:04:02PM +0200, Michal Simek wrote:
> 
> 
> On 04. 09. 20 11:07, Edgar E. Iglesias wrote:
> > From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
> > 
> > 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 <edgar.iglesias@xilinx.com>
> > ---
> >  arch/arm/cpu/armv8/start.S | 6 ++++--
> >  arch/arm/lib/crt0_64.S     | 3 ++-
> >  2 files changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
> > index 732bc385d4..335783014c 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 */
> > +	adrp    x2, __rel_dyn_start     /* x2 <- Runtime &__rel_dyn_start */
> > +	add     x2, x2, #:lo12:__rel_dyn_start
> > +	adrp    x3, __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..f28071a238 100644
> > --- a/arch/arm/lib/crt0_64.S
> > +++ b/arch/arm/lib/crt0_64.S
> > @@ -102,7 +102,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 */
> > +	adrp	x0, _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
> > 
> 
> I have tested 21MB and 51MB u-boot and there is need to also patch
> __bss_start.
> 
> 
> --- 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
> +       adrp    x0, __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)
> 

Thanks Michal, I can bundle this into v3.

Cheers,
Edgar

  reply	other threads:[~2020-09-04 13:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04  9:07 [PATCH v2 0/3] arm64: Large PIE fixes Edgar E. Iglesias
2020-09-04  9:07 ` [PATCH v2 1/3] arm64: Mention 4K aligned load addresses in the PIE Kconfig help Edgar E. Iglesias
2020-09-04 18:42   ` Stephen Warren
2020-09-06 22:16     ` André Przywara
2020-09-07  9:58       ` Edgar E. Iglesias
2020-09-04  9:07 ` [PATCH v2 2/3] arm64: Bail out PIE builds early if load address is not 4K aligned Edgar E. Iglesias
2020-09-04 18:43   ` Stephen Warren
2020-09-07  9:52     ` Edgar E. Iglesias
2020-09-07 12:57       ` Tom Rini
2020-09-07 13:40         ` Edgar E. Iglesias
2020-09-08 19:02       ` Stephen Warren
2020-09-04  9:07 ` [PATCH v2 3/3] arm64: Add support for larger PIE U-boot Edgar E. Iglesias
2020-09-04 13:04   ` Michal Simek
2020-09-04 13:11     ` Edgar E. Iglesias [this message]
2020-09-04 18:45   ` Stephen Warren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200904131127.GR14249@toto \
    --to=edgar.iglesias@xilinx.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox