From 3e5acdacdd54b1c8d9c254d6cc722cef7b01aef8 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Mon, 23 Sep 2024 21:19:20 -0400 Subject: [PATCH] llvmPackages.compiler-rt: fix cross-compilation on Darwin When compiler-rt targets Darwin, it is built with `-target`, which causes clang to try to invoke `ld` without a target prefix (e.g., it will try to exec `ld` instead of `x86_64-apple-darwin-ld` on a cross-build to x86_64-darwin). Specifying `--ld-path` overrides that behavior, allowing it to find the appropriate cross-linker. --- .../llvm/common/compiler-rt/default.nix | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix index 8a2cec518033..ad8d837b77ac 100644 --- a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix @@ -84,16 +84,21 @@ stdenv.mkDerivation ({ # This can be removed once the minimum SDK >10.12 on x86_64-darwin. ++ lib.optionals (stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isStatic) [ apple-sdk' ]; - env.NIX_CFLAGS_COMPILE = toString ([ - "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" - ] ++ lib.optionals (!haveLibc) [ - # The compiler got stricter about this, and there is a usellvm patch below - # which patches out the assert include causing an implicit definition of - # assert. It would be nicer to understand why compiler-rt thinks it should - # be able to #include in the first place; perhaps it's in the - # wrong, or perhaps there is a way to provide an assert.h. - "-Wno-error=implicit-function-declaration" - ]); + env = { + NIX_CFLAGS_COMPILE = toString ([ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ] ++ lib.optionals (!haveLibc) [ + # The compiler got stricter about this, and there is a usellvm patch below + # which patches out the assert include causing an implicit definition of + # assert. It would be nicer to understand why compiler-rt thinks it should + # be able to #include in the first place; perhaps it's in the + # wrong, or perhaps there is a way to provide an assert.h. + "-Wno-error=implicit-function-declaration" + ]); + } // lib.optionalAttrs (stdenv.hostPlatform.isDarwin) { + # Work around clang’s trying to invoke unprefixed-ld on Darwin when `-target` is passed. + NIX_CFLAGS_LINK = "--ld-path=${stdenv.cc.bintools}/bin/${stdenv.cc.targetPrefix}ld"; + }; cmakeFlags = [ "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"