LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc: Link with -z notext
@ 2026-11-10 15:44 Amit Machhiwal
  2026-11-11  7:54 ` Thomas Huth
  2026-11-11  8:30 ` Thomas Huth
  0 siblings, 2 replies; 4+ messages in thread
From: Amit Machhiwal @ 2026-11-10 15:44 UTC (permalink / raw)
  To: Laurent Vivier, Thomas Huth, Madhavan Srinivasan
  Cc: Amit Machhiwal, linuxppc-dev, kvm

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 <amachhiw@linux.ibm.com>
---
 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 \

base-commit: 5a221342a025948fa7d84f0c404748f6ba57f3ad
-- 
2.54.0 (Apple Git-157)



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] powerpc: Link with -z notext
  2026-11-10 15:44 [PATCH] powerpc: Link with -z notext Amit Machhiwal
@ 2026-11-11  7:54 ` Thomas Huth
  2026-11-11 10:18   ` Amit Machhiwal
  2026-11-11  8:30 ` Thomas Huth
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2026-11-11  7:54 UTC (permalink / raw)
  To: Amit Machhiwal, Laurent Vivier, Madhavan Srinivasan; +Cc: linuxppc-dev, kvm

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
  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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] powerpc: Link with -z notext
  2026-11-10 15:44 [PATCH] powerpc: Link with -z notext Amit Machhiwal
  2026-11-11  7:54 ` Thomas Huth
@ 2026-11-11  8:30 ` Thomas Huth
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2026-11-11  8:30 UTC (permalink / raw)
  To: Amit Machhiwal, Laurent Vivier, Madhavan Srinivasan
  Cc: linuxppc-dev, kvm, Paolo Bonzini

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 <amachhiw@linux.ibm.com>
> ---
>   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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] powerpc: Link with -z notext
  2026-11-11  7:54 ` Thomas Huth
@ 2026-11-11 10:18   ` Amit Machhiwal
  0 siblings, 0 replies; 4+ messages in thread
From: Amit Machhiwal @ 2026-11-11 10:18 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Amit Machhiwal, Laurent Vivier, Madhavan Srinivasan, linuxppc-dev,
	kvm

Hi Thomas,

On 2026/11/11 08:54 AM, Thomas Huth wrote:
> 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
>  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?

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 error

On 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-11 10:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 15:44 [PATCH] powerpc: Link with -z notext Amit Machhiwal
2026-11-11  7:54 ` Thomas Huth
2026-11-11 10:18   ` Amit Machhiwal
2026-11-11  8:30 ` Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox