powerpc: Link with -z notext
PATCH 1/1 powerpc: Link with -z notext
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").
--- powerpc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
powerpc/Makefile +1 -1
@@ -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 \
base-commit: 5a221342a025948fa7d84f0c404748f6ba57f3ad
Signature · 1 line
2.54.0 (Apple Git-157)
Am 10.11.26 um 16:44 schrieb Amit Machhiwal:
Quoted 4 lines
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
Hi!
This does not happen for me (using GNU ld version 2.46.1-1.fc44 from Fedora 44) ... which compiler and distro are you using?
Thomas
Hi Thomas,
Quoted 9 lines · Thomas Huth
Am 10.11.26 um 16:44 schrieb Amit Machhiwal:
Quoted 4 lines
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 relocationsHi!
This does not happen for me (using GNU ld version 2.46.1-1.fc44 from Fedora
44) ... which compiler and distro are you using?
Thanks for checking!
I'm also using the same GNU ld version on Fedora 44 PPC64LE host (more details are below). Are you cross compiling on an x86 host by any chance where you are not seeing this problem?
Assuming that you are, the difference is due to the default linker configuration between native and cross-compilation packages on Fedora:
On native Fedora 44 ppc64le:
----------------------------
$ ld --help | grep -E '\-z (no)?text'
-z text Treat DT_TEXTREL in output as error (default)
-z notext Don't treat DT_TEXTREL in output as error
-z textoff Don't treat DT_TEXTREL in output as errorOn Fedora x86_64 cross-linker (powerpc64le-linux-gnu-ld):
---------------------------------------------------------
$ powerpc64le-linux-gnu-ld --help | grep -E '\-z (no)?text'
-z text Treat DT_TEXTREL in output as error
-z notext Don't treat DT_TEXTREL in output as error (default)
-z textoff Don't treat DT_TEXTREL in output as error (default)Because the cross-linker defaults to -z notext, cross-compiling on x86_64 succeeds silently, whereas native builds fail:
/usr/bin/ld.bfd: error: read-only segment has dynamic relocations
Toolchain & host details (ppc64le native):
------------------------------------------
$ uname -a Linux fedora 7.3.3-200.fc44.ppc64le #1 SMP PREEMPT_DYNAMIC Fri Nov 6 20:22:11 UTC 2026 ppc64le GNU/Linux
$ ld --version GNU ld version 2.46.1-1.fc44
Thanks,
Amit
Am 11.11.26 um 11:18 schrieb Amit Machhiwal:
Quoted 10 lines
Hi Thomas,
Quoted 7 lines · Thomas Huth
Am 10.11.26 um 16:44 schrieb Amit Machhiwal:
Quoted 4 lines
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 relocationsHi!
Quoted 8 lines
Quoted 2 lines
This does not happen for me (using GNU ld version 2.46.1-1.fc44 from Fedora
44) ... which compiler and distro are you using?Thanks for checking!
I'm also using the same GNU ld version on Fedora 44 PPC64LE host (more details are below). Are you cross compiling on an x86 host by any chance where you are not seeing this problem?
Yes, I was cross-compiling, so that's likely the reason why I did not see the issue.
Anyway, could you please check the following patch to see whether it fixes the issue for you, too:
https://lore.kernel.org/kvm/[email protected]/
... that compiles the powerpc code with "-fpie" in the CFLAGS, so I think it should cure the issue, too, and it's likely the better way instead of suppressing the warnings with "-z notext".
Thomas
Am 13.11.26 um 13:03 schrieb Thomas Huth:
Quoted 20 lines
Am 11.11.26 um 11:18 schrieb Amit Machhiwal:
Quoted 10 lines
Hi Thomas,
Quoted 7 lines · Thomas Huth
Am 10.11.26 um 16:44 schrieb Amit Machhiwal:
Quoted 4 lines
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 relocationsHi!
Quoted 8 lines
Quoted 2 lines
This does not happen for me (using GNU ld version 2.46.1-1.fc44 from Fedora
44) ... which compiler and distro are you using?Thanks for checking!
I'm also using the same GNU ld version on Fedora 44 PPC64LE host (more details are below). Are you cross compiling on an x86 host by any chance where you are not seeing this problem?
Quoted 7 lines
Yes, I was cross-compiling, so that's likely the reason why I did not see the issue.
Anyway, could you please check the following patch to see whether it fixes the issue for you, too:
https://lore.kernel.org/kvm/[email protected]/
... that compiles the powerpc code with "-fpie" in the CFLAGS, so I think it should cure the issue, too, and it's likely the better way instead of suppressing the warnings with "-z notext".
I was finally able to get access to a ppc64 machine, and my patch is apparently causing other trouble there:
/usr/bin/ld.bfd: powerpc/cstart64.o: warning: relocation againststackptr' in read-only section .init'
So I went ahead and pushed your patch with "-z notext" instead to have at least a workaround 'til we figured out whether we can and want to push the "-pie" flag to the cpu-specific folders or not.
Thomas
Am 10.11.26 um 16:44 schrieb Amit Machhiwal:
Quoted 24 lines
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 relocationsThe tests are linked with -pie and relocate themselves at boot (see
relocate()inpowerpc/reloc64.c, called frompowerpc/cstart64.S). Newer GNU ld rejects relocations in read-only segments by default. TheMakefilealready checks after linking that onlyR_PPC64_RELATIVErelocations are present.Fix this by adding
-z notextto the powerpc linker flags, as was done for arm64 in commit5d67db4e1860("arm64: Link with -z notext").Signed-off-by Amit Machhiwal <[email protected]>--- powerpc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)powerpc/Makefile +0
-0
powerpc/Makefile include $(SRCDIR)/scripts/asm-offsets.mak · line 84
Quoted 8 lines
powerpc/Makefile +1
-1@@ -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