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).
This commit is contained in:
Randy Eckenrode 2023-07-08 00:10:34 -06:00
parent a61c7c58e4
commit c810782ee6
No known key found for this signature in database
GPG key ID: 64C1CD4EC2A600D9

View file

@ -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"}