u-boot-brain/arch
Kunihiko Hayashi 534f0fbd65 arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y
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>
2021-06-28 14:47:10 -04:00
..
arc global_data: Ensure we have <config.h> when symbols are not in Kconfig yet 2021-06-23 08:45:03 -04:00
arm arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y 2021-06-28 14:47:10 -04:00
m68k global_data: Ensure we have <config.h> when symbols are not in Kconfig yet 2021-06-23 08:45:03 -04:00
microblaze lmb: move CONFIG_LMB in Kconfig 2021-04-22 14:09:45 -04:00
mips MIPS: remove deprecated qemu_mips board 2021-05-25 15:35:06 +02:00
nds32 global_data: Ensure we have <config.h> when symbols are not in Kconfig yet 2021-06-23 08:45:03 -04:00
nios2 common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
powerpc Revert "powerpc: fix regression in arch_initr_trap()" 2021-06-23 08:45:03 -04:00
riscv riscv: andes_plic: Fix riscv_get_ipi() mask 2021-06-17 09:39:46 +08:00
sandbox net: use the same alias stem for ethernet as linux 2021-06-18 11:29:17 +03:00
sh lmb: move CONFIG_LMB in Kconfig 2021-04-22 14:09:45 -04:00
x86 x86: Discard .note.gnu.property sections 2021-06-23 17:21:14 +08:00
xtensa treewide: Convert macro and uses of __section(foo) to __section("foo") 2021-05-24 14:21:30 -04:00
.gitignore
Kconfig ARM: make LTO available 2021-05-24 14:21:30 -04:00
u-boot-elf.lds arch: Add explicit linker script for u-boot-elf 2020-04-03 11:52:55 -04:00