Skip to contentSkip to conversation

arm64: Link with -z notext

PATCH Applied Ricardo Koller 2 participants 2 messages Aug 19, 2021 – Aug 31, 2021 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Link with -z notext

Building the tests on arm64 fails when using LLD (the LLVM linker):

ld.lld: error: can't create dynamic relocation R_AARCH64_ABS64 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

defined in lib/libcflat.a(processor.o)
referenced by processor.c
processor.o:(vector_names) in archive lib/libcflat.a

The reason is that LLD defaults to errors for text relocations. The GNU LD defaults to let it go. In fact, the same error can be reproduced when using GNU LD with the '-z text' arg (to error on text relocations):

aarch64-linux-gnu-ld: read-only segment has dynamic relocations

Fix this link error by adding -z notext into the arm64 linker flags.

---
 arm/Makefile.arm64 | 1 +
 1 file changed, 1 insertion(+)
arm/Makefile.arm64 +1 -0
index dbc7524..e8a38d7 100644
@@ -7,6 +7,7 @@ bits = 64
 ldarch = elf64-littleaarch64
 
 arch_LDFLAGS = -pie -n
+arch_LDFLAGS += -z notext
 CFLAGS += -mstrict-align
 
 mno_outline_atomics := $(call cc-option, -mno-outline-atomics, "")
Signature · 1 line
2.33.0.rc2.250.ged5fa647cd-goog
Applied
#1 lore raw
Quoted 37 lines · Ricardo Koller

Building the tests on arm64 fails when using LLD (the LLVM linker):

ld.lld: error: can't create dynamic relocation R_AARCH64_ABS64 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

defined in lib/libcflat.a(processor.o)
referenced by processor.c
processor.o:(vector_names) in archive lib/libcflat.a

The reason is that LLD defaults to errors for text relocations. The GNU LD defaults to let it go. In fact, the same error can be reproduced when using GNU LD with the '-z text' arg (to error on text relocations):

aarch64-linux-gnu-ld: read-only segment has dynamic relocations

Fix this link error by adding -z notext into the arm64 linker flags.

---
 arm/Makefile.arm64 | 1 +
 1 file changed, 1 insertion(+)
arm/Makefile.arm64 +1 -0
index dbc7524..e8a38d7 100644
@@ -7,6 +7,7 @@ bits = 64
 ldarch = elf64-littleaarch64
 
 arch_LDFLAGS = -pie -n
+arch_LDFLAGS += -z notext
 CFLAGS += -mstrict-align
 
 mno_outline_atomics := $(call cc-option, -mno-outline-atomics, "")
Signature · 1 line
2.33.0.rc2.250.ged5fa647cd-goog

Applied to arm/queue and merged to master.

Thanks,
drew