commit:     2ba8dfe9407383b97485385552cab675a51b8bd5
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 24 23:52:43 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Sep 24 23:54:43 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2ba8dfe9

sys-libs/musl: backport 3 fixes

* Backport arm crti.o fix as we did for arm64 in 
9aabd6aa9abd2c48f85cb582fadf81eae944600f
* ppc* clobber fix
* GCC 15 union workaround/fix

I'm hoping to do a snapshot at some point soon as well: 
https://bugs.gentoo.org/956676#c14

Bug: https://bugs.gentoo.org/931782
Closes: https://bugs.gentoo.org/956676
Signed-off-by: Sam James <sam <AT> gentoo.org>

 sys-libs/musl/files/musl-arm-crti-alignment.patch  |  33 +++++
 sys-libs/musl/files/musl-dns-union.patch           |  33 +++++
 sys-libs/musl/files/musl-ppc-clobber.patch         | 154 +++++++++++++++++++++
 sys-libs/musl/musl-1.2.4-r4.ebuild                 |   2 +-
 .../{musl-1.2.4-r4.ebuild => musl-1.2.5-r4.ebuild} |  78 +++++++++--
 5 files changed, 286 insertions(+), 14 deletions(-)

diff --git a/sys-libs/musl/files/musl-arm-crti-alignment.patch 
b/sys-libs/musl/files/musl-arm-crti-alignment.patch
new file mode 100644
index 000000000000..ce7279c82f69
--- /dev/null
+++ b/sys-libs/musl/files/musl-arm-crti-alignment.patch
@@ -0,0 +1,33 @@
+https://bugs.gentoo.org/931782
+https://git.musl-libc.org/cgit/musl/commit/?id=9929a571b5b662c2ce106f1c08a9faf02af58d8a
+
+From 9929a571b5b662c2ce106f1c08a9faf02af58d8a Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= <[email protected]>
+Date: Thu, 10 Oct 2024 22:50:46 +0200
+Subject: arm: fix _init/_fini alignment in crti.o
+
+This is just cbf59dd6 applied to arm.
+---
+ crt/arm/crti.s | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/crt/arm/crti.s b/crt/arm/crti.s
+index 18dc1e41..cccda3ea 100644
+--- a/crt/arm/crti.s
++++ b/crt/arm/crti.s
+@@ -3,11 +3,13 @@
+ .section .init
+ .global _init
+ .type _init,%function
++.align 2
+ _init:
+       push {r0,lr}
+ 
+ .section .fini
+ .global _fini
+ .type _fini,%function
++.align 2
+ _fini:
+       push {r0,lr}
+-- 
+cgit v1.2.1

