U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>, u-boot@lists.denx.de
Cc: Stephen Warren <swarren@nvidia.com>,
	Michal Simek <michal.simek@xilinx.com>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH] arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y
Date: Sun, 27 Jun 2021 03:42:34 +0200	[thread overview]
Message-ID: <bbe65e38-ebf7-85a4-29dd-0403f4a296f8@denx.de> (raw)
In-Reply-To: <1623738782-10072-1-git-send-email-hayashi.kunihiko@socionext.com>

On 6/15/21 8:33 AM, Kunihiko Hayashi wrote:
> If both POSITION_INDEPENDENT and SYS_RELOC_GD_ENV_ADDR are enabled,
> wherever original env is placed anywhere, it should be relocated to
> the right address.
> 
> Relocation offset gd->reloc_off is calculated with SYS_TEXT_BASE in
> setup_reloc() and env address gd->env_addr is relocated by the offset in
> initr_reloc_global_data().
> 
> gd->env_addr
>    = (orig env) + gd->reloc_off
>    = (orig env) + (gd->relocaddr - SYS_TEXT_BASE)
> 
> However, SYS_TEXT_BASE isn't always runtime base address when
> POSITION_INDEPENDENT is enabled. So the relocated env_addr might point to
> wrong address. For example, if SYS_TEXT_BASE is zero, gd->env_addr is
> out of memory location and memory exception will occur.
> 
> There is a difference between linked address such as SYS_TEXT_BASE and
> runtime base address. In _main, the difference is calculated as
> "run-vs-link" offset. The env_addr should also be added to the offset
> to fix the address.
> 
> gd->env_addr
>    = (orig env) + ("run-vs-link" offset)   + gd->reloc_off
>    = (orig env) + (SYS_TEXT_BASE - _start) + (gd->relocaddr - SYS_TEXT_BASE)
>    = (orig env) + (gd->relocaddr - _start)
> 
> Cc: Marek Vasut <marex@denx.de>
> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>

Thank you for debugging and fixing this properly.

Acked-by: Marek Vasut <marex@denx.de>
Tested-by: Marek Vasut <marex@denx.de>

I did manage to reproduce it on RCar3, and this patch fixes the crash on 
boot indeed.

Tom, it would be good to include it in this release too.

  reply	other threads:[~2021-06-27  1:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15  6:33 [PATCH] arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y Kunihiko Hayashi
2021-06-27  1:42 ` Marek Vasut [this message]
2021-06-29 12:38 ` Tom Rini

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=bbe65e38-ebf7-85a4-29dd-0403f4a296f8@denx.de \
    --to=marex@denx.de \
    --cc=hayashi.kunihiko@socionext.com \
    --cc=joe.hershberger@ni.com \
    --cc=michal.simek@xilinx.com \
    --cc=swarren@nvidia.com \
    --cc=trini@konsulko.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