pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/60279: lang/gcc12: build fails on macos



>Number:         60279
>Category:       pkg
>Synopsis:       gcc12 does not build on macos (SDK 15.5)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 18 09:55:00 +0000 2026
>Originator:     Diogo
>Release:        Darwin 24.6.0
>Organization:
>Environment:
	System: Darwin 24.6.0
	root:xnu-11417.140.69~1/RELEASE_ARM64_T8103 arm64
	xcrun --show-sdk-version: 15.5
	pkgsrc: 2025Q4

>Description:
	While trying to build math/R on macos, the build of gcc12 faileds.
	math/R requires gfortran and macos has it fixed to version 12.


	The error looks like this:
```
libtool: compile:  /usr/local/pkgsrc/lang/gcc12/work/build/./gcc/xgcc -shared-libgcc -B/usr/local/pkgsrc/lang/gcc12/work/build/./gcc -nostdinc++ -L/usr/local/pkgsrc/lang/gcc12/work/build/aarch64-apple-darwin24/libstdc++-v3/src -L/usr/local/pkgsrc/lang/gcc12/work/build/aarch64-apple-darwin24/libstdc++-v3/src/.libs -L/usr/local/pkgsrc/lang/gcc12/work/build/aarch64-apple-darwin24/libstdc++-v3/libsupc++/.libs -B/usr/local/pkg/gcc12/aarch64-apple-darwin24/bin/ -B/usr/local/pkg/gcc12/aarch64-apple-darwin24/lib/ -isystem /usr/local/pkg/gcc12/aarch64-apple-darwin24/include -isystem /usr/local/pkg/gcc12/aarch64-apple-darwin24/sys-include -I/usr/local/pkgsrc/lang/gcc12/work/gcc-12.5.0/libstdc++-v3/../libgcc -I/usr/local/pkgsrc/lang/gcc12/work/build/aarch64-apple-darwin24/libstdc++-v3/include/aarch64-apple-darwin24 -I/usr/local/pkgsrc/lang/gcc12/work/build/aarch64-apple-darwin24/libstdc++-v3/include -I/usr/local/pkgsrc/lang/gcc12/work/gcc-12.5.0/libstdc++-v3/libsupc++ -std=gnu++98 -D_GLIBCXX_SH
 ARED -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi=2 -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -frandom-seed=complex_io.lo -g -O2 -c ../../../../../gcc-12.5.0/libstdc++-v3/src/c++98/complex_io.cc  -fno-common -DPIC -D_GLIBCXX_SHARED -o complex_io.o
In file included from /usr/local/pkgsrc/lang/gcc12/work/build/aarch64-apple-darwin24/libstdc++-v3/include/cmath:45,
                 from /usr/local/pkgsrc/lang/gcc12/work/build/aarch64-apple-darwin24/libstdc++-v3/include/complex:44,
                 from ../../../../../gcc-12.5.0/libstdc++-v3/src/c++98/complex_io.cc:25:
/usr/local/pkgsrc/lang/gcc12/work/build/gcc/include-fixed/math.h:634:8: error: '_Float16' does not name a type
  634 | extern _Float16 __fabsf16(_Float16) __API_AVAILABLE(macos(15.0), ios(18.0), watchos(11.0), tvos(18.0));
      |        ^~~~~~~~
```

>How-To-Repeat:
	cd /usr/local/pkgsrc/lang/gcc12 && bmake package

>Fix:
	Possibly, the best fix would be to move macos requirement to a newer
	gcc version, but gcc13 and gcc14 are also not building on macos.

	So below is a patch for gcc12, which allows the compilation to work with
	the current SDK.

---

diff --git a/lang/gcc12/Makefile b/lang/gcc12/Makefile
index 67c7b97e88c3..a3db7d086559 100644
--- a/lang/gcc12/Makefile
+++ b/lang/gcc12/Makefile
@@ -4,7 +4,7 @@ PKGNAME=	${GCC_PKGNAME}-${GCC12_DIST_VERSION}
 ## When bumping the PKGREVISION of this package the PKGREVISION of
 ## lang/gcc12-libs needs to be bumped to be at least 1 more than the
 ## PKGREVISION of this package!
