commit:     156e75fb38ab5a37f763729a7f79b89221015d9a
Author:     Z. Liu <zhixu.liu <AT> gmail <DOT> com>
AuthorDate: Mon Jan 13 14:01:28 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 14 02:30:59 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=156e75fb

sys-libs/musl: reduce namespace conflicts in sched.h in _GNU_SOURCE profile

patch from upstream on IRC

Closes: https://bugs.gentoo.org/895828
Signed-off-by: Z. Liu <zhixu.liu <AT> gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/40118
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../musl-sched.h-reduce-namespace-conflicts.patch  | 58 ++++++++++++++++++++++
 .../{musl-1.2.3-r8.ebuild => musl-1.2.3-r9.ebuild} |  4 ++
 .../{musl-1.2.4-r2.ebuild => musl-1.2.4-r3.ebuild} |  1 +
 .../{musl-1.2.5-r1.ebuild => musl-1.2.5-r2.ebuild} |  1 +
 4 files changed, 64 insertions(+)

diff --git a/sys-libs/musl/files/musl-sched.h-reduce-namespace-conflicts.patch 
b/sys-libs/musl/files/musl-sched.h-reduce-namespace-conflicts.patch
new file mode 100644
index 000000000000..d2d3b9343842
--- /dev/null
+++ b/sys-libs/musl/files/musl-sched.h-reduce-namespace-conflicts.patch
@@ -0,0 +1,58 @@
+commit 1a98576401ff604ff06a030a3644e2780b2a837d
+Author: Rich Felker <[email protected]>
+Date:   Mon Jan 13 08:31:02 2025 -0500
+
+    sched.h: reduce namespace conflicts in _GNU_SOURCE profile
+    
+    we have the cpuset macros call calloc/free/memset/memcmp directly so
+    that they don't depend on any further ABI surface. this is not
+    namespace-clean, but only affects the _GNU_SOURCE feature profile,
+    which is not intended to be namespace-clean. nonetheless, reports come
+    up now and then of things which are gratuitously broken, usually when
+    an application has wrapped malloc with macros.
+    
+    this patch parenthesizes the function names so that function-like
+    macros will not be expanded, and removes the unused declaration of
+    memcpy. this is not a complete solution, but it should improve things
+    for affected applications, particularly ones which are not even trying
+    to use the cpuset interfaces which got them just because g++ always
+    defines _GNU_SOURCE.
+
+diff --git a/include/sched.h b/include/sched.h
+index 204c34f5..8c3b53f0 100644
+--- a/include/sched.h
++++ b/include/sched.h
+@@ -78,11 +78,10 @@ int clone (int (*)(void *), void *, int, void *, ...);
+ int unshare(int);
+ int setns(int, int);
+ 
+-void *memcpy(void *__restrict, const void *__restrict, size_t);
+-int memcmp(const void *, const void *, size_t);
+-void *memset (void *, int, size_t);
+-void *calloc(size_t, size_t);
+-void free(void *);
++int (memcmp)(const void *, const void *, size_t);
++void *(memset)(void *, int, size_t);
++void *(calloc)(size_t, size_t);
++void (free)(void *);
+ 
+ typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } 
cpu_set_t;
+ int __sched_cpucount(size_t, const cpu_set_t *);
+@@ -116,13 +115,13 @@ __CPU_op_func_S(XOR, ^)
+ #define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d)
+ 
+ #define CPU_COUNT_S(size,set) __sched_cpucount(size,set)
+-#define CPU_ZERO_S(size,set) memset(set,0,size)
+-#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size))
++#define CPU_ZERO_S(size,set) (memset)(set,0,size)
++#define CPU_EQUAL_S(size,set1,set2) (!(memcmp)(set1,set2,size))
+ 
+ #define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \
+       + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) )
+-#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
+-#define CPU_FREE(set) free(set)
++#define CPU_ALLOC(n) ((cpu_set_t *)(calloc)(1,CPU_ALLOC_SIZE(n)))
++#define CPU_FREE(set) (free)(set)
+ 
+ #define CPU_SETSIZE 1024
+ 

diff --git a/sys-libs/musl/musl-1.2.3-r8.ebuild 
b/sys-libs/musl/musl-1.2.3-r9.ebuild
similarity index 98%
rename from sys-libs/musl/musl-1.2.3-r8.ebuild
rename to sys-libs/musl/musl-1.2.3-r9.ebuild
index 1aadcaab94cf..3436d7f34687 100644
--- a/sys-libs/musl/musl-1.2.3-r8.ebuild
+++ b/sys-libs/musl/musl-1.2.3-r9.ebuild
@@ -56,6 +56,10 @@ else
        PDEPEND="!crypt? ( sys-libs/libxcrypt[system] )"
 fi
 
+PATCHES=(
+       "${FILESDIR}"/${PN}-sched.h-reduce-namespace-conflicts.patch
+)
+
 is_crosscompile() {
        [[ ${CHOST} != ${CTARGET} ]]
 }

diff --git a/sys-libs/musl/musl-1.2.4-r2.ebuild 
b/sys-libs/musl/musl-1.2.4-r3.ebuild
similarity index 98%
rename from sys-libs/musl/musl-1.2.4-r2.ebuild
rename to sys-libs/musl/musl-1.2.4-r3.ebuild
index 8bfb46ffef59..3909d62c13de 100644
--- a/sys-libs/musl/musl-1.2.4-r2.ebuild
+++ b/sys-libs/musl/musl-1.2.4-r3.ebuild
@@ -51,6 +51,7 @@ 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
 )
 
 just_headers() {

diff --git a/sys-libs/musl/musl-1.2.5-r1.ebuild 
b/sys-libs/musl/musl-1.2.5-r2.ebuild
similarity index 98%
rename from sys-libs/musl/musl-1.2.5-r1.ebuild
rename to sys-libs/musl/musl-1.2.5-r2.ebuild
index 7fe02741839d..62c8bedc5e27 100644
--- a/sys-libs/musl/musl-1.2.5-r1.ebuild
+++ b/sys-libs/musl/musl-1.2.5-r2.ebuild
@@ -52,6 +52,7 @@ fi
 
 PATCHES=(
        "${FILESDIR}"/${PN}-1.2.4-arm64-crti-alignment.patch
+       "${FILESDIR}"/${PN}-sched.h-reduce-namespace-conflicts.patch
 )
 
 just_headers() {

Reply via email to