All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/musl: fix build for POWER10 and later
@ 2026-11-15  6:58 Yegor Yefremov
  2026-11-15  9:48 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Yegor Yefremov @ 2026-11-15  6:58 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain, Thomas Petazzoni

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
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
---
 package/musl/musl.mk | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/package/musl/musl.mk b/package/musl/musl.mk
index cb9f7f8870..b6e0ae6d97 100644
--- a/package/musl/musl.mk
+++ b/package/musl/musl.mk
@@ -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) \
-- 
2.34.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] package/musl: fix build for POWER10 and later
  2026-11-15  6:58 [Buildroot] [PATCH] package/musl: fix build for POWER10 and later Yegor Yefremov
@ 2026-11-15  9:48 ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni via buildroot @ 2026-11-15  9:48 UTC (permalink / raw)
  To: Yegor Yefremov; +Cc: buildroot, Julien Olivain

On Sun, Nov 15, 2026 at 07:58:03AM +0100, Yegor Yefremov wrote:
> 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

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

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

> Fixes: 3523e1ac79c15c5199a15589692e269191abd546 ("arch/Config.in.powerpc: add Power10 CPU type")
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>

Applied to master, thanks!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

end of thread, other threads:[~2026-11-15  9:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15  6:58 [Buildroot] [PATCH] package/musl: fix build for POWER10 and later Yegor Yefremov
2026-11-15  9:48 ` Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.