Skip to content

Commit

Permalink
Merge pull request #119326 from primeos/llvm-backport
Browse files Browse the repository at this point in the history
[20.09] Backport llvmPackages_12
  • Loading branch information
primeos committed Apr 13, 2021
2 parents 9106cc1 + 45f771a commit 09bd15f
Show file tree
Hide file tree
Showing 20 changed files with 1,539 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkgs/development/compilers/llvm/12/bintools.nix
@@ -0,0 +1,29 @@
{ runCommand, stdenv, llvm, lld, version }:

let
prefix =
if stdenv.hostPlatform != stdenv.targetPlatform
then "${stdenv.targetPlatform.config}-"
else "";
in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } ''
mkdir -p $out/bin
for prog in ${lld}/bin/*; do
ln -s $prog $out/bin/${prefix}$(basename $prog)
done
for prog in ${llvm}/bin/*; do
ln -sf $prog $out/bin/${prefix}$(basename $prog)
done
ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
ln -s ${llvm}/bin/llvm-as $out/bin/${prefix}as
ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
ln -s ${llvm}/bin/llvm-ranlib $out/bin/${prefix}ranlib
ln -s ${llvm}/bin/llvm-readelf $out/bin/${prefix}readelf
ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
ln -s ${llvm}/bin/llvm-strip $out/bin/${prefix}strip
ln -s ${lld}/bin/lld $out/bin/${prefix}ld
''
110 changes: 110 additions & 0 deletions pkgs/development/compilers/llvm/12/clang/default.nix
@@ -0,0 +1,110 @@
{ lib, stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3, lld
, fixDarwinDylibNames
, enableManpages ? false
}:

let
self = stdenv.mkDerivation ({
pname = "clang";
inherit version;

src = fetch "clang" "185r9rr254v75ja33nmm53j85lcnkj7bzsl18wvnd37jmz2nfxa5";
inherit clang-tools-extra_src;

unpackPhase = ''
unpackFile $src
mv clang-* clang
sourceRoot=$PWD/clang
unpackFile ${clang-tools-extra_src}
'';

nativeBuildInputs = [ cmake python3 lld ]
++ lib.optional enableManpages python3.pkgs.sphinx
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;

buildInputs = [ libxml2 llvm ];

cmakeFlags = [
"-DCMAKE_CXX_FLAGS=-std=c++14"
"-DCLANGD_BUILD_XPC=OFF"
] ++ lib.optionals enableManpages [
"-DCLANG_INCLUDE_DOCS=ON"
"-DLLVM_ENABLE_SPHINX=ON"
"-DSPHINX_OUTPUT_MAN=ON"
"-DSPHINX_OUTPUT_HTML=OFF"
"-DSPHINX_WARNINGS_AS_ERRORS=OFF"
];

patches = [
./purity.patch
# https://reviews.llvm.org/D51899
];

postPatch = ''
sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \
-e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \
lib/Driver/ToolChains/*.cpp
# Patch for standalone doc building
sed -i '1s,^,find_package(Sphinx REQUIRED)\n,' docs/CMakeLists.txt
'' + lib.optionalString stdenv.hostPlatform.isMusl ''
sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp
'';

outputs = [ "out" "lib" "python" ];

# Clang expects to find LLVMgold in its own prefix
postInstall = ''
if [ -e ${llvm}/lib/LLVMgold.so ]; then
ln -sv ${llvm}/lib/LLVMgold.so $out/lib
fi
ln -sv $out/bin/clang $out/bin/cpp
# Move libclang to 'lib' output
moveToOutput "lib/libclang.*" "$lib"
moveToOutput "lib/libclang-cpp.*" "$lib"
substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \
--replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \
--replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp."
mkdir -p $python/bin $python/share/clang/
mv $out/bin/{git-clang-format,scan-view} $python/bin
if [ -e $out/bin/set-xcode-analyzer ]; then
mv $out/bin/set-xcode-analyzer $python/bin
fi
mv $out/share/clang/*.py $python/share/clang
rm $out/bin/c-index-test
'';

passthru = {
isClang = true;
inherit llvm;
};

meta = {
description = "A c, c++, objective-c, and objective-c++ frontend for the llvm compiler";
homepage = "https://llvm.org/";
license = lib.licenses.ncsa;
platforms = lib.platforms.all;
};
} // lib.optionalAttrs enableManpages {
pname = "clang-manpages";

buildPhase = ''
make docs-clang-man
'';

installPhase = ''
mkdir -p $out/share/man/man1
# Manually install clang manpage
cp docs/man/*.1 $out/share/man/man1/
'';

outputs = [ "out" ];

doCheck = false;

meta.description = "man page for Clang ${version}";
});
in self
28 changes: 28 additions & 0 deletions pkgs/development/compilers/llvm/12/clang/purity.patch
@@ -0,0 +1,28 @@
From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001
From: Will Dietz <w@wdtz.org>
Date: Thu, 18 May 2017 11:56:12 -0500
Subject: [PATCH] "purity" patch for 5.0

---
lib/Driver/ToolChains/Gnu.cpp | 7 -------
1 file changed, 7 deletions(-)

diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
index fe3c0191bb..c6a482bece 100644
--- a/lib/Driver/ToolChains/Gnu.cpp
+++ b/lib/Driver/ToolChains/Gnu.cpp
@@ -487,12 +487,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!IsStatic) {
if (Args.hasArg(options::OPT_rdynamic))
CmdArgs.push_back("-export-dynamic");
-
- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) {
- CmdArgs.push_back("-dynamic-linker");
- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) +
- ToolChain.getDynamicLinker(Args)));
- }
}

CmdArgs.push_back("-o");
--
2.11.0
@@ -0,0 +1,23 @@
diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt
index 3a66dd9c3fb..7efc85d9f9f 100644
--- a/lib/builtins/CMakeLists.txt
+++ b/lib/builtins/CMakeLists.txt
@@ -301,6 +301,10 @@ if (NOT MSVC)
i386/umoddi3.S
)

+ set(i486_SOURCES ${i386_SOURCES})
+ set(i586_SOURCES ${i386_SOURCES})
+ set(i686_SOURCES ${i386_SOURCES})
+
if (WIN32)
set(i386_SOURCES
${i386_SOURCES}
@@ -608,6 +612,7 @@ else ()
endif()

foreach (arch ${BUILTIN_SUPPORTED_ARCH})
+ message("arch: ${arch}")
if (CAN_TARGET_${arch})
# For ARM archs, exclude any VFP builtins if VFP is not supported
if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$")
32 changes: 32 additions & 0 deletions pkgs/development/compilers/llvm/12/compiler-rt-armv7l.patch
@@ -0,0 +1,32 @@
diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake
--- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900
+++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900
@@ -24,7 +24,7 @@


set(ARM64 aarch64)
-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k)
+set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l)
set(HEXAGON hexagon)
set(X86 i386)
set(X86_64 x86_64)
diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt
--- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900
+++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900
@@ -474,6 +474,7 @@
set(armv7_SOURCES ${arm_SOURCES})
set(armv7s_SOURCES ${arm_SOURCES})
set(armv7k_SOURCES ${arm_SOURCES})
+set(armv7l_SOURCES ${arm_SOURCES})
set(arm64_SOURCES ${aarch64_SOURCES})

# macho_embedded archs
@@ -595,7 +596,7 @@
foreach (arch ${BUILTIN_SUPPORTED_ARCH})
if (CAN_TARGET_${arch})
# For ARM archs, exclude any VFP builtins if VFP is not supported
- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$")
+ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$")
string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}")
check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP)
if(NOT COMPILER_RT_HAS_${arch}_VFP)
33 changes: 33 additions & 0 deletions pkgs/development/compilers/llvm/12/compiler-rt-codesign.patch
@@ -0,0 +1,33 @@
From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001
From: Will Dietz <w@wdtz.org>
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 - $<TARGET_FILE:${libname}>
- WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
- )
- endif()
endif()
install(TARGETS ${libname}
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
2.14.1

90 changes: 90 additions & 0 deletions pkgs/development/compilers/llvm/12/compiler-rt.nix
@@ -0,0 +1,90 @@
{ lib, stdenv, version, fetch, cmake, python3, llvm, libcxxabi }:

let

useLLVM = stdenv.hostPlatform.useLLVM or false;
bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none";
inherit (stdenv.hostPlatform) isMusl;

in

stdenv.mkDerivation rec {
pname = "compiler-rt";
inherit version;
src = fetch pname "1x0z875nbdpzhr4qb7linm6r9swvdf6dvwqy1s22pbn4wdcw0cvf";

nativeBuildInputs = [ cmake python3 llvm ];
buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;

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}"
] ++ lib.optionals (stdenv.isDarwin) [
"-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON"
"-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.parsed.cpu.name}"
] ++ lib.optionals (useLLVM || bareMetal || isMusl) [
"-DCOMPILER_RT_BUILD_SANITIZERS=OFF"
"-DCOMPILER_RT_BUILD_XRAY=OFF"
"-DCOMPILER_RT_BUILD_LIBFUZZER=OFF"
"-DCOMPILER_RT_BUILD_PROFILE=OFF"
] ++ lib.optionals (useLLVM || 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"
"-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"
] ++ lib.optionals (bareMetal) [
"-DCOMPILER_RT_OS_DIR=baremetal"
];

outputs = [ "out" "dev" ];

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
]# ++ lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch
++ lib.optional stdenv.hostPlatform.isAarch32 ./compiler-rt-armv7l.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/builtin-config-ix.cmake \
--replace 'set(ARM64 arm64 arm64e)' 'set(ARM64)'
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>" ""
'';

# 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
'';

}

0 comments on commit 09bd15f

Please sign in to comment.