From c810782ee6e95b1a860459f64bd4bb5935039c72 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sat, 8 Jul 2023 00:10:34 -0600 Subject: cctools-llvm: use cctools assembler on x86_64-darwin and LLVM 11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- pkgs/os-specific/darwin/cctools/llvm.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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"} -- cgit 1.4.1