diff --git a/sys-libs/musl/files/musl-dns-union.patch 
b/sys-libs/musl/files/musl-dns-union.patch
new file mode 100644
index 000000000000..7b6affe43b3b
--- /dev/null
+++ b/sys-libs/musl/files/musl-dns-union.patch
@@ -0,0 +1,33 @@
+https://git.musl-libc.org/cgit/musl/commit/?id=6915b34860459a963fb1ba468a4d5389dd65c67b
+
+From 6915b34860459a963fb1ba468a4d5389dd65c67b Mon Sep 17 00:00:00 2001
+From: Rich Felker <[email protected]>
+Date: Mon, 5 May 2025 09:23:32 -0400
+Subject: dns resolver: reorder sockaddr union to make initialization safe
+
+some recent compilers have adopted a dubious interpretation of the C
+specification for union initializers, that when the initialized member
+is smaller than the size of the union, the remaining padding does not
+have to be zero-initialized. in the interests of not depending on any
+particular interpretation, place the larger member first so it's
+initialized and ensures the whole object is zero-filled.
+---
+ src/network/res_msend.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/network/res_msend.c b/src/network/res_msend.c
+index 86c2fcf4..fcb52513 100644
+--- a/src/network/res_msend.c
++++ b/src/network/res_msend.c
+@@ -83,8 +83,8 @@ int __res_msend_rc(int nqueries, const unsigned char *const 
*queries,
+       int fd;
+       int timeout, attempts, retry_interval, servfail_retry;
+       union {
+-              struct sockaddr_in sin;
+               struct sockaddr_in6 sin6;
++              struct sockaddr_in sin;
+       } sa = {0}, ns[MAXNS] = {{0}};
+       socklen_t sl = sizeof sa.sin;
+       int nns = 0;
+-- 
+cgit v1.2.1

diff --git a/sys-libs/musl/files/musl-ppc-clobber.patch 
b/sys-libs/musl/files/musl-ppc-clobber.patch
new file mode 100644
index 000000000000..8094d541a8a3
--- /dev/null
+++ b/sys-libs/musl/files/musl-ppc-clobber.patch
@@ -0,0 +1,154 @@
+https://bugs.gentoo.org/956676
+https://git.musl-libc.org/cgit/musl/patch/?id=f6944eb3c4ce1c97dc39dc36d32390dc9f70b67b
+
+From f6944eb3c4ce1c97dc39dc36d32390dc9f70b67b Mon Sep 17 00:00:00 2001
+From: Rich Felker <[email protected]>
+Date: Thu, 7 Aug 2025 15:35:14 -0400
+Subject: powerpc[64]: fix missing ctr and xer regs in syscall asm clobberlists
+
+the ctr and xer special registers are call-clobbered and
+syscall-clobbered. failure to include them in the clobber list may
+result in wrong code that attempts to use a value which is no longer
+present in the register after the syscall. this has been reported to
+manifest newly with gcc 15.
+---
+ arch/powerpc/syscall_arch.h   | 14 +++++++-------
+ arch/powerpc64/syscall_arch.h | 14 +++++++-------
+ 2 files changed, 14 insertions(+), 14 deletions(-)
+
+diff --git a/arch/powerpc/syscall_arch.h b/arch/powerpc/syscall_arch.h
+index 54c885cb..fe893af4 100644
+--- a/arch/powerpc/syscall_arch.h
++++ b/arch/powerpc/syscall_arch.h
+@@ -9,7 +9,7 @@ static inline long __syscall0(long n)
+       register long r3 __asm__("r3");
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "=r"(r3)
+-      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12");
++      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12", "ctr", "xer");
+       return r3;
+ }
+ 
+@@ -19,7 +19,7 @@ static inline long __syscall1(long n, long a)
+       register long r3 __asm__("r3") = a;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3)
+-      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12");
++      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12", "ctr", "xer");
+       return r3;
+ }
+ 
+@@ -30,7 +30,7 @@ static inline long __syscall2(long n, long a, long b)
+       register long r4 __asm__("r4") = b;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4)
+-      :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", 
"ctr", "xer");
+       return r3;
+ }
+ 
+@@ -42,7 +42,7 @@ static inline long __syscall3(long n, long a, long b, long c)
+       register long r5 __asm__("r5") = c;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5)
+-      :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", 
"xer");
+       return r3;
+ }
+ 
+@@ -55,7 +55,7 @@ static inline long __syscall4(long n, long a, long b, long 
c, long d)
+       register long r6 __asm__("r6") = d;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6)
+-      :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", 
"xer");
+       return r3;
+ }
+ 
+@@ -69,7 +69,7 @@ static inline long __syscall5(long n, long a, long b, long 
c, long d, long e)
+       register long r7 __asm__("r7") = e;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7)
+-      :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
+       return r3;
+ }
+ 
+@@ -84,7 +84,7 @@ static inline long __syscall6(long n, long a, long b, long 
c, long d, long e, lo
+       register long r8 __asm__("r8") = f;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7), "+r"(r8)
+-      :: "memory", "cr0", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r9", "r10", "r11", "r12", "ctr", "xer");
+       return r3;
+ }
+ 
+diff --git a/arch/powerpc64/syscall_arch.h b/arch/powerpc64/syscall_arch.h
+index 7d34fbe4..4c5d3ae9 100644
+--- a/arch/powerpc64/syscall_arch.h
++++ b/arch/powerpc64/syscall_arch.h
+@@ -7,7 +7,7 @@ static inline long __syscall0(long n)
+       register long r3 __asm__("r3");
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "=r"(r3)
+-      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12");
++      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12", "ctr", "xer");
+       return r3;
+ }
+ 
+@@ -17,7 +17,7 @@ static inline long __syscall1(long n, long a)
+       register long r3 __asm__("r3") = a;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3)
+-      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12");
++      :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", 
"r12", "ctr", "xer");
+       return r3;
+ }
+ 
+@@ -28,7 +28,7 @@ static inline long __syscall2(long n, long a, long b)
+       register long r4 __asm__("r4") = b;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4)
+-      :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", 
"ctr", "xer");
+       return r3;
+ }
+ 
+@@ -40,7 +40,7 @@ static inline long __syscall3(long n, long a, long b, long c)
+       register long r5 __asm__("r5") = c;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5)
+-      :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", 
"xer");
+       return r3;
+ }
+ 
+@@ -53,7 +53,7 @@ static inline long __syscall4(long n, long a, long b, long 
c, long d)
+       register long r6 __asm__("r6") = d;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6)
+-      :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", 
"xer");
+       return r3;
+ }
+ 
+@@ -67,7 +67,7 @@ static inline long __syscall5(long n, long a, long b, long 
c, long d, long e)
+       register long r7 __asm__("r7") = e;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7)
+-      :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
+       return r3;
+ }
+ 
+@@ -82,7 +82,7 @@ static inline long __syscall6(long n, long a, long b, long 
c, long d, long e, lo
+       register long r8 __asm__("r8") = f;
+       __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
+       : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7), "+r"(r8)
+-      :: "memory", "cr0", "r9", "r10", "r11", "r12");
++      :: "memory", "cr0", "r9", "r10", "r11", "r12", "ctr", "xer");
+       return r3;
+ }
+ 
+-- 
+cgit v1.2.1

