Skip to content

Commit 9020136

Browse files
committed
sys-devel/gcc-14.2.1_p20241221: fix building on macOS 15.4
Signed-off-by: Fabian Groffen <[email protected]>
1 parent 8acde87 commit 9020136

4 files changed

+326
-0
lines changed

Diff for: sys-devel/gcc/files/gcc-14.2.1-macos-15-4.patch

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
From efb88ebe0a6886f816c0d037df33df6556544ad6 Mon Sep 17 00:00:00 2001
2+
From: Iain Sandoe <[email protected]>
3+
Date: Thu, 3 Apr 2025 15:53:05 +0100
4+
Subject: [PATCH] c-family: Support cross-language keywords as an extension.
5+
6+
This allows us compatibility with clang extensions permitting
7+
C keywords in C++ and vice versa (initially implementing only
8+
two to deal with specific SDK issues).
9+
10+
Addresses issue #142.
11+
12+
gcc/c-family/ChangeLog:
13+
14+
* c-common.cc (flag_allow_extra_keywords): Mark
15+
_Alignas and _Alignof as usable in C++ when allowed.
16+
* c-common.h (D_EXT_C_IN_CXX, D_EXT_CXX_IN_C): New.
17+
* c.opt (flag_allow_extra_keywords): New.
18+
19+
gcc/ChangeLog:
20+
21+
* config/darwin.cc (darwin_override_options): If
22+
flag_allow_extra_keywords is not explicitly set then
23+
switch it on for Darwin.
24+
25+
gcc/cp/ChangeLog:
26+
27+
* lex.cc (init_reswords): Handle D_EXT_C_IN_CXX.
28+
29+
Signed-off-by: Iain Sandoe <[email protected]>
30+
---
31+
gcc/c-family/c-common.cc | 4 ++--
32+
gcc/c-family/c-common.h | 2 ++
33+
gcc/c-family/c.opt | 4 ++++
34+
gcc/config/darwin.cc | 4 ++++
35+
gcc/cp/lex.cc | 3 +++
36+
5 files changed, 15 insertions(+), 2 deletions(-)
37+
38+
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
39+
index 79dac5fccf30..a038651aa28b 100644
40+
--- a/gcc/c-family/c-common.cc
41+
+++ b/gcc/c-family/c-common.cc
42+
@@ -388,8 +388,8 @@ static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
43+
*/
44+
const struct c_common_resword c_common_reswords[] =
45+
{
46+
- { "_Alignas", RID_ALIGNAS, D_CONLY },
47+
- { "_Alignof", RID_ALIGNOF, D_CONLY },
48+
+ { "_Alignas", RID_ALIGNAS, D_EXT_C_IN_CXX },
49+
+ { "_Alignof", RID_ALIGNOF, D_EXT_C_IN_CXX },
50+
{ "_Atomic", RID_ATOMIC, D_CONLY },
51+
{ "_BitInt", RID_BITINT, D_CONLY },
52+
{ "_Bool", RID_BOOL, D_CONLY },
53+
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
54+
index 78414d4519e9..5831c8b5af9a 100644
55+
--- a/gcc/c-family/c-common.h
56+
+++ b/gcc/c-family/c-common.h
57+
@@ -445,6 +445,8 @@ extern machine_mode c_default_pointer_mode;
58+
#define D_CXX20 0x8000 /* In C++, C++20 only. */
59+
#define D_CXX_COROUTINES 0x10000 /* In C++, only with coroutines. */
60+
#define D_CXX_MODULES 0x20000 /* In C++, only with modules. */
61+
+#define D_EXT_C_IN_CXX 0x40000 /* In C++, allow additional C keywords. */
62+
+#define D_EXT_CXX_IN_C 0x80000 /* In C, allow additional C++ keywords. */
63+
64+
#define D_CXX_CONCEPTS_FLAGS D_CXXONLY | D_CXX_CONCEPTS
65+
#define D_CXX_CHAR8_T_FLAGS D_CXXONLY | D_CXX_CHAR8_T
66+
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
67+
index 418e87fa486b..7375dcf95efb 100644
68+
--- a/gcc/c-family/c.opt
69+
+++ b/gcc/c-family/c.opt
70+
@@ -1712,6 +1712,10 @@ fallow-extended-attribute-placement
71+
C ObjC C++ ObjC++ LTO Var(flag_allow_ext_attr_placement) Init(0)
72+
Allow placement of attributes on function definitions.
73+
74+
+fallow-extra-keywords
75+
+C ObjC C++ ObjC++ LTO Var(flag_allow_extra_keywords) Init(0)
76+
+Allow additional C keywords in C++ and vice versa.
77+
+
78+
fcilkplus
79+
C ObjC C++ ObjC++ LTO Undocumented Ignore
80+
Removed in GCC 8. This switch has no effect.
81+
diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
82+
index e6657753211f..233710ae566f 100644
83+
--- a/gcc/config/darwin.cc
84+
+++ b/gcc/config/darwin.cc
85+
@@ -3957,6 +3957,10 @@ darwin_override_options (void)
86+
/* Later systems can support aligned common. */
87+
emit_aligned_common = true;
88+
89+
+ /* We need to consume some C keywords in C++. */
90+
+ if (!OPTION_SET_P (flag_allow_extra_keywords))
91+
+ flag_allow_extra_keywords = true;
92+
+
93+
/* The c_dialect...() macros are not available to us here. */
94+
darwin_running_cxx = (strstr (lang_hooks.name, "C++") != 0);
95+
}
96+
diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc
97+
index 1110db7f8d07..0c4f93a6787b 100644
98+
--- a/gcc/cp/lex.cc
99+
+++ b/gcc/cp/lex.cc
100+
@@ -267,6 +267,9 @@ init_reswords (void)
101+
{
102+
if (c_common_reswords[i].disable & D_CONLY)
103+
continue;
104+
+ if (!flag_allow_extra_keywords
105+
+ && c_common_reswords[i].disable & D_EXT_C_IN_CXX)
106+
+ continue;
107+
id = get_identifier (c_common_reswords[i].word);
108+
C_SET_RID_CODE (id, c_common_reswords[i].rid);
109+
ridpointers [(int) c_common_reswords[i].rid] = id;
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 50f92929f337c81aaf330bb04ac0675dba340e25 Mon Sep 17 00:00:00 2001
2+
From: Iain Sandoe <[email protected]>
3+
Date: Sun, 29 Dec 2024 23:06:54 +0000
4+
Subject: [PATCH] includes, Darwin: Handle modular use for macOS SDKs.
5+
6+
gcc/ChangeLog:
7+
8+
* ginclude/stddef.h (defined):
9+
(__PTRDIFF_T):
10+
(__SIZE_T):
11+
12+
Signed-off-by: Iain Sandoe <[email protected]>
13+
---
14+
gcc/ginclude/stddef.h | 11 +++++++++++
15+
1 file changed, 11 insertions(+)
16+
17+
diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
18+
index be884e96336..16ac9bb0742 100644
19+
--- a/gcc/ginclude/stddef.h
20+
+++ b/gcc/ginclude/stddef.h
21+
@@ -89,6 +89,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22+
#undef _PTRDIFF_T_
23+
#endif
24+
25+
+#if defined (__APPLE__)
26+
+# if defined(__has_feature) && __has_feature(modules)
27+
+# if defined (__need_ptrdiff_t)
28+
+# undef __PTRDIFF_T
29+
+# endif
30+
+# if defined (__need_size_t)
31+
+# undef __SIZE_T
32+
+# endif
33+
+# endif
34+
+#endif
35+
+
36+
/* On VxWorks, <type/vxTypesBase.h> may have defined macros like
37+
_TYPE_size_t which will typedef size_t. fixincludes patched the
38+
vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
From 407e1099d055eaf39478cfdd933ed8aad273c1cc Mon Sep 17 00:00:00 2001
2+
From: Iain Sandoe <[email protected]>
3+
Date: Sun, 9 Mar 2025 09:24:34 +0000
4+
Subject: [PATCH] Darwin: Pass -macos_version_min to the linker [PR119172].
5+
6+
For binaries to be notarised, the SDK version must be available.
7+
Since we do not, at present, parse this information we have been
8+
passing "0.0" to ld64. This now results in a warning and a fail
9+
to notarise. As a quick-fix, we can fall back to letting ld64
10+
figure out the SDK version (which it does for -macos_version_min).
11+
12+
TODO: Parse the SDKSetting.plist at some point.
13+
14+
cherry-picked from 952e17223d3a9 and fc728cfd569e291a5
15+
16+
PR target/119172
17+
18+
gcc/ChangeLog:
19+
20+
* config.in: Regenerate.
21+
* config/darwin.h (DARWIN_PLATFORM_ID): Add the option to
22+
use -macos_version_min where available.
23+
* configure: Regenerate.
24+
* configure.ac: Check for ld64 support of -macos_version_min.
25+
26+
Co-authored-by: Andrew Pinski <[email protected]>
27+
28+
Signed-off-by: Iain Sandoe <[email protected]>
29+
Signed-off-by: Andrew Pinski <[email protected]>
30+
---
31+
gcc/config.in | 6 ++++++
32+
gcc/config/darwin.h | 13 +++++++++----
33+
gcc/configure | 17 +++++++++++++++++
34+
gcc/configure.ac | 12 ++++++++++++
35+
4 files changed, 44 insertions(+), 4 deletions(-)
36+
37+
diff --git a/gcc/config.in b/gcc/config.in
38+
index f3de4ba6776b..7db2dfdc192b 100644
39+
--- a/gcc/config.in
40+
+++ b/gcc/config.in
41+
@@ -2289,6 +2289,12 @@
42+
#endif
43+
44+
45+
+/* Define to 1 if ld64 supports '-macos_version_min'. */
46+
+#ifndef USED_FOR_TARGET
47+
+#undef LD64_HAS_MACOS_VERSION_MIN
48+
+#endif
49+
+
50+
+
51+
/* Define to 1 if ld64 supports '-platform_version'. */
52+
#ifndef USED_FOR_TARGET
53+
#undef LD64_HAS_PLATFORM_VERSION
54+
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
55+
index 5370511bec21..75050d2197a8 100644
56+
--- a/gcc/config/darwin.h
57+
+++ b/gcc/config/darwin.h
58+
@@ -285,12 +285,17 @@ extern GTY(()) int darwin_ms_struct;
59+
#define DARWIN_RDYNAMIC "%{rdynamic:%nrdynamic is not supported}"
60+
#endif
61+
62+
-#if LD64_HAS_PLATFORM_VERSION
63+
-#define DARWIN_PLATFORM_ID \
64+
- "%{mmacosx-version-min=*: -platform_version macos %* 0.0} "
65+
+#if LD64_HAS_MACOS_VERSION_MIN
66+
+# define DARWIN_PLATFORM_ID \
67+
+ "%{mmacosx-version-min=*:-macos_version_min %*} "
68+
#else
69+
-#define DARWIN_PLATFORM_ID \
70+
+# if LD64_HAS_PLATFORM_VERSION
71+
+# define DARWIN_PLATFORM_ID \
72+
+ "%{mmacosx-version-min=*: -platform_version macos %* 0.0} "
73+
+# else
74+
+# define DARWIN_PLATFORM_ID \
75+
"%{mmacosx-version-min=*:-macosx_version_min %*} "
76+
+# endif
77+
#endif
78+
79+
/* Code built with mdynamic-no-pic does not support PIE/PIC, so we disallow
80+
diff --git a/gcc/configure b/gcc/configure
81+
index 4f3a50627368..d19d262eedb8 100755
82+
--- a/gcc/configure
83+
+++ b/gcc/configure
84+
@@ -32718,6 +32718,7 @@ if test x"$ld64_flag" = x"yes"; then
85+
# Set defaults for possibly untestable items.
86+
gcc_cv_ld64_export_dynamic=0
87+
gcc_cv_ld64_platform_version=0
88+
+ gcc_cv_ld64_macos_version_min=0
89+
gcc_cv_ld64_demangle=0
90+
91+
if test "$build" = "$host"; then
92+
@@ -32750,6 +32751,7 @@ $as_echo "$gcc_cv_ld64_major" >&6; }
93+
fi
94+
if test "$gcc_cv_ld64_major" -ge 512; then
95+
gcc_cv_ld64_platform_version=1
96+
+ gcc_cv_ld64_macos_version_min=1
97+
fi
98+
elif test -x "$gcc_cv_ld" -a "$darwin_try_test" -eq 1; then
99+
# If the version was not specified, try to find it.
100+
@@ -32788,6 +32790,15 @@ $as_echo_n "checking linker for -platform_version support... " >&6; }
101+
fi
102+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_platform_version" >&5
103+
$as_echo "$gcc_cv_ld64_platform_version" >&6; }
104+
+
105+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker for -macos_version_min" >&5
106+
+$as_echo_n "checking linker for -macos_version_min... " >&6; }
107+
+ gcc_cv_ld64_macos_version_min=1
108+
+ if $gcc_cv_ld -macos_version_min 10.5 < /dev/null 2>&1 | grep 'unknown option' > /dev/null; then
109+
+ gcc_cv_ld64_macos_version_min=0
110+
+ fi
111+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld64_macos_version_min" >&5
112+
+$as_echo "$gcc_cv_ld64_macos_version_min" >&6; }
113+
fi
114+
115+
if test x"${gcc_cv_ld64_version}" != x; then
116+
@@ -32815,6 +32826,12 @@ cat >>confdefs.h <<_ACEOF
117+
#define LD64_HAS_PLATFORM_VERSION $gcc_cv_ld64_platform_version
118+
_ACEOF
119+
120+
+
121+
+
122+
+cat >>confdefs.h <<_ACEOF
123+
+#define LD64_HAS_MACOS_VERSION_MIN $gcc_cv_ld64_macos_version_min
124+
+_ACEOF
125+
+
126+
fi
127+
128+
if test x"$dsymutil_flag" = x"yes"; then
129+
diff --git a/gcc/configure.ac b/gcc/configure.ac
130+
index e12a237ea118..60309421cd1a 100644
131+
--- a/gcc/configure.ac
132+
+++ b/gcc/configure.ac
133+
@@ -6426,6 +6426,7 @@ if test x"$ld64_flag" = x"yes"; then
134+
# Set defaults for possibly untestable items.
135+
gcc_cv_ld64_export_dynamic=0
136+
gcc_cv_ld64_platform_version=0
137+
+ gcc_cv_ld64_macos_version_min=0
138+
gcc_cv_ld64_demangle=0
139+
140+
if test "$build" = "$host"; then
141+
@@ -6456,6 +6457,7 @@ if test x"$ld64_flag" = x"yes"; then
142+
fi
143+
if test "$gcc_cv_ld64_major" -ge 512; then
144+
gcc_cv_ld64_platform_version=1
145+
+ gcc_cv_ld64_macos_version_min=1
146+
fi
147+
elif test -x "$gcc_cv_ld" -a "$darwin_try_test" -eq 1; then
148+
# If the version was not specified, try to find it.
149+
@@ -6486,6 +6488,13 @@ if test x"$ld64_flag" = x"yes"; then
150+
gcc_cv_ld64_platform_version=0
151+
fi
152+
AC_MSG_RESULT($gcc_cv_ld64_platform_version)
153+
+
154+
+ AC_MSG_CHECKING(linker for -macos_version_min)
155+
+ gcc_cv_ld64_macos_version_min=1
156+
+ if $gcc_cv_ld -macos_version_min 10.5 < /dev/null 2>&1 | grep 'unknown option' > /dev/null; then
157+
+ gcc_cv_ld64_macos_version_min=0
158+
+ fi
159+
+ AC_MSG_RESULT($gcc_cv_ld64_macos_version_min)
160+
fi
161+
162+
if test x"${gcc_cv_ld64_version}" != x; then
163+
@@ -6501,6 +6510,9 @@ if test x"$ld64_flag" = x"yes"; then
164+
165+
AC_DEFINE_UNQUOTED(LD64_HAS_PLATFORM_VERSION, $gcc_cv_ld64_platform_version,
166+
[Define to 1 if ld64 supports '-platform_version'.])
167+
+
168+
+ AC_DEFINE_UNQUOTED(LD64_HAS_MACOS_VERSION_MIN, $gcc_cv_ld64_macos_version_min,
169+
+ [Define to 1 if ld64 supports '-macos_version_min'.])
170+
fi
171+
172+
if test x"$dsymutil_flag" = x"yes"; then

Diff for: sys-devel/gcc/gcc-14.2.1_p20241221.ebuild

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ src_prepare() {
4747
# apply big arm64-darwin patch first thing
4848
use elibc_Darwin && eapply "${DISTDIR}"/${PN}-14.2.1-arm64-darwin.patch
4949

50+
# fixes for macOS from upstream
51+
if use elibc_Darwin ; then
52+
eapply "${FILESDIR}"/${PN}-14.2.1-modular-macos-sdk.patch
53+
eapply "${FILESDIR}"/${PN}-14.2.1-pass-macos_version_min.patch
54+
eapply "${FILESDIR}"/${PN}-14.2.1-macos-15-4.patch
55+
fi
56+
5057
# run as with - on pipe (for Clang 16)
5158
eapply "${FILESDIR}"/${PN}-14.2.0-darwin-as-dash-pipe.patch
5259

0 commit comments

Comments
 (0)