From e4459e59a2d29c63ec8cb669b47bdfe4ece59b36 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Wed, 1 Sep 2021 12:47:49 -0700 Subject: [PATCH] llvmPackages_rocm: add compiler-rt Co-Authored-By: acowley --- .../compiler-rt/compiler-rt-codesign.patch | 33 +++++++++++ .../llvm/rocm/compiler-rt/default.nix | 57 +++++++++++++++++++ .../compilers/llvm/rocm/default.nix | 25 +++++++- .../llvm/rocm/{lld/default.nix => lld.nix} | 0 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/compilers/llvm/rocm/compiler-rt/compiler-rt-codesign.patch create mode 100644 pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix rename pkgs/development/compilers/llvm/rocm/{lld/default.nix => lld.nix} (100%) diff --git a/pkgs/development/compilers/llvm/rocm/compiler-rt/compiler-rt-codesign.patch b/pkgs/development/compilers/llvm/rocm/compiler-rt/compiler-rt-codesign.patch new file mode 100644 index 000000000000..3cc12b94b200 --- /dev/null +++ b/pkgs/development/compilers/llvm/rocm/compiler-rt/compiler-rt-codesign.patch @@ -0,0 +1,33 @@ +From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Tue, 19 Sep 2017 13:13:06 -0500 +Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that + needs it + +--- + cmake/Modules/AddCompilerRT.cmake | 8 ------ + test/asan/CMakeLists.txt | 52 --------------------------------------- + test/tsan/CMakeLists.txt | 47 ----------------------------------- + 3 files changed, 107 deletions(-) + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index bc5fb9ff7..b64eb4246 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() +- if(APPLE) +- # Ad-hoc sign the dylibs +- add_custom_command(TARGET ${libname} +- POST_BUILD +- COMMAND codesign --sign - $ +- WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} +- ) +- endif() + endif() + install(TARGETS ${libname} + ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} +2.14.1 + diff --git a/pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix b/pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix new file mode 100644 index 000000000000..126ceb6aaa72 --- /dev/null +++ b/pkgs/development/compilers/llvm/rocm/compiler-rt/default.nix @@ -0,0 +1,57 @@ +{ stdenv, lib, version, src, cmake, python3, llvm, libcxxabi }: +stdenv.mkDerivation rec { + pname = "compiler-rt"; + inherit version src; + + nativeBuildInputs = [ cmake python3 llvm ]; + + NIX_CFLAGS_COMPILE = [ + "-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}" + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + "-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)}" + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + "-DCMAKE_C_FLAGS=-nodefaultlibs" + #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" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ./compiler-rt-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ]; + + + # 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)' + ''; + + # Hack around weird upsream RPATH bug + postInstall = '' + ln -s "$out/lib"/*/* "$out/lib" + 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 + ''; + + enableParallelBuilding = true; +} diff --git a/pkgs/development/compilers/llvm/rocm/default.nix b/pkgs/development/compilers/llvm/rocm/default.nix index 581d05746718..980dd0d395da 100644 --- a/pkgs/development/compilers/llvm/rocm/default.nix +++ b/pkgs/development/compilers/llvm/rocm/default.nix @@ -1,4 +1,4 @@ -{ lib, buildPackages, fetchFromGitHub, callPackage, wrapCCWith }: +{ stdenv, lib, buildPackages, fetchFromGitHub, callPackage, wrapCCWith, overrideCC }: let version = "4.1.0"; @@ -23,12 +23,33 @@ in rec { ''; }; + clangNoCompilerRt = wrapCCWith rec { + cc = clang-unwrapped; + extraBuildCommands = '' + clang_version=`${cc}/bin/clang -v 2>&1 | grep "clang version " | grep -E -o "[0-9.-]+"` + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc}/lib/clang/$clang_version/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + echo "--gcc-toolchain=${stdenv.cc.cc}" >> $out/nix-support/cc-cflags + echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + rm $out/nix-support/add-hardening.sh + touch $out/nix-support/add-hardening.sh + ''; + }; + clang-unwrapped = callPackage ./clang.nix { inherit lld llvm version; src = "${src}/clang"; }; - lld = callPackage ./lld { + compiler-rt = callPackage ./compiler-rt { + inherit version llvm; + src = "${src}/compiler-rt"; + stdenv = overrideCC stdenv clangNoCompilerRt; + }; + + lld = callPackage ./lld.nix { inherit llvm version; src = "${src}/lld"; buildLlvmTools = buildPackages.llvmPackages_rocm; diff --git a/pkgs/development/compilers/llvm/rocm/lld/default.nix b/pkgs/development/compilers/llvm/rocm/lld.nix similarity index 100% rename from pkgs/development/compilers/llvm/rocm/lld/default.nix rename to pkgs/development/compilers/llvm/rocm/lld.nix