commit:     90201360973621a4e27cd43949785d3d654e0945
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Apr  5 13:38:28 2025 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Apr  5 13:38:28 2025 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=90201360

sys-devel/gcc-14.2.1_p20241221: fix building on macOS 15.4

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 sys-devel/gcc/files/gcc-14.2.1-macos-15-4.patch    | 109 +++++++++++++
 .../gcc/files/gcc-14.2.1-modular-macos-sdk.patch   |  38 +++++
 .../files/gcc-14.2.1-pass-macos_version_min.patch  | 172 +++++++++++++++++++++
 sys-devel/gcc/gcc-14.2.1_p20241221.ebuild          |   7 +
 4 files changed, 326 insertions(+)

diff --git a/sys-devel/gcc/files/gcc-14.2.1-macos-15-4.patch 
b/sys-devel/gcc/files/gcc-14.2.1-macos-15-4.patch
new file mode 100644
index 0000000000..6e77a1f7f1
--- /dev/null
+++ b/sys-devel/gcc/files/gcc-14.2.1-macos-15-4.patch
@@ -0,0 +1,109 @@
+From efb88ebe0a6886f816c0d037df33df6556544ad6 Mon Sep 17 00:00:00 2001
+From: Iain Sandoe <[email protected]>
+Date: Thu, 3 Apr 2025 15:53:05 +0100
+Subject: [PATCH] c-family: Support cross-language keywords as an extension.
+
+This allows us compatibility with clang extensions permitting
+C keywords in C++ and vice versa (initially implementing only
+two to deal with specific SDK issues).
+
+Addresses issue #142.
+
+gcc/c-family/ChangeLog:
+
+       * c-common.cc (flag_allow_extra_keywords): Mark
+       _Alignas and _Alignof as usable in C++ when allowed.
+       * c-common.h (D_EXT_C_IN_CXX, D_EXT_CXX_IN_C): New.
+       * c.opt (flag_allow_extra_keywords): New.
+
+gcc/ChangeLog:
+
+       * config/darwin.cc (darwin_override_options): If
+       flag_allow_extra_keywords is not explicitly set then
+       switch it on for Darwin.
+
+gcc/cp/ChangeLog:
+
+       * lex.cc (init_reswords): Handle D_EXT_C_IN_CXX.
+
+Signed-off-by: Iain Sandoe <[email protected]>
+---
+ gcc/c-family/c-common.cc | 4 ++--
+ gcc/c-family/c-common.h  | 2 ++
+ gcc/c-family/c.opt       | 4 ++++
+ gcc/config/darwin.cc     | 4 ++++
+ gcc/cp/lex.cc            | 3 +++
+ 5 files changed, 15 insertions(+), 2 deletions(-)
+
+diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
+index 79dac5fccf30..a038651aa28b 100644
+--- a/gcc/c-family/c-common.cc
++++ b/gcc/c-family/c-common.cc
+@@ -388,8 +388,8 @@ static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
+ */
+ const struct c_common_resword c_common_reswords[] =
+ {
+-  { "_Alignas",               RID_ALIGNAS,   D_CONLY },
+-  { "_Alignof",               RID_ALIGNOF,   D_CONLY },
++  { "_Alignas",               RID_ALIGNAS,   D_EXT_C_IN_CXX },
++  { "_Alignof",               RID_ALIGNOF,   D_EXT_C_IN_CXX },
+   { "_Atomic",                RID_ATOMIC,    D_CONLY },
+   { "_BitInt",                RID_BITINT,    D_CONLY },
+   { "_Bool",          RID_BOOL,      D_CONLY },
+diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
+index 78414d4519e9..5831c8b5af9a 100644
+--- a/gcc/c-family/c-common.h
++++ b/gcc/c-family/c-common.h
+@@ -445,6 +445,8 @@ extern machine_mode c_default_pointer_mode;
+ #define D_CXX20               0x8000  /* In C++, C++20 only.  */
+ #define D_CXX_COROUTINES 0x10000  /* In C++, only with coroutines.  */
+ #define D_CXX_MODULES 0x20000  /* In C++, only with modules.  */
++#define D_EXT_C_IN_CXX        0x40000  /* In C++, allow additional C 
keywords.  */
++#define D_EXT_CXX_IN_C        0x80000  /* In C, allow additional C++ 
keywords.  */
+ 
+ #define D_CXX_CONCEPTS_FLAGS D_CXXONLY | D_CXX_CONCEPTS
+ #define D_CXX_CHAR8_T_FLAGS D_CXXONLY | D_CXX_CHAR8_T
+diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
+index 418e87fa486b..7375dcf95efb 100644
+--- a/gcc/c-family/c.opt
++++ b/gcc/c-family/c.opt
+@@ -1712,6 +1712,10 @@ fallow-extended-attribute-placement
+ C ObjC C++ ObjC++ LTO Var(flag_allow_ext_attr_placement) Init(0)
+ Allow placement of attributes on function definitions.
+ 
++fallow-extra-keywords
++C ObjC C++ ObjC++ LTO Var(flag_allow_extra_keywords) Init(0)
++Allow additional C keywords in C++ and vice versa.
++
+ fcilkplus
+ C ObjC C++ ObjC++ LTO Undocumented Ignore
+ Removed in GCC 8.  This switch has no effect.
+diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
+index e6657753211f..233710ae566f 100644
+--- a/gcc/config/darwin.cc
++++ b/gcc/config/darwin.cc
+@@ -3957,6 +3957,10 @@ darwin_override_options (void)
+     /* Later systems can support aligned common.  */
+     emit_aligned_common = true;
+ 
++  /* We need to consume some C keywords in C++.  */
++  if (!OPTION_SET_P (flag_allow_extra_keywords))
++    flag_allow_extra_keywords = true;
++
+   /* The c_dialect...() macros are not available to us here.  */
+   darwin_running_cxx = (strstr (lang_hooks.name, "C++") != 0);
+ }
+diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc
+index 1110db7f8d07..0c4f93a6787b 100644
+--- a/gcc/cp/lex.cc
++++ b/gcc/cp/lex.cc
+@@ -267,6 +267,9 @@ init_reswords (void)
+     {
+       if (c_common_reswords[i].disable & D_CONLY)
+       continue;
++      if (!flag_allow_extra_keywords
++        && c_common_reswords[i].disable & D_EXT_C_IN_CXX)
++      continue;
+       id = get_identifier (c_common_reswords[i].word);
+       C_SET_RID_CODE (id, c_common_reswords[i].rid);
+       ridpointers [(int) c_common_reswords[i].rid] = id;

diff --git a/sys-devel/gcc/files/gcc-14.2.1-modular-macos-sdk.patch 
b/sys-devel/gcc/files/gcc-14.2.1-modular-macos-sdk.patch
new file mode 100644
index 0000000000..66a9d3d06c
--- /dev/null
+++ b/sys-devel/gcc/files/gcc-14.2.1-modular-macos-sdk.patch
@@ -0,0 +1,38 @@
+From 50f92929f337c81aaf330bb04ac0675dba340e25 Mon Sep 17 00:00:00 2001
+From: Iain Sandoe <[email protected]>
+Date: Sun, 29 Dec 2024 23:06:54 +0000
+Subject: [PATCH] includes, Darwin: Handle modular use for macOS SDKs.
+
+gcc/ChangeLog:
+
+       * ginclude/stddef.h (defined):
+       (__PTRDIFF_T):
+       (__SIZE_T):
+
+Signed-off-by: Iain Sandoe <[email protected]>
+---
+ gcc/ginclude/stddef.h | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
+index be884e96336..16ac9bb0742 100644
+--- a/gcc/ginclude/stddef.h
++++ b/gcc/ginclude/stddef.h
+@@ -89,6 +89,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
+ #undef _PTRDIFF_T_
+ #endif
+ 
++#if defined (__APPLE__)
++# if defined(__has_feature) && __has_feature(modules)
++#  if defined (__need_ptrdiff_t)
++#   undef __PTRDIFF_T
++#  endif
++#  if defined (__need_size_t)
++#   undef __SIZE_T
++#  endif
++# endif
++#endif
++
+ /* On VxWorks, <type/vxTypesBase.h> may have defined macros like
+    _TYPE_size_t which will typedef size_t.  fixincludes patched the
+    vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is

diff --git a/sys-devel/gcc/files/gcc-14.2.1-pass-macos_version_min.patch 
b/sys-devel/gcc/files/gcc-14.2.1-pass-macos_version_min.patch
new file mode 100644
index 0000000000..9b54aaefaa
--- /dev/null
+++ b/sys-devel/gcc/files/gcc-14.2.1-pass-macos_version_min.patch
@@ -0,0 +1,172 @@
+From 407e1099d055eaf39478cfdd933ed8aad273c1cc Mon Sep 17 00:00:00 2001
+From: Iain Sandoe <[email protected]>
+Date: Sun, 9 Mar 2025 09:24:34 +0000
+Subject: [PATCH] Darwin: Pass -macos_version_min to the linker [PR119172].
+
+For binaries to be notarised, the SDK version must be available.
+Since we do not, at present, parse this information we have been
+passing "0.0" to ld64.  This now results in a warning and a fail
+to notarise.  As a quick-fix, we can fall back to letting ld64
+figure out the SDK version (which it does for -macos_version_min).
+
+TODO: Parse the SDKSetting.plist at some point.
+
+cherry-picked from 952e17223d3a9 and fc728cfd569e291a5
+
+       PR target/119172
+
+gcc/ChangeLog:
+
+       * config.in: Regenerate.
+       * config/darwin.h (DARWIN_PLATFORM_ID): Add the option to
+       use -macos_version_min where available.
+       * configure: Regenerate.
+       * configure.ac: Check for ld64 support of -macos_version_min.
+
+Co-authored-by: Andrew Pinski <[email protected]>
+
+Signed-off-by: Iain Sandoe <[email protected]>
+Signed-off-by: Andrew Pinski <[email protected]>
+---
+ gcc/config.in       |  6 ++++++
+ gcc/config/darwin.h | 13 +++++++++----
+ gcc/configure       | 17 +++++++++++++++++
+ gcc/configure.ac    | 12 ++++++++++++
+ 4 files changed, 44 insertions(+), 4 deletions(-)
+
+diff --git a/gcc/config.in b/gcc/config.in
+index f3de4ba6776b..7db2dfdc192b 100644
+--- a/gcc/config.in
++++ b/gcc/config.in
+@@ -2289,6 +2289,12 @@
+ #endif
+ 
+ 
++/* Define to 1 if ld64 supports '-macos_version_min'. */
++#ifndef USED_FOR_TARGET
++#undef LD64_HAS_MACOS_VERSION_MIN
++#endif
++
++
+ /* Define to 1 if ld64 supports '-platform_version'. */
+ #ifndef USED_FOR_TARGET
+ #undef LD64_HAS_PLATFORM_VERSION
+diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
+index 5370511bec21..75050d2197a8 100644
+--- a/gcc/config/darwin.h
++++ b/gcc/config/darwin.h
+@@ -285,12 +285,17 @@ extern GTY(()) int darwin_ms_struct;
+ #define DARWIN_RDYNAMIC "%{rdynamic:%nrdynamic is not supported}"
+ #endif
+ 
+-#if LD64_HAS_PLATFORM_VERSION
+-#define DARWIN_PLATFORM_ID \
+-  "%{mmacosx-version-min=*: -platform_version macos %* 0.0} "
++#if LD64_HAS_MACOS_VERSION_MIN
++# define DARWIN_PLATFORM_ID \
++  "%{mmacosx-version-min=*:-macos_version_min %*} "
+ #else
+-#define DARWIN_PLATFORM_ID \
++# if LD64_HAS_PLATFORM_VERSION
++#  define DARWIN_PLATFORM_ID \
++  "%{mmacosx-version-min=*: -platform_version macos %* 0.0} "
++# else
++#  define DARWIN_PLATFORM_ID \
+   "%{mmacosx-version-min=*:-macosx_version_min %*} "
++# endif
+ #endif
+ 
+ /* Code built with mdynamic-no-pic does not support PIE/PIC, so  we disallow
+diff --git a/gcc/configure b/gcc/configure
+index 4f3a50627368..d19d262eedb8 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -32718,6 +32718,7 @@ if test x"$ld64_flag" = x"yes"; then
+   # Set defaults for possibly untestable items.
+   gcc_cv_ld64_export_dynamic=0
+   gcc_cv_ld64_platform_version=0
++  gcc_cv_ld64_macos_version_min=0
+   gcc_cv_ld64_demangle=0
+ 
+   if test "$build" = "$host"; then
+@@ -32750,6 +32751,7 @@ $as_echo "$gcc_cv_ld64_major" >&6; }
+     fi
+     if test "$gcc_cv_ld64_major" -ge 512; then
+       gcc_cv_ld64_platform_version=1
++      gcc_cv_ld64_macos_version_min=1
+     fi
+   elif test -x "$gcc_cv_ld" -a "$darwin_try_test" -eq 1; then
+     # If the version was not specified, try to find it.
+@@ -32788,6 +32790,15 @@ $as_echo_n "checking linker for -platform_version 
support... " >&6; }
+     fi
+     { $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$gcc_cv_ld64_platform_version" >&5
+ $as_echo "$gcc_cv_ld64_platform_version" >&6; }
++
++    { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker for 
-macos_version_min" >&5
++$as_echo_n "checking linker for -macos_version_min... " >&6; }
++    gcc_cv_ld64_macos_version_min=1
++    if $gcc_cv_ld -macos_version_min 10.5 < /dev/null 2>&1 | grep 'unknown 
option' > /dev/null; then
++      gcc_cv_ld64_macos_version_min=0
++    fi
++    { $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$gcc_cv_ld64_macos_version_min" >&5
++$as_echo "$gcc_cv_ld64_macos_version_min" >&6; }
+   fi
+ 
+   if test x"${gcc_cv_ld64_version}" != x; then
+@@ -32815,6 +32826,12 @@ cat >>confdefs.h <<_ACEOF
+ #define LD64_HAS_PLATFORM_VERSION $gcc_cv_ld64_platform_version
+ _ACEOF
+ 
++
++
++cat >>confdefs.h <<_ACEOF
++#define LD64_HAS_MACOS_VERSION_MIN $gcc_cv_ld64_macos_version_min
++_ACEOF
++
+ fi
+ 
+ if test x"$dsymutil_flag" = x"yes"; then
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index e12a237ea118..60309421cd1a 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -6426,6 +6426,7 @@ if test x"$ld64_flag" = x"yes"; then
+   # Set defaults for possibly untestable items.
+   gcc_cv_ld64_export_dynamic=0
+   gcc_cv_ld64_platform_version=0
++  gcc_cv_ld64_macos_version_min=0
+   gcc_cv_ld64_demangle=0
+ 
+   if test "$build" = "$host"; then
+@@ -6456,6 +6457,7 @@ if test x"$ld64_flag" = x"yes"; then
+     fi
+     if test "$gcc_cv_ld64_major" -ge 512; then
+       gcc_cv_ld64_platform_version=1
++      gcc_cv_ld64_macos_version_min=1
+     fi
+   elif test -x "$gcc_cv_ld" -a "$darwin_try_test" -eq 1; then
+     # If the version was not specified, try to find it.
+@@ -6486,6 +6488,13 @@ if test x"$ld64_flag" = x"yes"; then
+       gcc_cv_ld64_platform_version=0
+     fi
+     AC_MSG_RESULT($gcc_cv_ld64_platform_version)
++
++    AC_MSG_CHECKING(linker for -macos_version_min)
++    gcc_cv_ld64_macos_version_min=1
++    if $gcc_cv_ld -macos_version_min 10.5 < /dev/null 2>&1 | grep 'unknown 
option' > /dev/null; then
++      gcc_cv_ld64_macos_version_min=0
++    fi
++    AC_MSG_RESULT($gcc_cv_ld64_macos_version_min)
+   fi
+ 
+   if test x"${gcc_cv_ld64_version}" != x; then
+@@ -6501,6 +6510,9 @@ if test x"$ld64_flag" = x"yes"; then
+ 
+   AC_DEFINE_UNQUOTED(LD64_HAS_PLATFORM_VERSION, $gcc_cv_ld64_platform_version,
+   [Define to 1 if ld64 supports '-platform_version'.])
++
++  AC_DEFINE_UNQUOTED(LD64_HAS_MACOS_VERSION_MIN, 
$gcc_cv_ld64_macos_version_min,
++  [Define to 1 if ld64 supports '-macos_version_min'.])
+ fi
+ 
+ if test x"$dsymutil_flag" = x"yes"; then

diff --git a/sys-devel/gcc/gcc-14.2.1_p20241221.ebuild 
b/sys-devel/gcc/gcc-14.2.1_p20241221.ebuild
index a070196cdd..740575bca1 100644
--- a/sys-devel/gcc/gcc-14.2.1_p20241221.ebuild
+++ b/sys-devel/gcc/gcc-14.2.1_p20241221.ebuild
@@ -47,6 +47,13 @@ src_prepare() {
        # apply big arm64-darwin patch first thing
        use elibc_Darwin && eapply "${DISTDIR}"/${PN}-14.2.1-arm64-darwin.patch
 
+       # fixes for macOS from upstream
+       if use elibc_Darwin ; then
+               eapply "${FILESDIR}"/${PN}-14.2.1-modular-macos-sdk.patch
+               eapply "${FILESDIR}"/${PN}-14.2.1-pass-macos_version_min.patch
+               eapply "${FILESDIR}"/${PN}-14.2.1-macos-15-4.patch
+       fi
+
        # run as with - on pipe (for Clang 16)
        eapply "${FILESDIR}"/${PN}-14.2.0-darwin-as-dash-pipe.patch
 

Reply via email to