Skip to contentSkip to conversation

powerpc/boot: Allow text relocations for pseries wrapper with binutils 2.46+

PATCH Applied Amit Machhiwal 3 participants 3 messages May 25 – Jun 19 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/boot: Allow text relocations for pseries wrapper with binutils 2.46+

Binutils 2.46 changed the default linker behavior from '-z notext' to '-z text', which treats dynamic relocations in read-only segments as errors rather than warnings. This causes the pseries boot wrapper build to fail with:

/usr/bin/ld.bfd: arch/powerpc/boot/wrapper.a(crt0.o): warning:
relocation against _platform_stack_top' in read-only section .text'
/usr/bin/ld.bfd: error: read-only segment has dynamic relocations

The pseries wrapper uses '-pie' to create position-independent code. However, crt0.S contains a pointer to '_platform_stack_top' in the .text section, which requires a dynamic relocation at runtime. This creates DT_TEXTREL (text relocations), which were allowed by default in binutils 2.45 and earlier (via implicit '-z notext') but are now rejected by binutils 2.46+.

Add '-z notext' linker flag to explicitly allow text relocations for the pseries platform, similar to what is already done for the epapr platform. This restores the previous behavior and allows the boot wrapper to build successfully with binutils 2.46+.

---
 arch/powerpc/boot/wrapper | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/boot/wrapper +1 -0
index 1efd1206fcab..25321ce262e8 100755
@@ -262,6 +262,7 @@ pseries)
     if [ "$format" != "elf32ppc" ]; then
 	link_address=
 	pie=-pie
+	notext='-z notext'
     fi
     make_space=n
     ;;

base-commit: e7ae89a0c97ce2b68b0983cd01eda67cf373517d

Signature · 1 line
2.50.1 (Apple Git-155)
Tested-by on v1 1/1
#1 lore raw
Quoted 39 lines · Amit Machhiwal

Binutils 2.46 changed the default linker behavior from '-z notext' to '-z text', which treats dynamic relocations in read-only segments as errors rather than warnings. This causes the pseries boot wrapper build to fail with:

/usr/bin/ld.bfd: arch/powerpc/boot/wrapper.a(crt0.o): warning:
relocation against _platform_stack_top' in read-only section .text'
/usr/bin/ld.bfd: error: read-only segment has dynamic relocations

The pseries wrapper uses '-pie' to create position-independent code. However, crt0.S contains a pointer to '_platform_stack_top' in the .text section, which requires a dynamic relocation at runtime. This creates DT_TEXTREL (text relocations), which were allowed by default in binutils 2.45 and earlier (via implicit '-z notext') but are now rejected by binutils 2.46+.

Add '-z notext' linker flag to explicitly allow text relocations for the pseries platform, similar to what is already done for the epapr platform. This restores the previous behavior and allows the boot wrapper to build successfully with binutils 2.46+.

---
  arch/powerpc/boot/wrapper | 1 +
  1 file changed, 1 insertion(+)
arch/powerpc/boot/wrapper +1 -0
index 1efd1206fcab..25321ce262e8 100755
@@ -262,6 +262,7 @@ pseries)
      if [ "$format" != "elf32ppc" ]; then
  	link_address=
  	pie=-pie
+	notext='-z notext'
      fi
      make_space=n
      ;;
Quoted 1 line

base-commit: e7ae89a0c97ce2b68b0983cd01eda67cf373517d

Hi Amit,
I have tested this patch and it has fixed the kernel build issue. Here is my analysis:

i) Without applying the patch:

Kernel build failed with below error -

  CC [M]  drivers/net/usb/r8152.mod.o
  CC [M]  drivers/net/usb/hso.mod.o
  CC [M]  drivers/net/usb/lan78xx.mod.o
  CC [M]  drivers/net/usb/asix.mod.o
  CC [M]  drivers/net/usb/ax88179_178a.mod.o
/usr/bin/ld.bfd: arch/powerpc/boot/wrapper.a(crt0.o): warning: relocation against _platform_stack_top' in read-only section .text' /usr/bin/ld.bfd: error: read-only segment has dynamic relocations
make[2]: *** [arch/powerpc/boot/Makefile:386: arch/powerpc/boot/zImage.pseries] Error 1
  CC [M]  drivers/net/usb/cdc_ether.mod.o
make[1]: *** [arch/powerpc/Makefile:236: zImage] Error 2
make[1]: *** Waiting for unfinished jobs....

ii) After applying the patch :

Kernel build got successful.

Please feel free to add:

Thank you!
Anushree Mathur

maintainer Applied
#2 lore raw
In reply to Amit Machhiwal
Quoted 10 lines · Amit Machhiwal

Binutils 2.46 changed the default linker behavior from '-z notext' to '-z text', which treats dynamic relocations in read-only segments as errors rather than warnings. This causes the pseries boot wrapper build to fail with:

/usr/bin/ld.bfd: arch/powerpc/boot/wrapper.a(crt0.o): warning:
relocation against _platform_stack_top' in read-only section .text'
/usr/bin/ld.bfd: error: read-only segment has dynamic relocations

[...]

Applied to powerpc/next.

[1/1] powerpc/boot: Allow text relocations for pseries wrapper with binutils 2.46+

      https://git.kernel.org/powerpc/c/97f902dd4c99f8d085da5343dc58ae4f6ce7bdd9

cheers