diff --git a/sys-libs/musl/musl-1.2.4-r4.ebuild 
b/sys-libs/musl/musl-1.2.4-r4.ebuild
index 83fc6def71c0..79f9d494100f 100644
--- a/sys-libs/musl/musl-1.2.4-r4.ebuild
+++ b/sys-libs/musl/musl-1.2.4-r4.ebuild
@@ -13,7 +13,7 @@ else
 
        SRC_URI="https://musl.libc.org/releases/${P}.tar.gz";
        SRC_URI+=" verify-sig? ( https://musl.libc.org/releases/${P}.tar.gz.asc 
)"
-       KEYWORDS="-* amd64 arm arm64 ~m68k ~mips ppc ppc64 ~riscv x86"
+       KEYWORDS="-* ~amd64 ~arm ~arm64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~x86"
 
        BDEPEND="verify-sig? ( sec-keys/openpgp-keys-musl )"
 fi

diff --git a/sys-libs/musl/musl-1.2.4-r4.ebuild 
b/sys-libs/musl/musl-1.2.5-r4.ebuild
similarity index 69%
copy from sys-libs/musl/musl-1.2.4-r4.ebuild
copy to sys-libs/musl/musl-1.2.5-r4.ebuild
index 83fc6def71c0..5ecb3c134680 100644
--- a/sys-libs/musl/musl-1.2.4-r4.ebuild
+++ b/sys-libs/musl/musl-1.2.5-r4.ebuild
@@ -4,7 +4,11 @@
 EAPI=8
 
 inherit crossdev flag-o-matic toolchain-funcs prefix
-if [[ ${PV} == "9999" ]] ; then
+
+DESCRIPTION="Light, fast and, simple C library focused on 
standards-conformance and safety"
+HOMEPAGE="https://musl.libc.org";
+
+if [[ ${PV} == 9999 ]] ; then
        EGIT_REPO_URI="https://git.musl-libc.org/git/musl";
        inherit git-r3
 else
@@ -13,10 +17,11 @@ else
 
        SRC_URI="https://musl.libc.org/releases/${P}.tar.gz";
        SRC_URI+=" verify-sig? ( https://musl.libc.org/releases/${P}.tar.gz.asc 
)"
-       KEYWORDS="-* amd64 arm arm64 ~m68k ~mips ppc ppc64 ~riscv x86"
+       KEYWORDS="-* ~amd64 ~arm ~arm64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~x86"
 
        BDEPEND="verify-sig? ( sec-keys/openpgp-keys-musl )"
 fi
+
 GETENT_COMMIT="93a08815f8598db442d8b766b463d0150ed8e2ab"
 GETENT_FILE="musl-getent-${GETENT_COMMIT}.c"
 SRC_URI+="
@@ -25,9 +30,6 @@ SRC_URI+="
        https://dev.gentoo.org/~blueness/musl-misc/iconv.c
 "
 
-DESCRIPTION="Light, fast and simple C library focused on standards-conformance 
and safety"
-HOMEPAGE="https://musl.libc.org";
-
 LICENSE="MIT LGPL-2 GPL-2"
 SLOT="0"
 IUSE="crypt headers-only split-usr"
