[PATCH] arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y

Tom Rini trini at konsulko.com
Tue Jun 29 14:38:10 CEST 2021


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 at denx.de>
> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko at socionext.com>
> Acked-by: Marek Vasut <marex at denx.de>
> Tested-by: Marek Vasut <marex at denx.de>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210629/c7ab6426/attachment.sig>


More information about the U-Boot mailing list