diff options
Diffstat (limited to 'nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix')
-rw-r--r-- | nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix b/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix index 11ec2b4d04fa..f2986bf872f7 100644 --- a/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix +++ b/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix @@ -1,9 +1,11 @@ # Create a cctools-compatible bintools that uses equivalent tools from LLVM in place of the ones # from cctools when possible. -{ lib, stdenv, makeWrapper, cctools-port, llvmPackages, enableManpages ? true }: +{ lib, stdenv, makeWrapper, cctools-port, llvmPackages, enableManpages ? stdenv.targetPlatform == stdenv.hostPlatform }: let + inherit (stdenv) targetPlatform hostPlatform; + cctoolsVersion = lib.getVersion cctools-port; llvmVersion = llvmPackages.release_version; @@ -18,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" @@ -50,9 +56,10 @@ let ] ++ lib.optional (!useLLVMBitcodeStrip) "bitcode_strip" ++ lib.optional (!useLLVMOtool) "otool" - ++ lib.optional (!useLLVMStrip) "strip"; + ++ lib.optional (!useLLVMStrip) "strip" + ++ lib.optional (!useClangAssembler) "as"; - inherit (stdenv.cc) targetPrefix; + targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; linkManPages = pkg: source: target: lib.optionalString enableManpages '' sourcePath=${pkg}/share/man/man1/${source}.1.gz @@ -77,11 +84,13 @@ 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/llvm-ar" "$out/bin/${targetPrefix}ar" + '' + '' + ln -s "${lib.getBin llvmPackages.bintools-unwrapped}/bin/${targetPrefix}llvm-ar" "$out/bin/${targetPrefix}ar" ${linkManPages llvmPackages.llvm-manpages "llvm-ar" "ar"} for tool in ${toString llvm_bins}; do @@ -97,7 +106,7 @@ stdenv.mkDerivation { ${linkManPages (lib.getMan cctools-port) "ld64" "ld64"} ${lib.optionalString (!useLLVMOtool) # The actual man page for otool in cctools is llvm-otool - linkManPages (lib.getMan cctools-port) "llvm-otool" "llvm-otool"} + (linkManPages (lib.getMan cctools-port) "llvm-otool" "llvm-otool")} ''; passthru = { inherit targetPrefix; }; |