@@ -49,10 +51,12 @@ else
 fi
 
 PATCHES=(
-       "${FILESDIR}"/${P}-elfutils-0.190-relr.patch
        "${FILESDIR}"/${PN}-1.2.4-arm64-crti-alignment.patch
        "${FILESDIR}"/${PN}-sched.h-reduce-namespace-conflicts.patch
        "${FILESDIR}"/${PN}-iconv-out-of-bound-fix.patch
+       "${FILESDIR}"/${PN}-arm-crti-alignment.patch
+       "${FILESDIR}"/${PN}-ppc-clobber.patch
+       "${FILESDIR}"/${PN}-dns-union.patch
 )
 
 just_headers() {
@@ -62,12 +66,12 @@ just_headers() {
 pkg_setup() {
        if [[ ${CTARGET} == ${CHOST} ]] ; then
                case ${CHOST} in
-               *-musl*) ;;
-               *) die "Use sys-devel/crossdev to build a musl toolchain" ;;
+                       *-musl*) ;;
+                       *) die "Use sys-devel/crossdev to build a musl 
toolchain" ;;
                esac
        fi
 
-       # fix for #667126, copied from glibc ebuild
+       # Fix for bug #667126, copied from glibc ebuild:
        # make sure host make.conf doesn't pollute us
        if target_is_not_host || tc-is-cross-compiler ; then
                CHOST=${CTARGET} strip-unsupported-flags
@@ -125,7 +129,7 @@ src_compile() {
                        VPATH="${WORKDIR}/misc"
        fi
 
-       $(tc-getCC) ${CFLAGS} -c -o libssp_nonshared.o  
"${FILESDIR}"/stack_chk_fail_local.c || die
+       $(tc-getCC) ${CPPFLAGS} ${CFLAGS} -c -o libssp_nonshared.o 
"${FILESDIR}"/stack_chk_fail_local.c || die
        $(tc-getAR) -rcs libssp_nonshared.a libssp_nonshared.o || die
 }
 
@@ -192,18 +196,66 @@ src_install() {
        fi
 }
 
+# Simple test to make sure our new musl isn't completely broken.
+# Make sure we don't test with statically built binaries since
+# they will fail.  Also, skip if this musl is a cross compiler.
+#
+# If coreutils is built with USE=multicall, some of these files
+# will just be wrapper scripts, not actual ELFs we can test.
+musl_sanity_check() {
+       cd / #228809
+
+       # We enter ${ED} so to avoid trouble if the path contains
+       # special characters; for instance if the path contains the
+       # colon character (:), then the linker will try to split it
+       # and look for the libraries in an unexpected place. This can
+       # lead to unsafe code execution if the generated prefix is
+       # within a world-writable directory.
+       # (e.g. /var/tmp/portage:${HOSTNAME})
+       pushd "${ED}"/usr/$(get_libdir) >/dev/null
+
+       # first let's find the actual dynamic linker here
+       # symlinks may point to the wrong abi
+       local newldso=$(find . -maxdepth 1 -name 'libc.so' -type f -print -quit)
+
+       einfo Last-minute run tests with ${newldso} in /usr/$(get_libdir) ...
+
+       local x striptest
+       for x in cal date env free ls true uname uptime ; do
+               x=$(type -p ${x})
+               [[ -z ${x} || ${x} != ${EPREFIX}/* ]] && continue
+               striptest=$(LC_ALL="C" file -L ${x} 2>/dev/null) || continue
+               case ${striptest} in
+               *"statically linked"*) continue;;
+               *"static-pie linked"*) continue;;
+               *"ASCII text"*) continue;;
+               esac
+               # We need to clear the locale settings as the upgrade might want
+               # incompatible locale data.  This test is not for verifying 
that.
+               LC_ALL=C \
+               ${newldso} --library-path . ${x} > /dev/null \
+                       || die "simple run test (${x}) failed"
+       done
+
+       popd >/dev/null
+}
+
 pkg_preinst() {
-       # nothing to do if just installing headers
+       # Nothing to do if just installing headers
        just_headers && return
 
-       # prepare /etc/ld.so.conf.d/ for files
+       # Prepare /etc/ld.so.conf.d/ for files
        mkdir -p "${EROOT}"/etc/ld.so.conf.d
+
+       [[ -n ${ROOT} ]] && return 0
+       [[ -d ${ED}/usr/$(get_libdir) ]] || return 0
+       musl_sanity_check
 }
 
 pkg_postinst() {
        target_is_not_host && return 0
 
-       [ -n "${ROOT}" ] && return 0
+       [[ -n "${ROOT}" ]] && return 0
 
        ldconfig || die
 }

Reply via email to