diff mbox series

[meta-darwin,3/3] gcc: keep aarch64 outline atomics hidden

Message ID 20261203133818.967228-3-ecordonnier@snap.com
State New
Headers show
Series [meta-darwin,1/3] lldb: build nativesdk-lldb with clang for the macOS SDK | expand

Commit Message

Etienne Cordonnier Dec. 3, 2026, 1:38 p.m. UTC
From: Etienne Cordonnier <ecordonnier@snap.com>

0101 replaces the local STARTFN macro in libgcc/config/aarch64/lse.S
with the generic ENTRY macro, so that Mach-O gets the symbol prefix
(ASMNAME), the right alignment directive and no .type/.size. STARTFN
emitted HIDDEN(\name); ENTRY does not.

As a result every __aarch64_{cas,swp,ldadd,ldclr,ldeor,ldset}* helper
in libgcc.a, 125 in total, is a default-visibility global instead of
hidden. gcc-source is shared by all GCC recipes, so this also affects
the Linux aarch64 target libgcc, not only Darwin. Any shared library
that pulls the helpers in without --exclude-libs or a version script
then exports them, and its consumers bind to that copy instead of the
private copy in their own DSO.

Mark each helper hidden again. HIDDEN expands to .hidden on ELF and to
.private_extern on Mach-O (both defined by 0101), which matches
upstream GCC. The same defect is present in iains/gcc-15-branch
(gcc-15-3-darwin), the source of 0101.

Tested: gcc-source do_patch applies 0104 on top of 0101 without fuzz.
Assembling lse.S for aarch64 with and without 0104 for cas8_acq,
cas16_acq_rel, swp4_acq_rel, ldadd8_relax, ldclr2_acq, ldset1_rel and
ldeor4_relax gives a plain global symbol without it and .hidden with
it. Not tested on Darwin.

AI-Generated: Claude Sonnet 5.5
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
 ...-aarch64-keep-outline-atomics-hidden.patch | 35 +++++++++++++++++++
 recipes-devtools/gcc/gcc-source_%.bbappend    |  7 ++++
 2 files changed, 42 insertions(+)
 create mode 100644 recipes-devtools/gcc/files/0104-libgcc-aarch64-keep-outline-atomics-hidden.patch
diff mbox series

Patch

diff --git a/recipes-devtools/gcc/files/0104-libgcc-aarch64-keep-outline-atomics-hidden.patch b/recipes-devtools/gcc/files/0104-libgcc-aarch64-keep-outline-atomics-hidden.patch
new file mode 100644
index 0000000..fac1843
--- /dev/null
+++ b/recipes-devtools/gcc/files/0104-libgcc-aarch64-keep-outline-atomics-hidden.patch
@@ -0,0 +1,35 @@ 
+Subject: [PATCH] libgcc: aarch64: keep outline atomics hidden after Darwin ENTRY conversion
+
+0101 replaces lse.S's local STARTFN macro (which emitted HIDDEN(\name)) with
+the generic ENTRY macro, which has no HIDDEN. Every __aarch64_{cas,swp,ld*}
+helper in libgcc.a thus becomes default-visibility. Mark them hidden again.
+HIDDEN is .hidden on ELF and .private_extern on Mach-O.
+
+Upstream-Status: Inappropriate [fixes a downstream Darwin backport]
+---
+--- a/libgcc/config/aarch64/lse.S
++++ b/libgcc/config/aarch64/lse.S
+@@ -186,6 +186,7 @@
+ 
+ #ifdef L_cas
+ 
++	HIDDEN (ASMNAME (NAME(cas)))
+ ENTRY (ASMNAME (NAME(cas)))
+ 	JUMP_IF_NOT_LSE	8f
+ 
+@@ -249,6 +250,7 @@
+ # define SWP	.inst 0x38208020 + B + N
+ #endif
+ 
++	HIDDEN (ASMNAME (NAME (swp)))
+ ENTRY (ASMNAME (NAME (swp)))
+ 	JUMP_IF_NOT_LSE	8f
+ 
+@@ -293,6 +295,7 @@
+ # define LDOP	.inst 0x38200020 + OPN + B + N
+ #endif
+ 
++	HIDDEN (ASMNAME (NAME (LDNM)))
+ ENTRY (ASMNAME (NAME (LDNM)))
+ 	JUMP_IF_NOT_LSE	8f
+ 
diff --git a/recipes-devtools/gcc/gcc-source_%.bbappend b/recipes-devtools/gcc/gcc-source_%.bbappend
index de18cff..a886d63 100644
--- a/recipes-devtools/gcc/gcc-source_%.bbappend
+++ b/recipes-devtools/gcc/gcc-source_%.bbappend
@@ -25,6 +25,13 @@  SRC_URI:append = " \
     file://0103-libgcc-i386-cpuinfo-avoid-darwin-alias-ice.patch \
 "
 
+# 0101 replaces lse.S's STARTFN (which emitted HIDDEN) with the generic ENTRY
+# macro, which does not; this restores hidden visibility of the outline-atomic
+# helpers, which would otherwise leak out of every shared library using them.
+SRC_URI:append = " \
+    file://0104-libgcc-aarch64-keep-outline-atomics-hidden.patch \
+"
+
 # gcc-15.3.0 tarball ships zlib/zlib.map with CRLF; 0101 tail hunk is LF-only.
 python do_patch:prepend() {
     import pathlib