-#PKGREVISION=	1
+PKGREVISION=	1
 COMMENT=	The GNU Compiler Collection (GCC) - 12.0 Release Series
 
 LANGS=			c
diff --git a/lang/gcc12/distinfo b/lang/gcc12/distinfo
index 4cb2eb533e30..ee0b82e08f21 100644
--- a/lang/gcc12/distinfo
+++ b/lang/gcc12/distinfo
@@ -9,6 +9,8 @@ Size (gcc-12.5.0.tar.xz) = 85897368 bytes
 BLAKE2s (isl-0.16.1.tar.bz2) = 01c3fc657326e81414986eb7ede6f73e540b97009745ced125cdf7f4a8d80f61
 SHA512 (isl-0.16.1.tar.bz2) = c188667a84dc5bdddb4ab7c35f89c91bf15a8171f4fcaf41301cf285fb7328846d9a367c096012fec4cc69d244f0bc9e95d84c09ec097394cd4093076f2a041b
 Size (isl-0.16.1.tar.bz2) = 1626446 bytes
+SHA1 (patch-fixincludes_fixincl.x) = a1569a94f3294bdd85122dae19de0fb718eb39ac
+SHA1 (patch-fixincludes_inclhack.def) = 567f4a5175ddcd42e5bd0a21a72316cb3ffb3d58
 SHA1 (patch-gcc_Makefile.in) = a31ddc27f1092cfdf5ac896ca79c8590b5aceb47
 SHA1 (patch-gcc_config.gcc) = 260f187048260e539e928bb04594b6394bb03912
 SHA1 (patch-gcc_config.host) = bf95dd21bfdf79d173e745fbd35c9bb99fdf4087
@@ -29,4 +31,6 @@ SHA1 (patch-libgcc_crtstuff.c) = a16d465039de00c195cf0694560140a9c38f3a25
 SHA1 (patch-libgfortran_io_io.h) = d44676239a7f45e42054d24bd5224f43c20055c0
 SHA1 (patch-libquadmath_printf_quadmath-printf.c) = 78e09f1e6d61ee57cee83275093cf46b2335d204
 SHA1 (patch-libquadmath_strtod_strtod__l.c) = 6142c10d34174174cce7f06c37eab04dc431b2dc
+SHA1 (patch-libstdc++-v3_include_bits_basic__ios.h) = 6701bd9a6a8f68034bc8fff7989bbebfe1ef71f3
+SHA1 (patch-libstdc++-v3_include_bits_basic__ios.tcc) = 12f7d51f22de44f23e59880ee5b1caba42eadc44
 SHA1 (patch-libstdc++-v3_libsupc++_new__opa.cc) = c8169d28f25c57ba89ffe8c9f897313bb8644382
