Skip to contentSkip to conversation

package/musl: fix build for POWER10 and later

PATCH Applied Yegor Yefremov 2 participants 3 messages Nov 15 – Nov 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/musl: fix build for POWER10 and later

When targeting POWER10 or POWER11, gcc generates pc-relative code by default, and the resulting C functions do not preserve the TOC pointer. musl's powerpc64 assembly calls or tail-calls C functions assuming the TOC-based ABI (bl without a following nop in crt_arch.h, b __dlsym in dlsym.s, b __setjmp_toc in setjmp.s/sigsetjmp.s), so the linker cannot insert the needed TOC save/restore stubs and linking libc.so fails:

dlstart.c:(.text+0x24): call to `_dlstart_c' lacks nop, can't restore toc; (toc save/adjust stub)
ld: final link failed: bad value

Build musl with -mno-pcrel for POWER10 and POWER11, so musl itself is built as TOC-based code. Applications can still be built with pc-relative code and link against it.

The issue has been reported upstream [1], as musl does not accept AI-assisted patches.

This issue has been present since commit 3523e1ac79c1 ("arch/Config.in.powerpc: add Power10 CPU type"), which made it possible to build musl with -mcpu=power10 (and later power11, added by commit da1b45dd00fd ("arch/Config.in.powerpc: add Power11 CPU type")). It therefore affects 2026.08 and later, including 2026.08.x.

Fixes:
https://autobuild.buildroot.org/results/1342da7c9258a93eada96f92f53a643e316ce7f6

[1] https://www.openwall.com/lists/musl/2026/11/15/2

Fixes 3523e1ac79c15c5199a15589692e269191abd546 ("arch/Config.in.powerpc: add Power10 CPU type")
Assisted-by Claude:claude-opus-5-5
---
 package/musl/musl.mk | 7 +++++++
 1 file changed, 7 insertions(+)
package/musl/musl.mk +7 -0
index cb9f7f8870..b6e0ae6d97 100644
@@ -49,6 +49,13 @@ ifeq ($(BR2_ARM_INSTRUCTIONS_THUMB),y)
 MUSL_EXTRA_CFLAGS += -marm
 endif
 
+# The powerpc64 assembly code assumes TOC-based C code, but gcc
+# generates pc-relative code by default for POWER10 and later, which
+# makes linking libc.so fail.
+ifeq ($(BR2_powerpc_power10)$(BR2_powerpc_power11),y)
+MUSL_EXTRA_CFLAGS += -mno-pcrel
+endif
+
 define MUSL_CONFIGURE_CMDS
 	(cd $(@D); \
 		$(TARGET_CONFIGURE_OPTS) \
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 23 lines · Yegor Yefremov

When targeting POWER10 or POWER11, gcc generates pc-relative code by default, and the resulting C functions do not preserve the TOC pointer. musl's powerpc64 assembly calls or tail-calls C functions assuming the TOC-based ABI (bl without a following nop in crt_arch.h, b __dlsym in dlsym.s, b __setjmp_toc in setjmp.s/sigsetjmp.s), so the linker cannot insert the needed TOC save/restore stubs and linking libc.so fails:

dlstart.c:(.text+0x24): call to `_dlstart_c' lacks nop, can't restore toc; (toc save/adjust stub)
ld: final link failed: bad value

Build musl with -mno-pcrel for POWER10 and POWER11, so musl itself is built as TOC-based code. Applications can still be built with pc-relative code and link against it.

The issue has been reported upstream [1], as musl does not accept AI-assisted patches.

This issue has been present since commit 3523e1ac79c1 ("arch/Config.in.powerpc: add Power10 CPU type"), which made it possible to build musl with -mcpu=power10 (and later power11, added by commit da1b45dd00fd ("arch/Config.in.powerpc: add Power11 CPU type")). It therefore affects 2026.08 and later, including 2026.08.x.

Quoted 4 lines

Fixes:
https://autobuild.buildroot.org/results/1342da7c9258a93eada96f92f53a643e316ce7f6

[1] https://www.openwall.com/lists/musl/2026/11/15/2

Funnily enough, I had already reported the issue to upstream musl:

https://www.openwall.com/lists/musl/2026/11/05/3

Quoted 3 lines
Fixes 3523e1ac79c15c5199a15589692e269191abd546 ("arch/Config.in.powerpc: add Power10 CPU type")
Assisted-by Claude:claude-opus-5-5

Applied to master, thanks!

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Yegor Yefremov

In reply of:

Quoted 23 lines

When targeting POWER10 or POWER11, gcc generates pc-relative code by default, and the resulting C functions do not preserve the TOC pointer. musl's powerpc64 assembly calls or tail-calls C functions assuming the TOC-based ABI (bl without a following nop in crt_arch.h, b __dlsym in dlsym.s, b __setjmp_toc in setjmp.s/sigsetjmp.s), so the linker cannot insert the needed TOC save/restore stubs and linking libc.so fails:

dlstart.c:(.text+0x24): call to `_dlstart_c' lacks nop, can't restore toc; (toc save/adjust stub)
ld: final link failed: bad value

Build musl with -mno-pcrel for POWER10 and POWER11, so musl itself is built as TOC-based code. Applications can still be built with pc-relative code and link against it.

The issue has been reported upstream [1], as musl does not accept AI-assisted patches.

This issue has been present since commit 3523e1ac79c1 ("arch/Config.in.powerpc: add Power10 CPU type"), which made it possible to build musl with -mcpu=power10 (and later power11, added by commit da1b45dd00fd ("arch/Config.in.powerpc: add Power11 CPU type")). It therefore affects 2026.08 and later, including 2026.08.x.

Quoted 8 lines

Fixes:
https://autobuild.buildroot.org/results/1342da7c9258a93eada96f92f53a643e316ce7f6

[1] https://www.openwall.com/lists/musl/2026/11/15/2

Fixes 3523e1ac79c15c5199a15589692e269191abd546 ("arch/Config.in.powerpc: add Power10 CPU type")
Assisted-by Claude:claude-opus-5-5

Applied to 2026.08.x. Thanks

Quoted 12 lines
---
 package/musl/musl.mk | 7 +++++++
 1 file changed, 7 insertions(+)
package/musl/musl.mk +0 -0
index cb9f7f8870..b6e0ae6d97 100644
@@ -49,6 +49,13 @@ ifeq ($(BR2_ARM_INSTRUCTIONS_THUMB),y)
 MUSL_EXTRA_CFLAGS += -marm
 endif
 

package/musl/musl.mk ifeq ($(BR2_ARM_INSTRUCTIONS_THUMB),y) · line 61

Quoted 10 lines
package/musl/musl.mk +7 -0
+# The powerpc64 assembly code assumes TOC-based C code, but gcc
+# generates pc-relative code by default for POWER10 and later, which
+# makes linking libc.so fail.
+ifeq ($(BR2_powerpc_power10)$(BR2_powerpc_power11),y)
+MUSL_EXTRA_CFLAGS += -mno-pcrel
+endif
+
 define MUSL_CONFIGURE_CMDS
 	(cd $(@D); \
 		$(TARGET_CONFIGURE_OPTS) \

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot