Am 10.11.26 um 16:44 schrieb Amit Machhiwal:
Building the powerpc tests with GNU ld 2.46.1 fails when linking the
test binaries:
/usr/bin/ld.bfd: error: read-only segment has dynamic relocations
The tests are linked with -pie and relocate themselves at boot (see
relocate() in powerpc/reloc64.c, called from powerpc/cstart64.S).
Newer GNU ld rejects relocations in read-only segments by default. The
Makefile already checks after linking that only R_PPC64_RELATIVE
relocations are present.
Fix this by adding `-z notext` to the powerpc linker flags, as was done
for arm64 in commit 5d67db4e1860 ("arm64: Link with -z notext").
Signed-off-by: Amit Machhiwal <[email protected]>
---
powerpc/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/powerpc/Makefile b/powerpc/Makefile
index 41e752b070bc..35fe58835726 100644
--- a/powerpc/Makefile
+++ b/powerpc/Makefile
@@ -78,7 +78,7 @@ include $(SRCDIR)/scripts/asm-offsets.mak
FLATLIBS = $(libcflat) $(LIBFDT_archive)
%.elf: CFLAGS += $(arch_CFLAGS)
-%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n
+%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n -z notext
%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o)
%.aux.o
$(LD) $(LDFLAGS) -o $@ \
-T $(SRCDIR)/powerpc/flat.lds --build-id=none \
Another thought: Why are we only using -pie for the LDFLAGS, but we rather
seem to compile with -fno-pic in the CFLAGS? That looks weird ... I guess
the -fno-pic is required for certain targets (s390x and the non-EFI builds
of the other targets?), but maybe we should only add it only where it is
required and compile the targets that have relocation code with -fpie in the
CFLAGS instead?
Thomas