summary refs log tree commit diff
diff options
context:
space:
mode:
authorRandy Eckenrode <randy@largeandhighquality.com>2023-07-08 00:10:34 -0600
committerRandy Eckenrode <randy@largeandhighquality.com>2023-07-09 13:29:11 -0600
commitc810782ee6e95b1a860459f64bd4bb5935039c72 (patch)
tree802fd26d06042e25b57e7fdbcd3d3552fecac29a
parenta61c7c58e4bbfa5bce895d505aa2eaed6dc40176 (diff)
downloadnixpkgs-c810782ee6e95b1a860459f64bd4bb5935039c72.tar
nixpkgs-c810782ee6e95b1a860459f64bd4bb5935039c72.tar.gz
nixpkgs-c810782ee6e95b1a860459f64bd4bb5935039c72.tar.bz2
nixpkgs-c810782ee6e95b1a860459f64bd4bb5935039c72.tar.lz
nixpkgs-c810782ee6e95b1a860459f64bd4bb5935039c72.tar.xz
nixpkgs-c810782ee6e95b1a860459f64bd4bb5935039c72.tar.zst
nixpkgs-c810782ee6e95b1a860459f64bd4bb5935039c72.zip
cctools-llvm: use cctools assembler on x86_64-darwin and LLVM 11
Clang 11 performs an optimization on x86_64 that is sensitive to the
presence of debug information. This results in GCC’s bootstrap failing
because it builds stage 2 with debug information and stage 3 without,
and the resulting objects do not match.

This patch uses the cctools assembler on LLVM 11 and x86_64-darwin while
using the integrated assembler on newer versions, which matches the
platform tools (Apple has uses the integrated assembler since Xcode 12).
-rw-r--r--pkgs/os-specific/darwin/cctools/llvm.nix9
1 files changed, 8 insertions, 1 deletions
diff --git a/pkgs/os-specific/darwin/cctools/llvm.nix b/pkgs/os-specific/darwin/cctools/llvm.nix
index dcaca355af5..f2986bf872f 100644
--- a/pkgs/os-specific/darwin/cctools/llvm.nix
+++ b/pkgs/os-specific/darwin/cctools/llvm.nix
@@ -20,6 +20,10 @@ let
   # not appear to have issues, but the source is not available yet (as of June 2023).
   useLLVMStrip = lib.versionAtLeast llvmVersion "15" || lib.versionAtLeast cctoolsVersion "1005.2";
 
+  # Clang 11 performs an optimization on x86_64 that is sensitive to the presence of debug info.
+  # This causes GCC to fail to bootstrap due to object file differences between stages 2 and 3.
+  useClangAssembler = lib.versionAtLeast llvmVersion "12" || !stdenv.isx86_64;
+
   llvm_bins = [
     "dwarfdump"
     "nm"
@@ -52,7 +56,8 @@ let
   ]
   ++ lib.optional (!useLLVMBitcodeStrip) "bitcode_strip"
   ++ lib.optional (!useLLVMOtool) "otool"
-  ++ lib.optional (!useLLVMStrip) "strip";
+  ++ lib.optional (!useLLVMStrip) "strip"
+  ++ lib.optional (!useClangAssembler) "as";
 
   targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-";
 
@@ -79,10 +84,12 @@ stdenv.mkDerivation {
     mkdir -p "$out/bin" "$man"
     ln -s ${lib.getDev cctools-port} "$dev"
 
+  '' + lib.optionalString useClangAssembler ''
     # Use the clang-integrated assembler instead of using `as` from cctools.
     makeWrapper "${lib.getBin llvmPackages.clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \
       --add-flags "-x assembler -integrated-as -c"
 
+  '' + ''
     ln -s "${lib.getBin llvmPackages.bintools-unwrapped}/bin/${targetPrefix}llvm-ar" "$out/bin/${targetPrefix}ar"
     ${linkManPages llvmPackages.llvm-manpages "llvm-ar" "ar"}