Skip to content

Use gcc14 on Darwin aarch64 #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
outpaddling opened this issue Mar 7, 2025 · 29 comments
Open

Use gcc14 on Darwin aarch64 #81

outpaddling opened this issue Mar 7, 2025 · 29 comments

Comments

@outpaddling
Copy link

Any objections to the following quick-fix? Since it's limited to Darwin aarch64, my only concern would be that it may not work on out-of-date macOS / Xcode installations. Not sure if anyone cares about that.

--- a/mk/compiler/gfortran.mk
+++ b/mk/compiler/gfortran.mk
@@ -48,9 +48,12 @@ POSSIBLE_GFORTRAN_VERSION?=  ${CC_VERSION:S/gcc-//:C/.[0-9].[0-9]$//}
 # On a variety of platforms various versions of gfortran are
 # problematic.
 
-# Choose gcc12 for Darwin/aarch64.  \todo Explain why.
-# gcc7 does not build on Darwin 12.6.x, so match aarch64.
-.if ${MACHINE_PLATFORM:MDarwin-*-*}
+# Choose gcc14 for Darwin/aarch64.  This is a quick fix, as gcc14
+# is the only one that builds with the latest Xcode.  We may want
+# to change this after the gcc packages are cleaned up.
+.if ${MACHINE_PLATFORM:MDarwin-*-aarch64*}
+POSSIBLE_GFORTRAN_VERSION=     14
+.elif ${MACHINE_PLATFORM:MDarwin-*-*}
 POSSIBLE_GFORTRAN_VERSION=     12
 .endif
@jperkin
Copy link

jperkin commented Mar 7, 2025

So the initial problem is that this doesn't currently build:

https://us-central.manta.mnx.io/pkgsrc/public/reports/Darwin/12.3/arm64/20250304.1520/gcc14-14.2.0nb1/configure.log

There may also still be issues with building on 12.3 which is what my current binary package set uses. So I'd rather wait a few days and see if I can resolve this next week, unless you have time in the meantime.

@outpaddling
Copy link
Author

Ooops, yeah. I forgot that Adam's patches didn't make it into the dreckly fork, and my gcc14 was installed manually from wip on my M1. So currently, there is no gcc package in dreckly that works on Darwin-aarch64.

@jperkin
Copy link

jperkin commented Mar 7, 2025

gcc12 does, which is what ships in my binary package repository currently, but only on older macOS releases.

@outpaddling
Copy link
Author

outpaddling commented Mar 7, 2025

What approach would you suggest to support modern releases? I think you suggested separate packages for Darwin, maybe do that based on Iain's branches, so we're not maintaining local patch sets?

On the other hand, the current pkgsrc gcc14 just works, so it could at least be used as a stop-gap, assuming it works on older releases as well. Then we fix a ton of packages and can take our time devising a more sustainable solution.

@barracuda156
Copy link

@jperkin Looks like patches fail to apply.
gcc14 must build, so if it does not, something is wrong in the way the port is set up, not with gcc itself.

It should not be too hard to fix it, given that we have a port in MacPorts which builds on every macOS and confirmed to work.

P. S. MacPorts does not enable modula2 and gccrs, though both were building earlier and at least modula should still build. As I recall, they did not need any patches, simply adding to the list of langs worked. But I am not sure about the current status of these two.

@outpaddling
Copy link
Author

outpaddling commented Mar 7, 2025

The problem is that the Homebrew patch set downloaded from Makefile.common:

.if ${MACHINE_PLATFORM:MDarwin-*-aarch64}
BUILDLINK_TRANSFORM+=   rm:-nodefaultrpaths
CONFIGURE_ARGS+=        --disable-darwin-at-rpath
PATCHFILES=             gcc-14.2.0.diff
PATCH_SITES=            https://raw.githubusercontent.com/Homebrew/formula-patches/d5dcb91/gcc/         
PATCH_DIST_STRIP=       -p1
.endif

conflicts with the static patches in lang/gcc14/patches. This was discussed on the pkgsrc mailing lists back in December. The current pkgsrc gcc14 has one (large) unified patch set in the patches dir. There's a copy of it in pkgsrc-wip that I used to install on dreckly.

@outpaddling
Copy link
Author

outpaddling commented Mar 11, 2025

I ran the heavily patched pkgsrc gcc14 through CI so we have a basis for comparison:

https://github.com/drecklypkg/dreckly/actions/runs/13774769853

It also succeeded on my Alma8 installation.

Both this package and the current dreckly gcc14 failed on macOS 12:

System Software Overview:

  System Version: macOS 12.7.6 (21H1320)
  Kernel Version: Darwin 21.6.0
  Boot Volume: mac os
  Boot Mode: Normal
  Computer Name: abalone
  User Name: Jason Bacon (bacon)
  Secure Virtual Memory: Enabled
  System Integrity Protection: Enabled
  Time since boot: 26 days 12:33

 Xcode command-line tools:
 version: 14.2.0.0.1.1668646533

@barracuda156
Copy link

barracuda156 commented Mar 11, 2025

@outpaddling Is there a log (for macOS 12 build failure).

@outpaddling
Copy link
Author

checking for cabs... libtool: compile:  /Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/./gcc/xgcc -shared-libgcc -B/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/./gcc -nostdinc++ -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/src -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/src/.libs -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/libsupc++/.libs -B/Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/bin/ -B/Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/lib/ -isystem /Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/include -isystem /Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/sys-include -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/gcc-14.2.0/libstdc++-v3/../libgcc -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/include/x86_64-apple-darwin21 -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/include -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/gcc-14.2.0/libstdc++-v3/libsupc++ -I/Users/bacon/Dreckly/pkg/include -I/Users/bacon/Dreckly/pkg/include -D_GLIBCXX_SHARED -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi=2 -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -frandom-seed=eh_arm.lo -g -O2 -c ../../../../gcc-14.2.0/libstdc++-v3/libsupc++/eh_arm.cc  -fno-common -DPIC -D_GLIBCXX_SHARED -o eh_arm.o
/Users/bacon/Dreckly/pkg/bin/mksh ../libtool --tag CXX --tag disable-shared   --mode=compile /Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/./gcc/xgcc -shared-libgcc -B/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/./gcc -nostdinc++ -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/src -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/src/.libs -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/libsupc++/.libs -B/Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/bin/ -B/Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/lib/ -isystem /Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/include -isystem /Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/sys-include    -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/gcc-14.2.0/libstdc++-v3/../libgcc -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/include/x86_64-apple-darwin21 -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/include -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/gcc-14.2.0/libstdc++-v3/libsupc++ -I/Users/bacon/Dreckly/pkg/include -I/Users/bacon/Dreckly/pkg/include -prefer-pic -D_GLIBCXX_SHARED -fno-implicit-templates   -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi=2  -fdiagnostics-show-location=once    -ffunction-sections -fdata-sections  -frandom-seed=eh_aux_runtime.lo  -g -O2  -c -o eh_aux_runtime.lo ../../../../gcc-14.2.0/libstdc++-v3/libsupc++/eh_aux_runtime.cc
In file included from ../../../../gcc-14.2.0/libstdc++-v3/libsupc++/eh_arm.cc:26:
../../../../gcc-14.2.0/libstdc++-v3/libsupc++/unwind-cxx.h:92:3: error: '_Unwind_Ptr' does not name a type; did you mean '_Unwind_Action'?
   92 |   _Unwind_Ptr catchTemp;
      |   ^~~~~~~~~~~
      |   _Unwind_Action
../../../../gcc-14.2.0/libstdc++-v3/libsupc++/unwind-cxx.h:146:3: error: '_Unwind_Ptr' does not name a type; did you mean '_Unwind_Action'?
  146 |   _Unwind_Ptr catchTemp;
      |   ^~~~~~~~~~~
      |   _Unwind_Action
gmake[4]: *** [Makefile:777: eh_arm.lo] Error 1
gmake[4]: *** Waiting for unfinished jobs....
libtool: compile:  /Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/./gcc/xgcc -shared-libgcc -B/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/./gcc -nostdinc++ -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/src -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/src/.libs -L/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/libsupc++/.libs -B/Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/bin/ -B/Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/lib/ -isystem /Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/include -isystem /Users/bacon/Dreckly/pkg/gcc14-patched/x86_64-apple-darwin21/sys-include -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/gcc-14.2.0/libstdc++-v3/../libgcc -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/include/x86_64-apple-darwin21 -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/include -I/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/gcc-14.2.0/libstdc++-v3/libsupc++ -I/Users/bacon/Dreckly/pkg/include -I/Users/bacon/Dreckly/pkg/include -D_GLIBCXX_SHARED -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi=2 -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -frandom-seed=eh_aux_runtime.lo -g -O2 -c ../../../../gcc-14.2.0/libstdc++-v3/libsupc++/eh_aux_runtime.cc  -fno-common -DPIC -D_GLIBCXX_SHARED -o eh_aux_runtime.o
In file included from ../../../../gcc-14.2.0/libstdc++-v3/libsupc++/eh_alloc.cc:38:
../../../../gcc-14.2.0/libstdc++-v3/libsupc++/unwind-cxx.h:92:3: error: '_Unwind_Ptr' does not name a type; did you mean '_Unwind_Action'?
   92 |   _Unwind_Ptr catchTemp;
      |   ^~~~~~~~~~~
      |   _Unwind_Action
../../../../gcc-14.2.0/libstdc++-v3/libsupc++/unwind-cxx.h:146:3: error: '_Unwind_Ptr' does not name a type; did you mean '_Unwind_Action'?
  146 |   _Unwind_Ptr catchTemp;
      |   ^~~~~~~~~~~
      |   _Unwind_Action
yes
checking for cabsl... gmake[4]: *** [Makefile:777: eh_alloc.lo] Error 1
In file included from ../../../../gcc-14.2.0/libstdc++-v3/libsupc++/eh_aux_runtime.cc:29:
../../../../gcc-14.2.0/libstdc++-v3/libsupc++/unwind-cxx.h:92:3: error: '_Unwind_Ptr' does not name a type; did you mean '_Unwind_Action'?
   92 |   _Unwind_Ptr catchTemp;
      |   ^~~~~~~~~~~
      |   _Unwind_Action
../../../../gcc-14.2.0/libstdc++-v3/libsupc++/unwind-cxx.h:146:3: error: '_Unwind_Ptr' does not name a type; did you mean '_Unwind_Action'?
  146 |   _Unwind_Ptr catchTemp;
      |   ^~~~~~~~~~~
      |   _Unwind_Action
gmake[4]: *** [Makefile:777: eh_aux_runtime.lo] Error 1
gmake[4]: Leaving directory '/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3/libsupc++'
gmake[3]: *** [Makefile:577: all-recursive] Error 1
gmake[3]: Leaving directory '/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3'
gmake[2]: *** [Makefile:502: all] Error 2
gmake[2]: Leaving directory '/Users/bacon/Dreckly/dreckly/lang/gcc14-patched/work/build/x86_64-apple-darwin21/libstdc++-v3'
gmake[1]: *** [Makefile:13559: all-target-libstdc++-v3] Error 2
gmake[1]: *** Waiting for unfinished jobs....

@barracuda156
Copy link

barracuda156 commented Mar 11, 2025

@outpaddling This is probably related to libunwind-headers being found. See, for example: https://trac.macports.org/ticket/43869
And: https://trac.macports.org/ticket/57198
I don’t know how pkgsrc uses libunwind-headers. MacPorts requires to deactivate them prior to building ports which conflict with them (like gcc).

@jperkin
Copy link

jperkin commented Mar 11, 2025

Yeh my plan was to have a separate build for Darwin, similar to how I have a separate build for the illumos patchset at https://github.com/TritonDataCenter/pkgsrc-extra/tree/main/gcc13. I did look briefly last week or so at seeing if there was a way to reasonably split OPSYS-specific bits from a single package but it just ends up too complicated.

@outpaddling
Copy link
Author

I'm not clear on what you mean by "split OPSYS-specific bits from a single package". Do you mean separate gcc packages for different platforms, e.g. gcc14-sun, fcc14-darwin? Or split OPSYS-specific bits within the same package?

@jperkin
Copy link

jperkin commented Mar 12, 2025

Yeh separate packages, at least for these platforms where there are huge patchsets required.

It is possible to combine everything into one, and you end up with e.g. patches.Darwin/ and distinfo.Darwin but it's messy, and ultimately these packages are already way too complicated and suffer from historical baggage.

My SunOS-specific gcc13 package is significantly cleaner than lang/gcc13, for example.

@outpaddling
Copy link
Author

OK, good - I've been leaning toward separate packages as well, but haven't given this nearly as much thought as you have. What I was thinking: Since GCC deps are already managed through mk files, it seems like it would be pretty easy to split off a package for a particular platform. For the Darwin packages, we could look into using Iain's distfiles as upstream, so they would require minimal local patches and updates would be simple.

@jperkin
Copy link

jperkin commented Mar 12, 2025

Yeh exactly. My SunOS package uses the illumos branches on GitHub as upstream so that patches/ only includes minimal overrides.

@barracuda156
Copy link

For the Darwin packages, we could look into using Iain's distfiles as upstream, so they would require minimal local patches and updates would be simple.

That will certainly reduce patches required, and we do want to use Iain’s branches on macOS in any case, whether directly or via patching a gcc release.

By the way, is there an intent to have these merged into pkgsrc upstream? If yes, then a patch applied to an official release may still be preferable (which is what MacPorts does). If not, then using Iain’s branches directly is easier.

@jperkin
Copy link

jperkin commented Mar 12, 2025

Tracking the branches directly keeps our packages much cleaner and should be the way forward for these specific packages, consistent with our core value of maintainability.

@barracuda156
Copy link

Tracking the branches directly keeps our packages much cleaner and should be the way forward for these specific packages, consistent with our core value of maintainability.

Yeah, that makes sense.

@outpaddling
Copy link
Author

By the way, is there an intent to have these merged into pkgsrc upstream? If yes, then a patch applied to an official release may still be preferable (which is what MacPorts does). If not, then using Iain’s branches directly is easier.

That would be up to the pkgsrc package maintainer(s). There will undoubtedly be a lot of updates and fixes copied between dreckly and pkgsrc, but they are independent package managers moving in different directions.

Using Iain's branches directly would also be a good way to thoroughly test his patches, and ultimately help justify upstreaming them.

@outpaddling
Copy link
Author

FYI, the gcc14-darwin package in the ci/gcc14 branch appears to work fine on my M1 and my old x86 Macbook:

ProductName: macOS
ProductVersion: 15.3.2
BuildVersion: 24D81

ProductName: macOS
ProductVersion: 12.7.6
BuildVersion: 21H1320

What remains to be done before committing it to trunk?

outpaddling added a commit to outpaddling/dreckly that referenced this issue Apr 27, 2025
This is an incremental patch to support the use of platform-specific
gcc14 packages.  It will have no effect until such packages are
added.

This only effects gfortran dependencies for now, as our only available
test port is gcc14-darwin (in ci/gcc14 branch), and darwin is
clang-based.  We will need similar updates to gcc.mk if/when
platform-specific gcc packages are created for gcc-based platforms.

Also update default to gcc14 for all Darwin per discussion in drecklypkg#81.
@outpaddling
Copy link
Author

It would be good if others could test https://github.com/drecklypkg/dreckly/tree/ci/gcc14/lang/gcc14-darwin on as many macOS versions and CPUs as possible. As I mentioned above, I have tested it on 12/x86_64 and 15/aarch64. We also have 13/x86_64 in CI, but that's the extent of what I can test right now.

@barracuda156
Copy link

@outpaddling Since the build requires C++11 (which is correct), it must use a C++11-capable compiler, but I do not see that in the port. Is it picked based on declared C++11 standard? If not, then we know for sure it will fail on systems where Xcode compiler has no C++11 support.

@outpaddling
Copy link
Author

@barracuda156 Good point. I wouldn't worry about building gcc14-darwin directly with the native compiler on a system that old. I'm mainly concerned about avoiding regressions on recent macOS versions that I can't test. If someone really wants to use such an old OS, they' should probably just use the newest gfortran that the native compiler can build, rather than 14. Or maybe one of the same vintage as the native gcc to ensure compatibility.

@barracuda156
Copy link

The correct procedure, very well tested, is to build gcc10 and use that to build gcc14. It is implemented in MacPorts, for example, and it is a way recommended by gcc upstream. We do not want some archaic gfortran, really, on any systems. And it is better to have the same primary compiler across all systems, rather than a zoo of versions. gcc14 works back to 10.4. And while specifically 10.4 is less-trivial due to Xcode toolchain issues, 10.5+ can be easily supported.

@barracuda156
Copy link

There is arguably no need to re-invent a bicycle, what is needed is simply to translate existing logic in tcl into perl, and have gcc10-bootstrap port for the purpose of building gcc14 starting from Xcode with no C++11 support.

@barracuda156
Copy link

@catap Kirill, would it be hard to port gcc10-bootstrap to pkgsrc (to use on macOS, not NetBSD)?

@catap
Copy link

catap commented Apr 28, 2025

@barracuda156 if you use my branch it shouldn't be a big deal to be honest.

The main pain was to fight with multiarch in macports :)

@barracuda156
Copy link

Hopefully universal builds is not a concern here. (I gave up on them myself, it is just too broken across numerous ports.)

@outpaddling
Copy link
Author

There is arguably no need to re-invent a bicycle, what is needed is simply to translate existing logic in tcl into perl, and have gcc10-bootstrap port for the purpose of building gcc14 starting from Xcode with no C++11 support.

If I were interested in gcc14 on an EOL macOS platform, I would probably install gcc10 in a separate dreckly tree used just for bootstrapping a second tree for general use. This would avoid adding a lot of complexity to the dreckly gcc packages that would consume man-hours, lead to more bugs, and wouldn't benefit most dreckly users. We had a discussion about this on the pkgsrc-users list years ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants