From 3d64e7edbb8c541d03f1f8c86bc7e19f6298aa23 Mon Sep 17 00:00:00 2001 From: Boey Maun Suang Date: Fri, 6 Jan 2023 16:24:50 +1100 Subject: [PATCH] gnat12: Add support for x86_64-darwin --- pkgs/development/compilers/gcc/10/default.nix | 2 +- pkgs/development/compilers/gcc/11/default.nix | 2 +- pkgs/development/compilers/gcc/12/default.nix | 5 ++- .../development/compilers/gcc/4.8/default.nix | 2 +- .../development/compilers/gcc/4.9/default.nix | 2 +- pkgs/development/compilers/gcc/6/default.nix | 2 +- pkgs/development/compilers/gcc/7/default.nix | 2 +- pkgs/development/compilers/gcc/8/default.nix | 2 +- pkgs/development/compilers/gcc/9/default.nix | 2 +- .../ada-cctools-as-detection-configure.patch | 33 +++++++++++++++++++ .../compilers/gcc/common/pre-configure.nix | 27 ++++++++++++++- pkgs/top-level/all-packages.nix | 7 ++++ 12 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 pkgs/development/compilers/gcc/ada-cctools-as-detection-configure.patch diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index e4cebab266e8..b2c2ac9875aa 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -185,7 +185,7 @@ stdenv.mkDerivation ({ preConfigure = (import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; }) + '' ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h ''; diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index de764b9ccc7c..0724eedc29c8 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -189,7 +189,7 @@ stdenv.mkDerivation ({ preConfigure = (import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; }) + '' ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h ''; diff --git a/pkgs/development/compilers/gcc/12/default.nix b/pkgs/development/compilers/gcc/12/default.nix index 3c9362fee1ad..1a4af0ab2869 100644 --- a/pkgs/development/compilers/gcc/12/default.nix +++ b/pkgs/development/compilers/gcc/12/default.nix @@ -109,6 +109,9 @@ let majorVersion = "12"; }) ] + # Fix detection of bootstrap compiler Ada support (cctools as) on Nix Darwin + ++ optional (stdenv.isDarwin && langAda) ../ada-cctools-as-detection-configure.patch + # Obtain latest patch with ../update-mcfgthread-patches.sh ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch; @@ -227,7 +230,7 @@ stdenv.mkDerivation ({ preConfigure = (import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; }) + '' ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h ''; diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index ba084af53ee5..e0c30f35a13d 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -192,7 +192,7 @@ stdenv.mkDerivation ({ preConfigure = import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform langJava langGo crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform langJava langGo crossStageStatic enableMultilib; }; dontDisableStatic = true; diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index c28ef88ce933..d886cc84ecaf 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -212,7 +212,7 @@ stdenv.mkDerivation ({ preConfigure = import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform langJava langGo crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform langJava langGo crossStageStatic enableMultilib; }; dontDisableStatic = true; diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 8bd9d41f1eae..f82070153b78 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -223,7 +223,7 @@ stdenv.mkDerivation ({ preConfigure = import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform gnatboot langJava langAda langGo crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform gnatboot langJava langAda langGo crossStageStatic enableMultilib; }; dontDisableStatic = true; diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 637be9fd971c..076eec21a142 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -191,7 +191,7 @@ stdenv.mkDerivation ({ preConfigure = import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform langGo crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform langGo crossStageStatic enableMultilib; }; dontDisableStatic = true; diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index 4eb47d00c5c2..18054c8c19b9 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -173,7 +173,7 @@ stdenv.mkDerivation ({ preConfigure = import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform langGo crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform langGo crossStageStatic enableMultilib; }; dontDisableStatic = true; diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 4c49cdaa3e25..7cdde48667f6 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -186,7 +186,7 @@ stdenv.mkDerivation ({ preConfigure = import ../common/pre-configure.nix { inherit lib; - inherit version targetPlatform hostPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; + inherit version targetPlatform hostPlatform buildPlatform gnatboot langAda langGo langJit crossStageStatic enableMultilib; }; dontDisableStatic = true; diff --git a/pkgs/development/compilers/gcc/ada-cctools-as-detection-configure.patch b/pkgs/development/compilers/gcc/ada-cctools-as-detection-configure.patch new file mode 100644 index 000000000000..e6b5b3653322 --- /dev/null +++ b/pkgs/development/compilers/gcc/ada-cctools-as-detection-configure.patch @@ -0,0 +1,33 @@ +As originally implemented, the error message check +described in the configure script +breaks detection of Ada compiler support on x86_64-darwin, +because the assembler in the version of cctools currently used +unconditionally emits a deprecation message to stdout, +with no way to disable it. + +Furthermore, GCC 3.4 was the minimum version needed to build GNAT +as far back as GCC 4.4 (see the GCC git repo, tags/releases/gcc-4.4.0, +gcc/doc/install.texi, lines 2052-2053 [1]); +GCC 3.4 is newer than any of the broken GCC versions +that the configure script works around +(see the part of the comment in the configure script +before the context in the patch below), +and GCC 4.4 is older than any GCC that Nix currently packages (GCC 4.8). + +We therefore choose to not check for error messages, +and just check for an error code. +There's no harm in still checking for an object file being created, though. + +[1]: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/doc/install.texi;h=6bdfbece981f7fb6c26da672d45e5d3ba7879c69;hb=b7fc996728085c0591ea7c5d0e1c84a8f6a29bd8#l2052 +--- a/configure 2022-08-19 18:09:52.000000000 +1000 ++++ b/configure 2022-12-26 17:30:49.000000000 +1100 +@@ -5622,8 +5622,7 @@ + # Other compilers, like HP Tru64 UNIX cc, exit successfully when + # given a .adb file, but produce no object file. So we must check + # if an object file was really produced to guard against this. +-errors=`(${CC} -c conftest.adb) 2>&1 || echo failure` +-if test x"$errors" = x && test -f conftest.$ac_objext; then ++if ${CC} -c conftest.adb && test -f conftest.$ac_objext; then + acx_cv_cc_gcc_supports_ada=yes + fi + rm -f conftest.* diff --git a/pkgs/development/compilers/gcc/common/pre-configure.nix b/pkgs/development/compilers/gcc/common/pre-configure.nix index ae5ffe6ab0d0..e3b38eb74e95 100644 --- a/pkgs/development/compilers/gcc/common/pre-configure.nix +++ b/pkgs/development/compilers/gcc/common/pre-configure.nix @@ -1,4 +1,4 @@ -{ lib, version, hostPlatform, targetPlatform +{ lib, version, buildPlatform, hostPlatform, targetPlatform , gnatboot ? null , langAda ? false , langJava ? false @@ -24,6 +24,31 @@ in lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) '' export PATH=${gnatboot}/bin:$PATH '' +# On x86_64-darwin, the gnatboot bootstrap compiler that we need to build a +# native GCC with Ada support emits assembly that is accepted by the Clang +# integrated assembler, but not by the GNU assembler in cctools-port that Nix +# usually in the x86_64-darwin stdenv. In particular, x86_64-darwin gnatboot +# emits MOVQ as the mnemonic for quadword interunit moves, such as between XMM +# and general registers (e.g "movq %xmm0, %rbp"); the cctools-port assembler, +# however, only recognises MOVD for such moves. +# +# Therefore, for native x86_64-darwin builds that support Ada, we have to use +# the Clang integrated assembler to build (at least stage 1 of) GCC, but have to +# target GCC at the cctools-port GNU assembler. In the wrapped x86_64-darwin +# gnatboot, the former is provided as `as`, while the latter is provided as +# `gas`. +# ++ lib.optionalString ( + langAda + && buildPlatform == hostPlatform + && hostPlatform == targetPlatform + && targetPlatform.isx86_64 + && targetPlatform.isDarwin + ) '' + export AS_FOR_BUILD=${gnatboot}/bin/as + export AS_FOR_TARGET=${gnatboot}/bin/gas +'' + # NOTE 2020/3/18: This environment variable prevents configure scripts from # detecting the presence of aligned_alloc on Darwin. There are many facts that # collectively make this fix necessary: diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 32bf99f1c449..d148286bdc5e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14491,6 +14491,13 @@ with pkgs; && stdenv.buildPlatform == stdenv.hostPlatform then buildPackages.gnatboot12 else buildPackages.gnat12; + stdenv = + if stdenv.hostPlatform == stdenv.targetPlatform + && stdenv.buildPlatform == stdenv.hostPlatform + && stdenv.buildPlatform.isDarwin + && stdenv.buildPlatform.isx86_64 + then overrideCC stdenv gnatboot12 + else stdenv; }); gnatboot = gnatboot12;