git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #39743 from Ralith/compiler-rt

llvm: factor out compiler-rt, fix libstdcxxStdenv sanitizer headers

commit11d26c797fb4010f5cae07848902e7fad8a9d3a9 authorJohn Ericson <Ericson2314@yahoo.com> dateThu 24 May 2018, 10:18 (9 years ago) parent33b8830205fc55
7 files changed+69−29
pkgs/build-support/cc-wrapper/default.nix+2−2 pkgs/development/compilers/llvm/6/clang/default.nix+2−7 pkgs/development/compilers/llvm/6/compiler-rt.nix+31 pkgs/development/compilers/llvm/6/default.nix+21−4 pkgs/development/compilers/llvm/6/llvm.nix−16 pkgs/test/cc-wrapper/default.nix+5 pkgs/test/cc-wrapper/sanitizers.c+8
pkgs/build-support/cc-wrapper/default.nix+2−2
@@ -9,7 +9,7 @@
99, stdenvNoCC, nativeTools, propagateDoc ? !nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
1010, cc ? null, libc ? null, bintools, coreutils ? null, shell ? stdenvNoCC.shell
1111, extraPackages ? [], extraBuildCommands ? ""
12−, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
12+, isGNU ? false, isClang ? cc.isClang or false, isCompilerRT ? false, gnugrep ? null
1313, buildPackages ? {}
1414}:
1515
@@ -90,7 +90,7 @@ stdenv.mkDerivation {
9090 # Binutils, and Apple's "cctools"; "bintools" as an attempt to find an
9191 # unused middle-ground name that evokes both.
9292 inherit bintools;
93− inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile;
93+ inherit libc nativeTools nativeLibc nativePrefix isGNU isClang isCompilerRT default_cxx_stdlib_compile;
9494
9595 emacsBufferSetup = pkgs: ''
9696 ; We should handle propagation here too
pkgs/development/compilers/llvm/6/clang/default.nix+2−7
@@ -30,10 +30,7 @@ let
3030 "-DSPHINX_OUTPUT_MAN=ON"
3131 "-DSPHINX_OUTPUT_HTML=OFF"
3232 "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
33− ]
34− # Maybe with compiler-rt this won't be needed?
35− ++ stdenv.lib.optional stdenv.isLinux "-DGCC_INSTALL_PREFIX=${gcc}"
36− ++ stdenv.lib.optional (stdenv.cc.libc != null) "-DC_INCLUDE_DIRS=${stdenv.cc.libc}/include";
33+ ];
3734
3835 patches = [ ./purity.patch ];
3936
@@ -51,13 +48,11 @@ let
5148 outputs = [ "out" "lib" "python" ];
5249
5350 # Clang expects to find LLVMgold in its own prefix
54− # Clang expects to find sanitizer libraries in its own prefix
5551 postInstall = ''
5652 if [ -e ${llvm}/lib/LLVMgold.so ]; then
5753 ln -sv ${llvm}/lib/LLVMgold.so $out/lib
5854 fi
5955
60− ln -sv ${llvm}/lib/clang/${release_version}/lib $out/lib/clang/${release_version}/
6156 ln -sv $out/bin/clang $out/bin/cpp
6257
6358 # Move libclang to 'lib' output
@@ -79,7 +74,7 @@ let
7974 passthru = {
8075 isClang = true;
8176 inherit llvm;
82− } // stdenv.lib.optionalAttrs stdenv.isLinux {
77+ } // stdenv.lib.optionalAttrs stdenv.targetPlatform.isLinux {
8378 inherit gcc;
8479 };
8580
pkgs/development/compilers/llvm/6/compiler-rt.nixnew file+31
@@ -0,0 +1,31 @@
1+{ stdenv, version, fetch, cmake, python, llvm }:
2+with stdenv.lib;
3+stdenv.mkDerivation rec {
4+ name = "compiler-rt-${version}";
5+ inherit version;
6+ src = fetch "compiler-rt" "16m7rvh3w6vq10iwkjrr1nn293djld3xm62l5zasisaprx117k6h";
7+
8+ nativeBuildInputs = [ cmake python llvm ];
9+
10+ configureFlags = [
11+ "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
12+ ];
13+
14+ outputs = [ "dev" "out" ];
15+
16+ patches = [
17+ ./compiler-rt-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
18+ ] ++ optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch;
19+
20+ # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
21+ # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
22+ # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
23+ # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
24+ # a flag and turn the flag off during the stdenv build.
25+ postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
26+ substituteInPlace cmake/config-ix.cmake \
27+ --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
28+ '';
29+
30+ enableParallelBuilding = true;
31+}
pkgs/development/compilers/llvm/6/default.nix+21−4
@@ -14,7 +14,6 @@ let
1414 inherit sha256;
1515 };
1616
17− compiler-rt_src = fetch "compiler-rt" "16m7rvh3w6vq10iwkjrr1nn293djld3xm62l5zasisaprx117k6h";
1817 clang-tools-extra_src = fetch "clang-tools-extra" "1ll9v6r29xfdiywbn9iss49ad39ah3fk91wiv0sr6k6k9i544fq5";
1918
2019 # Add man output without introducing extra dependencies.
@@ -27,7 +26,6 @@ let
2726 in {
2827
2928 llvm = overrideManOutput (callPackage ./llvm.nix {
30− inherit compiler-rt_src;
3129 inherit (targetLlvmLibraries) libcxxabi;
3230 });
3331 clang-unwrapped = overrideManOutput (callPackage ./clang {
@@ -43,11 +41,28 @@ let
4341 libstdcxxClang = wrapCCWith {
4442 cc = tools.clang-unwrapped;
4543 extraPackages = [ libstdcxxHook ];
44+ extraBuildCommands = stdenv.lib.optionalString stdenv.targetPlatform.isLinux ''
45+ echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
46+ '';
4647 };
4748
48− libcxxClang = wrapCCWith {
49+ libcxxClang = wrapCCWith rec {
4950 cc = tools.clang-unwrapped;
50− extraPackages = [ targetLlvmLibraries.libcxx targetLlvmLibraries.libcxxabi ];
51+ extraPackages = [
52+ targetLlvmLibraries.libcxx
53+ targetLlvmLibraries.libcxxabi
54+ targetLlvmLibraries.compiler-rt
55+ ];
56+ isCompilerRT = true;
57+ extraBuildCommands = ''
58+ rsrc="$out/resource-root"
59+ mkdir "$rsrc"
60+ ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
61+ ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
62+ echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
63+ '' + stdenv.lib.optionalString stdenv.targetPlatform.isLinux ''
64+ echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
65+ '';
5166 };
5267
5368 lld = callPackage ./lld.nix {};
@@ -59,6 +74,8 @@ let
5974 callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python2 isl release_version version fetch; });
6075 in {
6176
77+ compiler-rt = callPackage ./compiler-rt.nix {};
78+
6279 stdenv = overrideCC stdenv buildLlvmTools.clang;
6380
6481 libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
pkgs/development/compilers/llvm/6/llvm.nix−16
@@ -11,7 +11,6 @@
1111, version
1212, release_version
1313, zlib
14−, compiler-rt_src
1514, libcxxabi
1615, debugVersion ? false
1716, enableManpages ? false
@@ -33,8 +32,6 @@ in stdenv.mkDerivation (rec {
3332 unpackFile ${src}
3433 mv llvm-${version}* llvm
3534 sourceRoot=$PWD/llvm
36− unpackFile ${compiler-rt_src}
37− mv compiler-rt-* $sourceRoot/projects/compiler-rt
3835 '';
3936
4037 outputs = [ "out" "python" ]
@@ -48,15 +45,7 @@ in stdenv.mkDerivation (rec {
4845
4946 propagatedBuildInputs = [ ncurses zlib ];
5047
51− # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
52− # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
53− # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
54− # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
55− # a flag and turn the flag off during the stdenv build.
5648 postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
57− substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
58− --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
59−
6049 substituteInPlace cmake/modules/AddLLVM.cmake \
6150 --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
6251 --replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
@@ -70,15 +59,11 @@ in stdenv.mkDerivation (rec {
7059 substituteInPlace unittests/Support/CMakeLists.txt \
7160 --replace "Path.cpp" ""
7261 rm unittests/Support/Path.cpp
73−
74− # Revert compiler-rt commit that makes codesign mandatory
75− patch -p1 -i ${./compiler-rt-codesign.patch} -d projects/compiler-rt
7662 '' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
7763 patch -p1 -i ${../TLI-musl.patch}
7864 substituteInPlace unittests/Support/CMakeLists.txt \
7965 --replace "add_subdirectory(DynamicLibrary)" ""
8066 rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
81− patch -p1 -i ${./sanitizers-nongnu.patch} -d projects/compiler-rt
8267 '';
8368
8469 # hacky fix: created binaries need to be run before installation
@@ -93,7 +78,6 @@ in stdenv.mkDerivation (rec {
9378 "-DLLVM_BUILD_TESTS=ON"
9479 "-DLLVM_ENABLE_FFI=ON"
9580 "-DLLVM_ENABLE_RTTI=ON"
96− "-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code
9781 ]
9882 ++ stdenv.lib.optional enableSharedLibraries
9983 "-DLLVM_LINK_LLVM_DYLIB=ON"
pkgs/test/cc-wrapper/default.nix+5
@@ -38,6 +38,11 @@ stdenv.mkDerivation {
3838
3939 NIX_LDFLAGS="-L$NIX_BUILD_TOP/foo/lib -rpath $NIX_BUILD_TOP/foo/lib" $CC -lfoo -o ldflags-check ${./ldflags-main.c}
4040 ./ldflags-check
41+ '' + stdenv.lib.optionalString (stdenv.cc.isCompilerRT or false) ''
42+
43+ $CC -o sanitizers -fsanitize=address,undefined ${./sanitizers.c}
44+ ./sanitizers
45+ '' + ''
4146
4247 touch $out
4348 '';
pkgs/test/cc-wrapper/sanitizers.cnew file+8
@@ -0,0 +1,8 @@
1+#include <sanitizer/asan_interface.h>
2+#include <stdio.h>
3+
4+int main(int argc, char **argv)
5+{
6+ fprintf(stderr, "ok\n");
7+ return 0;
8+}