Skip to contentSkip to conversation

Makefile: apply dynamic relocations for LLD

PATCH In review Alistair Delva 2 participants 2 messages Sep 26, 2022 – Oct 11, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: apply dynamic relocations for LLD

From: Nick Desaulniers <[email protected]>

It seems that for aarch64, unless we apply dynamic relocations to the location being relocated, we fail to boot.

As Fangrui notes:
For dynamic relocations using the RELA format (readelf -Wr), GNU ld sets the initial content to r_addend; ld.lld doesn't do that by default (needs --apply-dynamic-relocs).

Otherwise .rodata appears to be full of NUL-bytes before relocation, causing crashes when trying to invoke the function pointers in init_sequence_f from initcall_run_list().

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 010ace9d7c..af06b7aa19 100644
@@ -1022,7 +1022,7 @@ LDFLAGS_u-boot += $(LDFLAGS_FINAL)
 LDFLAGS_u-boot += $(call ld-option, --no-dynamic-linker)
 
 # ld.lld support
-LDFLAGS_u-boot += -z notext
+LDFLAGS_u-boot += -z notext $(call ld-option,--apply-dynamic-relocs)
 
 LDFLAGS_u-boot += --build-id=none
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 14 lines · Alistair Delva

From: Nick Desaulniers <[email protected]>

It seems that for aarch64, unless we apply dynamic relocations to the location being relocated, we fail to boot.

As Fangrui notes:
For dynamic relocations using the RELA format (readelf -Wr), GNU ld sets the initial content to r_addend; ld.lld doesn't do that by default (needs --apply-dynamic-relocs).

Otherwise .rodata appears to be full of NUL-bytes before relocation, causing crashes when trying to invoke the function pointers in init_sequence_f from initcall_run_list().

Quoted 7 lines

Applied to u-boot/master, thanks!

Signature · 1 line
Tom