From: Tom Rini <trini@konsulko.com>
To: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Cc: u-boot@lists.denx.de, Stephen Warren <swarren@nvidia.com>,
Michal Simek <michal.simek@xilinx.com>,
Joe Hershberger <joe.hershberger@ni.com>,
Marek Vasut <marex@denx.de>
Subject: Re: [PATCH] arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y
Date: Tue, 29 Jun 2021 08:38:10 -0400 [thread overview]
Message-ID: <20210629123810.GW9516@bill-the-cat> (raw)
In-Reply-To: <1623738782-10072-1-git-send-email-hayashi.kunihiko@socionext.com>
[-- Attachment #1: Type: text/plain, Size: 1483 bytes --]
On Tue, Jun 15, 2021 at 03:33:02PM +0900, 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>
> Acked-by: Marek Vasut <marex@denx.de>
> Tested-by: Marek Vasut <marex@denx.de>
Applied to u-boot/master, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
prev parent reply other threads:[~2021-06-29 12:38 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
2021-06-29 12:38 ` Tom Rini [this message]
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=20210629123810.GW9516@bill-the-cat \
--to=trini@konsulko.com \
--cc=hayashi.kunihiko@socionext.com \
--cc=joe.hershberger@ni.com \
--cc=marex@denx.de \
--cc=michal.simek@xilinx.com \
--cc=swarren@nvidia.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