diff options
author | Tristan Ross <tristan.ross@midstall.com> | 2024-03-28 11:18:31 -0700 |
---|---|---|
committer | Tristan Ross <tristan.ross@midstall.com> | 2024-04-12 13:38:29 -0700 |
commit | 312264686e6e803fbe5c2b1b6b1dc1815166f13a (patch) | |
tree | 7fd1cec8d10f83316084268e8883735d6ba0c5f8 /pkgs/development/compilers/llvm | |
parent | 6ac255deb576100fd80f3114ef852429bac02f6a (diff) |
llvmPackages_{12,13,14,15,16,17,18,git}: use common compiler-rt
Diffstat (limited to 'pkgs/development/compilers/llvm')
16 files changed, 281 insertions, 1084 deletions
diff --git a/pkgs/development/compilers/llvm/12/compiler-rt/default.nix b/pkgs/development/compilers/llvm/12/compiler-rt/default.nix deleted file mode 100644 index e11a1b397e764..0000000000000 --- a/pkgs/development/compilers/llvm/12/compiler-rt/default.nix +++ /dev/null @@ -1,131 +0,0 @@ -{ lib, stdenv, llvm_meta, version, fetch -, cmake, python3, xcbuild, libllvm, linuxHeaders, libxcrypt -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD -}: - -let - - useLLVM = stdenv.hostPlatform.useLLVM or false; - bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; - haveLibc = stdenv.cc.libc != null; - inherit (stdenv.hostPlatform) isMusl; - -in - -stdenv.mkDerivation { - pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; - inherit version; - src = fetch "compiler-rt" "1950rg294izdwkaasi7yjrmadc9mzdd5paf0q63jjcq2m3rdbj5l"; - - nativeBuildInputs = [ cmake python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; - - env.NIX_CFLAGS_COMPILE = toString [ - "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" - ]; - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - ./gnu-install-dirs.patch - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - ./armv7l.patch - # Fix build on armv6l - ../../common/compiler-rt/armv6-mcr-dmb.patch - ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch - ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch - ]; - - # 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.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM) '' - substituteInPlace lib/builtins/int_util.c \ - --replace "#include <stdlib.h>" "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include <assert.h>" "" - substituteInPlace lib/builtins/cpu_model.c \ - --replace "#include <assert.h>" "" - ''; - - preConfigure = lib.optionalString (useLLVM && !haveLibc) '' - cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a - ''; - - meta = llvm_meta // { - homepage = "https://compiler-rt.llvm.org/"; - description = "Compiler runtime libraries"; - mainProgram = "hwasan_symbolize"; - longDescription = '' - The compiler-rt project provides highly tuned implementations of the - low-level code generator support routines like "__fixunsdfdi" and other - calls generated when a target doesn't have a short sequence of native - instructions to implement a core IR operation. It also provides - implementations of run-time libraries for dynamic testing tools such as - AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. - ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - # compiler-rt requires a Clang stdenv on 32-bit RISC-V: - # https://reviews.llvm.org/D43106#1019077 - broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; - }; -} diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix index bd87dc5f34f03..6803b315496e3 100644 --- a/pkgs/development/compilers/llvm/12/default.nix +++ b/pkgs/development/compilers/llvm/12/default.nix @@ -230,14 +230,44 @@ let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + src = fetch "compiler-rt" "1950rg294izdwkaasi7yjrmadc9mzdd5paf0q63jjcq2m3rdbj5l"; + patches = [ + ../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./compiler-rt/armv7l.patch + # Fix build on armv6l + ../common/compiler-rt/armv6-mcr-dmb.patch + ../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + src = fetch "compiler-rt" "1950rg294izdwkaasi7yjrmadc9mzdd5paf0q63jjcq2m3rdbj5l"; + patches = [ + ../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./compiler-rt/armv7l.patch + # Fix build on armv6l + ../common/compiler-rt/armv6-mcr-dmb.patch + ../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt diff --git a/pkgs/development/compilers/llvm/13/compiler-rt/default.nix b/pkgs/development/compilers/llvm/13/compiler-rt/default.nix deleted file mode 100644 index 3c83e4e58a178..0000000000000 --- a/pkgs/development/compilers/llvm/13/compiler-rt/default.nix +++ /dev/null @@ -1,138 +0,0 @@ -{ lib, stdenv, llvm_meta, version, src -, cmake, python3, xcbuild, libllvm, linuxHeaders, libxcrypt -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD -}: - -let - - useLLVM = stdenv.hostPlatform.useLLVM or false; - bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; - haveLibc = stdenv.cc.libc != null; - inherit (stdenv.hostPlatform) isMusl isAarch64; - -in - -stdenv.mkDerivation { - pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; - inherit version; - - inherit src; - sourceRoot = "${src.name}/compiler-rt"; - - nativeBuildInputs = [ cmake python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; - - env.NIX_CFLAGS_COMPILE = toString [ - "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" - ]; - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isAarch64) [ - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # Prevent a compilation error on darwin - ./darwin-targetconditionals.patch - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - ./armv7l.patch - # Fix build on armv6l - ../../common/compiler-rt/armv6-mcr-dmb.patch - ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch - ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch - ../../common/compiler-rt/armv6-scudo-no-yield.patch - ../../common/compiler-rt/armv6-scudo-libatomic.patch - ]; - - # 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.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM) '' - substituteInPlace lib/builtins/int_util.c \ - --replace "#include <stdlib.h>" "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include <assert.h>" "" - substituteInPlace lib/builtins/cpu_model.c \ - --replace "#include <assert.h>" "" - ''; - - preConfigure = lib.optionalString (useLLVM && !haveLibc) '' - cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a - ''; - - meta = llvm_meta // { - homepage = "https://compiler-rt.llvm.org/"; - description = "Compiler runtime libraries"; - mainProgram = "hwasan_symbolize"; - longDescription = '' - The compiler-rt project provides highly tuned implementations of the - low-level code generator support routines like "__fixunsdfdi" and other - calls generated when a target doesn't have a short sequence of native - instructions to implement a core IR operation. It also provides - implementations of run-time libraries for dynamic testing tools such as - AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. - ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - # compiler-rt requires a Clang stdenv on 32-bit RISC-V: - # https://reviews.llvm.org/D43106#1019077 - broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; - }; -} diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index 429dfe5f1f3ee..1033543240b36 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -267,14 +267,48 @@ in let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version src; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./compiler-rt/armv7l.patch + # Fix build on armv6l + ../common/compiler-rt/armv6-mcr-dmb.patch + ../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ../common/compiler-rt/armv6-scudo-no-yield.patch + ../common/compiler-rt/armv6-scudo-libatomic.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./compiler-rt/armv7l.patch + # Fix build on armv6l + ../common/compiler-rt/armv6-mcr-dmb.patch + ../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ../common/compiler-rt/armv6-scudo-no-yield.patch + ../common/compiler-rt/armv6-scudo-libatomic.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt diff --git a/pkgs/development/compilers/llvm/14/compiler-rt/default.nix b/pkgs/development/compilers/llvm/14/compiler-rt/default.nix deleted file mode 100644 index 3482ed343c5a0..0000000000000 --- a/pkgs/development/compilers/llvm/14/compiler-rt/default.nix +++ /dev/null @@ -1,146 +0,0 @@ -{ lib, stdenv, llvm_meta, version -, monorepoSrc, runCommand -, cmake, python3, xcbuild, libllvm, linuxHeaders, libxcrypt -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD -}: - -let - - useLLVM = stdenv.hostPlatform.useLLVM or false; - bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; - haveLibc = stdenv.cc.libc != null; - inherit (stdenv.hostPlatform) isMusl; - - baseName = "compiler-rt"; - - src = runCommand "${baseName}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${baseName} "$out" - ''; -in - -stdenv.mkDerivation { - pname = baseName + lib.optionalString (haveLibc) "-libc"; - inherit version; - - inherit src; - sourceRoot = "${src.name}/${baseName}"; - - nativeBuildInputs = [ cmake python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; - - env.NIX_CFLAGS_COMPILE = toString [ - "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" - ]; - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - ./gnu-install-dirs.patch - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # Prevent a compilation error on darwin - ./darwin-targetconditionals.patch - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - ./armv7l.patch - # Fix build on armv6l - ../../common/compiler-rt/armv6-mcr-dmb.patch - ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch - ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch - ../../common/compiler-rt/armv6-scudo-no-yield.patch - ../../common/compiler-rt/armv6-scudo-libatomic.patch - ]; - - # 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.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM) '' - substituteInPlace lib/builtins/int_util.c \ - --replace "#include <stdlib.h>" "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include <assert.h>" "" - substituteInPlace lib/builtins/cpu_model.c \ - --replace "#include <assert.h>" "" - ''; - - preConfigure = lib.optionalString (useLLVM && !haveLibc) '' - cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a - ''; - - meta = llvm_meta // { - homepage = "https://compiler-rt.llvm.org/"; - description = "Compiler runtime libraries"; - mainProgram = "hwasan_symbolize"; - longDescription = '' - The compiler-rt project provides highly tuned implementations of the - low-level code generator support routines like "__fixunsdfdi" and other - calls generated when a target doesn't have a short sequence of native - instructions to implement a core IR operation. It also provides - implementations of run-time libraries for dynamic testing tools such as - AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. - ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - # compiler-rt requires a Clang stdenv on 32-bit RISC-V: - # https://reviews.llvm.org/D43106#1019077 - broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; - }; -} diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix index 6dcdcfa925840..6d618b38b3bfc 100644 --- a/pkgs/development/compilers/llvm/14/default.nix +++ b/pkgs/development/compilers/llvm/14/default.nix @@ -266,14 +266,50 @@ in let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 release_version version monorepoSrc; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./compiler-rt/armv7l.patch + # Fix build on armv6l + ../common/compiler-rt/armv6-mcr-dmb.patch + ../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ../common/compiler-rt/armv6-scudo-no-yield.patch + ../common/compiler-rt/armv6-scudo-libatomic.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./compiler-rt/armv7l.patch + # Fix build on armv6l + ../common/compiler-rt/armv6-mcr-dmb.patch + ../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ../common/compiler-rt/armv6-scudo-no-yield.patch + ../common/compiler-rt/armv6-scudo-libatomic.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt diff --git a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix b/pkgs/development/compilers/llvm/15/compiler-rt/default.nix deleted file mode 100644 index d257c69cbcd05..0000000000000 --- a/pkgs/development/compilers/llvm/15/compiler-rt/default.nix +++ /dev/null @@ -1,145 +0,0 @@ -{ lib, stdenv, llvm_meta, version -, monorepoSrc, runCommand -, cmake, ninja, python3, xcbuild, libllvm, linuxHeaders, libxcrypt -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD -}: - -let - - useLLVM = stdenv.hostPlatform.useLLVM or false; - bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; - haveLibc = stdenv.cc.libc != null; - inherit (stdenv.hostPlatform) isMusl; - - baseName = "compiler-rt"; - - src = runCommand "${baseName}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${baseName} "$out" - ''; -in - -stdenv.mkDerivation { - pname = baseName + lib.optionalString (haveLibc) "-libc"; - inherit version; - - inherit src; - sourceRoot = "${src.name}/${baseName}"; - - nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; - - env.NIX_CFLAGS_COMPILE = toString [ - "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" - ]; - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - - # `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" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - ./gnu-install-dirs.patch - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # Prevent a compilation error on darwin - ./darwin-targetconditionals.patch - # See: https://github.com/NixOS/nixpkgs/pull/186575 - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 - ../../common/compiler-rt/armv7l-15.patch - ]; - - # 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.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM) '' - substituteInPlace lib/builtins/int_util.c \ - --replace "#include <stdlib.h>" "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include <assert.h>" "" - substituteInPlace lib/builtins/cpu_model.c \ - --replace "#include <assert.h>" "" - ''; - - preConfigure = lib.optionalString (useLLVM && !haveLibc) '' - cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a - ''; - - meta = llvm_meta // { - homepage = "https://compiler-rt.llvm.org/"; - description = "Compiler runtime libraries"; - mainProgram = "hwasan_symbolize"; - longDescription = '' - The compiler-rt project provides highly tuned implementations of the - low-level code generator support routines like "__fixunsdfdi" and other - calls generated when a target doesn't have a short sequence of native - instructions to implement a core IR operation. It also provides - implementations of run-time libraries for dynamic testing tools such as - AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. - ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - # compiler-rt requires a Clang stdenv on 32-bit RISC-V: - # https://reviews.llvm.org/D43106#1019077 - broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; - }; -} diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index dcafd2970d005..0e3564c772489 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -281,14 +281,40 @@ in let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt diff --git a/pkgs/development/compilers/llvm/16/compiler-rt/default.nix b/pkgs/development/compilers/llvm/16/compiler-rt/default.nix deleted file mode 100644 index 2a15e5302b463..0000000000000 --- a/pkgs/development/compilers/llvm/16/compiler-rt/default.nix +++ /dev/null @@ -1,159 +0,0 @@ -{ lib, stdenv, llvm_meta, version -, monorepoSrc, runCommand -, cmake, ninja, python3, xcbuild, libllvm, linuxHeaders, libxcrypt -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD -}: - -let - - useLLVM = stdenv.hostPlatform.useLLVM or false; - bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; - haveLibc = stdenv.cc.libc != null; - isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; - inherit (stdenv.hostPlatform) isMusl; - - baseName = "compiler-rt"; - - src = runCommand "${baseName}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${baseName} "$out" - ''; -in - -stdenv.mkDerivation { - pname = baseName + lib.optionalString (haveLibc) "-libc"; - inherit version; - - inherit src; - sourceRoot = "${src.name}/${baseName}"; - - nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; - - 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 <assert.h> 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" - ]); - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [ - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM && !haveLibc) [ - "-DCMAKE_C_FLAGS=-nodefaultlibs" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - - # `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" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - ./gnu-install-dirs.patch - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # Prevent a compilation error on darwin - ./darwin-targetconditionals.patch - # See: https://github.com/NixOS/nixpkgs/pull/186575 - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 - # ../../common/compiler-rt/armv7l-15.patch - ]; - - # 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.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM && !haveLibc) '' - substituteInPlace lib/builtins/int_util.c \ - --replace "#include <stdlib.h>" "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include <assert.h>" "" - substituteInPlace lib/builtins/cpu_model.c \ - --replace "#include <assert.h>" "" - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: - # The presence of crtbegin_shared has been added and removed; it's possible - # people have added/removed it to get it working on their platforms. - # Try each in turn for now. - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a - ''; - - meta = llvm_meta // { - homepage = "https://compiler-rt.llvm.org/"; - description = "Compiler runtime libraries"; - mainProgram = "hwasan_symbolize"; - longDescription = '' - The compiler-rt project provides highly tuned implementations of the - low-level code generator support routines like "__fixunsdfdi" and other - calls generated when a target doesn't have a short sequence of native - instructions to implement a core IR operation. It also provides - implementations of run-time libraries for dynamic testing tools such as - AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. - ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - # compiler-rt requires a Clang stdenv on 32-bit RISC-V: - # https://reviews.llvm.org/D43106#1019077 - broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; - }; -} diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix index 46d17c193fc92..9a4f43843392b 100644 --- a/pkgs/development/compilers/llvm/16/default.nix +++ b/pkgs/development/compilers/llvm/16/default.nix @@ -296,14 +296,40 @@ in let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt diff --git a/pkgs/development/compilers/llvm/17/compiler-rt/default.nix b/pkgs/development/compilers/llvm/17/compiler-rt/default.nix deleted file mode 100644 index 2a15e5302b463..0000000000000 --- a/pkgs/development/compilers/llvm/17/compiler-rt/default.nix +++ /dev/null @@ -1,159 +0,0 @@ -{ lib, stdenv, llvm_meta, version -, monorepoSrc, runCommand -, cmake, ninja, python3, xcbuild, libllvm, linuxHeaders, libxcrypt -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD -}: - -let - - useLLVM = stdenv.hostPlatform.useLLVM or false; - bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; - haveLibc = stdenv.cc.libc != null; - isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; - inherit (stdenv.hostPlatform) isMusl; - - baseName = "compiler-rt"; - - src = runCommand "${baseName}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${baseName} "$out" - ''; -in - -stdenv.mkDerivation { - pname = baseName + lib.optionalString (haveLibc) "-libc"; - inherit version; - - inherit src; - sourceRoot = "${src.name}/${baseName}"; - - nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; - - 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 <assert.h> 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" - ]); - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [ - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM && !haveLibc) [ - "-DCMAKE_C_FLAGS=-nodefaultlibs" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - - # `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" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - ./gnu-install-dirs.patch - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # Prevent a compilation error on darwin - ./darwin-targetconditionals.patch - # See: https://github.com/NixOS/nixpkgs/pull/186575 - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 - # ../../common/compiler-rt/armv7l-15.patch - ]; - - # 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.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM && !haveLibc) '' - substituteInPlace lib/builtins/int_util.c \ - --replace "#include <stdlib.h>" "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include <assert.h>" "" - substituteInPlace lib/builtins/cpu_model.c \ - --replace "#include <assert.h>" "" - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: - # The presence of crtbegin_shared has been added and removed; it's possible - # people have added/removed it to get it working on their platforms. - # Try each in turn for now. - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a - ''; - - meta = llvm_meta // { - homepage = "https://compiler-rt.llvm.org/"; - description = "Compiler runtime libraries"; - mainProgram = "hwasan_symbolize"; - longDescription = '' - The compiler-rt project provides highly tuned implementations of the - low-level code generator support routines like "__fixunsdfdi" and other - calls generated when a target doesn't have a short sequence of native - instructions to implement a core IR operation. It also provides - implementations of run-time libraries for dynamic testing tools such as - AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. - ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - # compiler-rt requires a Clang stdenv on 32-bit RISC-V: - # https://reviews.llvm.org/D43106#1019077 - broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; - }; -} diff --git a/pkgs/development/compilers/llvm/17/default.nix b/pkgs/development/compilers/llvm/17/default.nix index fb3e967cc39b8..5724a55664bcf 100644 --- a/pkgs/development/compilers/llvm/17/default.nix +++ b/pkgs/development/compilers/llvm/17/default.nix @@ -281,14 +281,40 @@ in let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./compiler-rt/gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # Prevent a compilation error on darwin + ./compiler-rt/darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt diff --git a/pkgs/development/compilers/llvm/18/compiler-rt/default.nix b/pkgs/development/compilers/llvm/18/compiler-rt/default.nix deleted file mode 100644 index f51316beb5705..0000000000000 --- a/pkgs/development/compilers/llvm/18/compiler-rt/default.nix +++ /dev/null @@ -1,157 +0,0 @@ -{ lib, stdenv, llvm_meta, version -, monorepoSrc, runCommand -, cmake, ninja, python3, xcbuild, libllvm, linuxHeaders, libxcrypt -, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD -}: - -let - - useLLVM = stdenv.hostPlatform.useLLVM or false; - bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; - haveLibc = stdenv.cc.libc != null; - isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; - inherit (stdenv.hostPlatform) isMusl; - - baseName = "compiler-rt"; - - src = runCommand "${baseName}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${baseName} "$out" - ''; -in - -stdenv.mkDerivation { - pname = baseName + lib.optionalString (haveLibc) "-libc"; - inherit version; - - inherit src; - sourceRoot = "${src.name}/${baseName}"; - - nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; - - 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 <assert.h> 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" - ]); - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [ - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM && !haveLibc) [ - "-DCMAKE_C_FLAGS=-nodefaultlibs" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - - # `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" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # See: https://github.com/NixOS/nixpkgs/pull/186575 - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 - # ../../common/compiler-rt/armv7l-15.patch - ]; - - # 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.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM && !haveLibc) '' - substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ - --replace "<stdlib.h>" "<stddef.h>" - substituteInPlace lib/builtins/int_util.c \ - --replace "#include <stdlib.h>" "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include <assert.h>" "" - substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast version "18") "/x86"}.c \ - --replace "#include <assert.h>" "" - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: - # The presence of crtbegin_shared has been added and removed; it's possible - # people have added/removed it to get it working on their platforms. - # Try each in turn for now. - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' - ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a - ''; - - meta = llvm_meta // { - homepage = "https://compiler-rt.llvm.org/"; - description = "Compiler runtime libraries"; - longDescription = '' - The compiler-rt project provides highly tuned implementations of the - low-level code generator support routines like "__fixunsdfdi" and other - calls generated when a target doesn't have a short sequence of native - instructions to implement a core IR operation. It also provides - implementations of run-time libraries for dynamic testing tools such as - AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. - ''; - # "All of the code in the compiler-rt project is dual licensed under the MIT - # license and the UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - # compiler-rt requires a Clang stdenv on 32-bit RISC-V: - # https://reviews.llvm.org/D43106#1019077 - broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; - }; -} diff --git a/pkgs/development/compilers/llvm/18/default.nix b/pkgs/development/compilers/llvm/18/default.nix index 5f7f67438f0f3..a5d5299d11341 100644 --- a/pkgs/development/compilers/llvm/18/default.nix +++ b/pkgs/development/compilers/llvm/18/default.nix @@ -281,14 +281,34 @@ in let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt diff --git a/pkgs/development/compilers/llvm/git/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix index 606ae2868893d..4f44d6396d301 100644 --- a/pkgs/development/compilers/llvm/git/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix @@ -1,6 +1,19 @@ -{ lib, stdenv, llvm_meta, version -, monorepoSrc, runCommand -, cmake, ninja, python3, xcbuild, libllvm, linuxHeaders, libxcrypt +{ lib +, stdenv +, llvm_meta +, release_version +, version +, patches ? [] +, src ? null +, monorepoSrc ? null +, runCommand +, cmake +, ninja +, python3 +, xcbuild +, libllvm +, linuxHeaders +, libxcrypt , doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD }: @@ -9,26 +22,34 @@ let useLLVM = stdenv.hostPlatform.useLLVM or false; bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; haveLibc = stdenv.cc.libc != null; - isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; - inherit (stdenv.hostPlatform) isMusl; + isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic && lib.versionAtLeast release_version "16"; + inherit (stdenv.hostPlatform) isMusl isAarch64; baseName = "compiler-rt"; + pname = baseName + lib.optionalString (haveLibc) "-libc"; + + src' = if monorepoSrc != null then + runCommand "${baseName}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${baseName} "$out" + '' else src; - src = runCommand "${baseName}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${baseName} "$out" + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") ''; in -stdenv.mkDerivation { - pname = baseName + lib.optionalString (haveLibc) "-libc"; - inherit version; +stdenv.mkDerivation ({ + inherit pname version patches; - inherit src; - sourceRoot = "${src.name}/${baseName}"; + src = src'; + sourceRoot = if lib.versionOlder release_version "13" then null + else "${src'.name}/${baseName}"; - nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] + nativeBuildInputs = [ cmake ] + ++ (lib.optional (lib.versionAtLeast release_version "15") ninja) + ++ [ python3 libllvm.dev ] ++ lib.optional stdenv.isDarwin xcbuild.xcrun; buildInputs = lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; @@ -50,6 +71,8 @@ stdenv.mkDerivation { "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals ((useLLVM || bareMetal || isMusl || isAarch64) && (lib.versions.major release_version == "13")) [ + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" "-DCOMPILER_RT_BUILD_XRAY=OFF" @@ -58,7 +81,7 @@ stdenv.mkDerivation { "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary ] ++ lib.optionals (useLLVM || bareMetal) [ "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [ + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic) [ "-DCMAKE_CXX_COMPILER_WORKS=ON" ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ "-DCMAKE_C_COMPILER_WORKS=ON" @@ -72,32 +95,22 @@ stdenv.mkDerivation { "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ] ++ lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) (lib.optionals (lib.versionAtLeast release_version "16") [ "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" + ] ++ [ "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - + ] ++ 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.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ + ]) ++ lib.optionals (lib.versionAtLeast version "19" && stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ "-DSANITIZER_MIN_OSX_VERSION=10.10" ]; outputs = [ "out" "dev" ]; - patches = [ - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # See: https://github.com/NixOS/nixpkgs/pull/186575 - ../../common/compiler-rt/darwin-plistbuddy-workaround.patch - # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 - # ../../common/compiler-rt/armv7l-15.patch - ]; - # 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 @@ -109,16 +122,17 @@ stdenv.mkDerivation { '' + lib.optionalString stdenv.isDarwin '' substituteInPlace cmake/config-ix.cmake \ --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM && !haveLibc) '' + '' + lib.optionalString (useLLVM && !haveLibc) ((lib.optionalString (lib.versionAtLeast release_version "18") '' substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ --replace "<stdlib.h>" "<stddef.h>" + '') + '' substituteInPlace lib/builtins/int_util.c \ --replace "#include <stdlib.h>" "" substituteInPlace lib/builtins/clear_cache.c \ --replace "#include <assert.h>" "" substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast version "18") "/x86"}.c \ --replace "#include <assert.h>" "" - ''; + ''); # Hack around weird upsream RPATH bug postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' @@ -156,4 +170,4 @@ stdenv.mkDerivation { # https://reviews.llvm.org/D43106#1019077 broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; }; -} +} // (if lib.versionOlder release_version "16" then { inherit preConfigure; } else {})) diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index 06da0b3b6a3c6..e7871dc21863a 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -286,14 +286,34 @@ in let callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); in { - compiler-rt-libc = callPackage ./compiler-rt { + compiler-rt-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; - compiler-rt-no-libc = callPackage ./compiler-rt { + compiler-rt-no-libc = callPackage ../common/compiler-rt { + patches = [ + ./compiler-rt/X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./compiler-rt/normalize-var.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../common/compiler-rt/armv7l-15.patch + ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false then overrideCC stdenv buildLlvmTools.clangNoCompilerRt |