From 654e19fb8311738c9112dce9409ca37ef4d2103f Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Mon, 23 Sep 2024 21:19:20 -0400 Subject: [PATCH] llvmPackages.compiler-rt: always build sanitizers on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also enable TSAN since the SDK has xpc. There’s no reason to disable it. --- .../llvm/common/compiler-rt/default.nix | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix index a6d727739d27..d26ce0628c63 100644 --- a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix @@ -7,6 +7,8 @@ , src ? null , monorepoSrc ? null , runCommand +, apple-sdk +, apple-sdk_10_13 , cmake , ninja , python3 @@ -46,6 +48,14 @@ let baseName = "compiler-rt"; pname = baseName + lib.optionalString (haveLibc) "-libc"; + # Sanitizers require 10.13 or newer. Instead of disabling them for most x86_64-darwin users, + # build them with a newer SDK and the default (10.12) deployment target. + apple-sdk' = + if lib.versionOlder (lib.getVersion apple-sdk) "10.13" then + apple-sdk_10_13.override { enableBootstrap = true; } + else + apple-sdk.override { enableBootstrap = true; }; + src' = if monorepoSrc != null then runCommand "${baseName}-src-${version}" {} '' mkdir -p "$out" @@ -129,29 +139,20 @@ stdenv.mkDerivation ({ "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DSANITIZER_MIN_OSX_VERSION=${stdenv.hostPlatform.darwinMinVersion}" ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 "-DCOMPILER_RT_ENABLE_IOS=OFF" - ]) ++ lib.optionals (lib.versionAtLeast version "19" && stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ - "-DSANITIZER_MIN_OSX_VERSION=10.10" - ] ++ lib.optionals (noSanitizers && lib.versionAtLeast release_version "19") [ + ]) ++ lib.optionals (noSanitizers && lib.versionAtLeast release_version "19") [ "-DCOMPILER_RT_BUILD_CTX_PROFILE=OFF" ] ++ devExtraCmakeFlags; outputs = [ "out" "dev" ]; - # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks - # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra - # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd - # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by - # a flag and turn the flag off during the stdenv build. postPatch = lib.optionalString (!stdenv.hostPlatform.isDarwin) '' substituteInPlace cmake/builtin-config-ix.cmake \ --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.hostPlatform.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' '' + lib.optionalString (!haveLibc) ((lib.optionalString (lib.versionAtLeast release_version "18") '' substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ --replace "" ""