diff --git a/lang/gcc12/patches/patch-fixincludes_fixincl.x b/lang/gcc12/patches/patch-fixincludes_fixincl.x
new file mode 100644
index 000000000000..14452855135f
--- /dev/null
+++ b/lang/gcc12/patches/patch-fixincludes_fixincl.x
@@ -0,0 +1,94 @@
+$NetBSD$
+
+Keep the pre-generated fixincludes data in sync with the Darwin FP16
+header workaround in inclhack.def.
+
+--- /tmp/fixincl.x.base	2026-04-17 15:12:38
++++ /usr/local/pkgsrc/lang/gcc12/work/gcc-12.5.0/fixincludes/fixincl.x	2026-04-17 15:12:27
+@@ -2835,6 +2835,52 @@
+ 
+ /* * * * * * * * * * * * * * * * * * * * * * * * * *
+  *
++ *  Description of Darwin_Math_Fp16 fix
++ */
++tSCC zDarwin_Math_Fp16Name[] =
++     "darwin_math_fp16";
++
++/*
++ *  File name selection pattern
++ */
++tSCC zDarwin_Math_Fp16List[] =
++  "math.h\0";
++/*
++ *  Machine/OS name selection pattern
++ */
++tSCC* apzDarwin_Math_Fp16Machs[] = {
++        "*-*-darwin*",
++        (const char*)NULL };
++
++/*
++ *  content selection pattern - do fix if pattern found
++ */
++tSCC zDarwin_Math_Fp16Select0[] =
++       "/\\* half precision math functions \\*/";
++
++/*
++ *  content bypass pattern - skip fix if pattern found
++ */
++tSCC zDarwin_Math_Fp16Bypass0[] =
++       "#if !defined\\(__cplusplus\\)";
++
++#define    DARWIN_MATH_FP16_TEST_CT  2
++static tTestDesc aDarwin_Math_Fp16Tests[] = {
++  { TT_NEGREP,   zDarwin_Math_Fp16Bypass0, (regex_t*)NULL },
++  { TT_EGREP,    zDarwin_Math_Fp16Select0, (regex_t*)NULL }, };
++
++/*
++ *  Fix Command Arguments for Darwin_Math_Fp16
++ */
++static const char* apzDarwin_Math_Fp16Patch[] = { sed_cmd_z,
++    "-e", "/\\/\\* half precision math functions \\*\\//a\\\n\
++#if !defined(__cplusplus)",
++    "-e", "/#if (defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090) || \\\\/i\\\n\
++#endif /* !defined(__cplusplus) */",
++    (char*)NULL };
++
++/* * * * * * * * * * * * * * * * * * * * * * * * * *
++ *
+  *  Description of Darwin_Ll_Funcs_Avail fix
+  */
+ tSCC zDarwin_Ll_Funcs_AvailName[] =
+@@ -10864,9 +10910,9 @@
+  *
+  *  List of all fixes
+  */
+-#define REGEX_COUNT          304
++#define REGEX_COUNT          306
+ #define MACH_LIST_SIZE_LIMIT 187
+-#define FIX_COUNT            267
++#define FIX_COUNT            268
+ 
+ /*
+  *  Enumerate the fixes
+@@ -10939,6 +10985,7 @@
+     DARWIN_9_LONG_DOUBLE_FUNCS_2_FIXIDX,
+     DARWIN_EXTERNC_FIXIDX,
+     DARWIN_GCC4_BREAKAGE_FIXIDX,
++    DARWIN_MATH_FP16_FIXIDX,
+     DARWIN_LL_FUNCS_AVAIL_FIXIDX,
+     DARWIN_LONGJMP_NORETURN_FIXIDX,
+     DARWIN_OS_TRACE_1_FIXIDX,
+@@ -11474,8 +11521,13 @@
+   {  zDarwin_Gcc4_BreakageName,    zDarwin_Gcc4_BreakageList,
+      apzDarwin_Gcc4_BreakageMachs,
+      DARWIN_GCC4_BREAKAGE_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
+      aDarwin_Gcc4_BreakageTests,   apzDarwin_Gcc4_BreakagePatch, 0 },
+ 
++  {  zDarwin_Math_Fp16Name,    zDarwin_Math_Fp16List,
++     apzDarwin_Math_Fp16Machs,
++     DARWIN_MATH_FP16_TEST_CT, FD_MACH_ONLY,
++     aDarwin_Math_Fp16Tests,   apzDarwin_Math_Fp16Patch, 0 },
++
+   {  zDarwin_Ll_Funcs_AvailName,    zDarwin_Ll_Funcs_AvailList,
+      apzDarwin_Ll_Funcs_AvailMachs,
+      DARWIN_LL_FUNCS_AVAIL_TEST_CT, FD_MACH_ONLY,
diff --git a/lang/gcc12/patches/patch-fixincludes_inclhack.def b/lang/gcc12/patches/patch-fixincludes_inclhack.def
new file mode 100644
index 000000000000..a87de67c4654
--- /dev/null
+++ b/lang/gcc12/patches/patch-fixincludes_inclhack.def
@@ -0,0 +1,32 @@
+$NetBSD$
+
+Wrap the macOS 15 half-precision declarations so GCC 12 can build with
+Apple's current SDK headers in C++ mode.
+
+--- /usr/local/pkgsrc/lang/gcc12/work/gcc-12.5.0/fixincludes/inclhack.def.orig	2026-04-17 15:10:29
++++ /usr/local/pkgsrc/lang/gcc12/work/gcc-12.5.0/fixincludes/inclhack.def	2026-04-17 15:10:30
+@@ -1379,6 +1379,24 @@
+   c_fix_arg = "((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))";
+   test_text = "#if defined(__GNUC__) && (__GNUC__ >= 3) && "
+   	      "(__GNUC_MINOR__ >= 1)\n";
++};
++
++/*
++ *  macOS 15 <math.h> exposes _Float16 declarations that GCC 12 cannot use
++ *  in C++ mode.
++ */
++fix = {
++  hackname  = darwin_math_fp16;
++  mach      = "*-*-darwin*";
++  files     = math.h;
++  select    = "/\\* half precision math functions \\*/";
++  bypass    = "#if !defined\\(__cplusplus\\)";
++  c_fix     = sed;
++  c_fix_arg = "-e";
++  c_fix_arg = "/\\/\\* half precision math functions \\*\\//a\\\n#if !defined(__cplusplus)";
++  c_fix_arg = "-e";
++  c_fix_arg = "/#if (defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090) || \\\\/i\\\n#endif /* !defined(__cplusplus) */";
++  test_text = "/* half precision math functions */\nextern _Float16 __fmaf16(_Float16, _Float16, _Float16) __API_AVAILABLE(macos(15.0), ios(18.0), watchos(11.0), tvos(18.0));";
+ };
+ 
+ /*
diff --git a/lang/gcc12/patches/patch-libstdc++-v3_include_bits_basic__ios.h b/lang/gcc12/patches/patch-libstdc++-v3_include_bits_basic__ios.h
new file mode 100644
index 000000000000..fdada5f9afb9
--- /dev/null
+++ b/lang/gcc12/patches/patch-libstdc++-v3_include_bits_basic__ios.h
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Cast combined iostate flags explicitly on Darwin.
+
+--- libstdc++-v3/include/bits/basic_ios.h.orig	2025-07-11 08:33:07
++++ libstdc++-v3/include/bits/basic_ios.h
+@@ -155,7 +155,7 @@
+       */
+       void
+       setstate(iostate __state)
+-      { this->clear(this->rdstate() | __state); }
++      { this->clear(iostate(this->rdstate() | __state)); }
+ 
+       // Flip the internal state on for the proper state bits, then
+       // rethrows the propagated exception if bit also set in
diff --git a/lang/gcc12/patches/patch-libstdc++-v3_include_bits_basic__ios.tcc b/lang/gcc12/patches/patch-libstdc++-v3_include_bits_basic__ios.tcc
new file mode 100644
index 000000000000..1e452ba7ae25
--- /dev/null
+++ b/lang/gcc12/patches/patch-libstdc++-v3_include_bits_basic__ios.tcc
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Cast combined iostate flags explicitly on Darwin.
+
+--- libstdc++-v3/include/bits/basic_ios.tcc.orig	2025-07-11 08:33:07
++++ libstdc++-v3/include/bits/basic_ios.tcc
+@@ -43,7 +43,7 @@
+       if (this->rdbuf())
+ 	_M_streambuf_state = __state;
+       else
+-	_M_streambuf_state = __state | badbit;
++	_M_streambuf_state = iostate(__state | badbit);
+       if (this->exceptions() & this->rdstate())
+ 	__throw_ios_failure(__N("basic_ios::clear"));
+     }





Home | Main Index | Thread Index | Old Index