git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #59338 from matthewbauer/llvm-libc++

llvm8: support c++ in cross case

commit7edf2db0fddc64e53e06c95fc0f1efcfe3f714f9 authorMatthew Bauer <mjbauer95@gmail.com> dateFri 12 Apr 2019, 14:09 (8 years ago) parent6ebcac76794b01
12 files changed+633−25
pkgs/build-support/cc-wrapper/default.nix+2−2 pkgs/development/compilers/llvm/8/clang/default.nix+7−1 pkgs/development/compilers/llvm/8/clang/static-pie.patch+157 pkgs/development/compilers/llvm/8/clang/unwindlib.patch+372 pkgs/development/compilers/llvm/8/compiler-rt.nix+2−2 pkgs/development/compilers/llvm/8/default.nix+59−15 pkgs/development/compilers/llvm/8/libc++/default.nix+2−1 pkgs/development/compilers/llvm/8/libc++abi.nix+6−1 pkgs/development/compilers/llvm/8/libunwind.nix+22 pkgs/development/libraries/kerberos/krb5.nix+2−1 pkgs/stdenv/cross/default.nix+1−1 pkgs/top-level/all-packages.nix+1−1
pkgs/build-support/cc-wrapper/default.nix+2−2
@@ -45,9 +45,9 @@ let
4545 # The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
4646 coreutils_bin = if nativeTools then "" else getBin coreutils;
4747
48− default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) then
48+ default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) && !(targetPlatform.useLLVM or false) then
4949 "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)"
50− else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) then
50+ else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) && !(targetPlatform.useLLVM or false) then
5151 "-isystem ${libcxx}/include/c++/v1"
5252 else "";
5353
pkgs/development/compilers/llvm/8/clang/default.nix+7−1
@@ -1,4 +1,4 @@
1−{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python
1+{ stdenv, fetch, fetchpatch, cmake, libxml2, llvm, version, clang-tools-extra_src, python
22, fixDarwinDylibNames
33, enableManpages ? false
44, enablePolly ? false # TODO: get this info from llvm (passthru?)
@@ -39,6 +39,12 @@ let
3939 patches = [
4040 ./purity.patch
4141 ./clang-xpc.patch
42+ # Backport for -static-pie, which the latter touches, and which is nice in
43+ # its own right.
44+ ./static-pie.patch
45+ # Backport for the `--unwindlib=[libgcc|complier-rt]` flag, which is
46+ # needed for our bootstrapping to not interfere with C.
47+ ./unwindlib.patch
4248 ];
4349
4450 postPatch = ''
pkgs/development/compilers/llvm/8/clang/static-pie.patchnew file+157
@@ -0,0 +1,157 @@
1+commit 7a9842bc92921e79b84630045276861be90b2d47
2+Author: Siva Chandra <sivachandra@google.com>
3+Date: Wed Feb 20 19:07:04 2019 +0000
4+
5+ [Clang Driver] Add support for "-static-pie" argument to the Clang driver.
6+
7+ Summary: This change mimics GCC's support for the "-static-pie" argument.
8+
9+ Subscribers: cfe-commits
10+
11+ Tags: #clang
12+
13+ Differential Revision: https://reviews.llvm.org/D58307
14+
15+ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354502 91177308-0d34-0410-b5e6-96231b3b80d8
16+ (cherry picked from commit 7d6cd7825e6883f8650e32b07f3750824c2cef62)
17+
18+diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
19+index d02d9744d7..75a21e66c7 100644
20+--- a/include/clang/Driver/Options.td
21++++ b/include/clang/Driver/Options.td
22+@@ -2502,6 +2502,7 @@ def pthread : Flag<["-"], "pthread">, Flags<[CC1Option]>,
23+ def no_pthread : Flag<["-"], "no-pthread">, Flags<[CC1Option]>;
24+ def p : Flag<["-"], "p">;
25+ def pie : Flag<["-"], "pie">;
26++def static_pie : Flag<["-"], "static-pie">;
27+ def read__only__relocs : Separate<["-"], "read_only_relocs">;
28+ def remap : Flag<["-"], "remap">;
29+ def rewrite_objc : Flag<["-"], "rewrite-objc">, Flags<[DriverOption,CC1Option]>,
30+diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp
31+index d7e316befa..85ffc1618d 100644
32+--- a/lib/Driver/ToolChains/CommonArgs.cpp
33++++ b/lib/Driver/ToolChains/CommonArgs.cpp
34+@@ -1138,19 +1138,22 @@ static void AddLibgcc(const llvm::Triple &Triple, const Driver &D,
35+ bool isCygMing = Triple.isOSCygMing();
36+ bool IsIAMCU = Triple.isOSIAMCU();
37+ bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
38+- Args.hasArg(options::OPT_static);
39++ Args.hasArg(options::OPT_static) ||
40++ Args.hasArg(options::OPT_static_pie);
41+
42+ bool SharedLibgcc = Args.hasArg(options::OPT_shared_libgcc);
43+ bool UnspecifiedLibgcc = !StaticLibgcc && !SharedLibgcc;
44+
45+ // Gcc adds libgcc arguments in various ways:
46+ //
47+- // gcc <none>: -lgcc --as-needed -lgcc_s --no-as-needed
48+- // g++ <none>: -lgcc_s -lgcc
49+- // gcc shared: -lgcc_s -lgcc
50+- // g++ shared: -lgcc_s -lgcc
51+- // gcc static: -lgcc -lgcc_eh
52+- // g++ static: -lgcc -lgcc_eh
53++ // gcc <none>: -lgcc --as-needed -lgcc_s --no-as-needed
54++ // g++ <none>: -lgcc_s -lgcc
55++ // gcc shared: -lgcc_s -lgcc
56++ // g++ shared: -lgcc_s -lgcc
57++ // gcc static: -lgcc -lgcc_eh
58++ // g++ static: -lgcc -lgcc_eh
59++ // gcc static-pie: -lgcc -lgcc_eh
60++ // g++ static-pie: -lgcc -lgcc_eh
61+ //
62+ // Also, certain targets need additional adjustments.
63+
64+diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
65+index 69dba8fec8..0faa0bb473 100644
66+--- a/lib/Driver/ToolChains/Gnu.cpp
67++++ b/lib/Driver/ToolChains/Gnu.cpp
68+@@ -334,6 +334,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
69+ const bool isAndroid = ToolChain.getTriple().isAndroid();
70+ const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
71+ const bool IsPIE = getPIE(Args, ToolChain);
72++ const bool IsStaticPIE = Args.hasArg(options::OPT_static_pie);
73+ const bool HasCRTBeginEndFiles =
74+ ToolChain.getTriple().hasEnvironment() ||
75+ (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
76+@@ -354,6 +355,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
77+ if (IsPIE)
78+ CmdArgs.push_back("-pie");
79+
80++ if (IsStaticPIE) {
81++ CmdArgs.push_back("-static");
82++ CmdArgs.push_back("-pie");
83++ CmdArgs.push_back("--no-dynamic-linker");
84++ }
85++
86+ if (Args.hasArg(options::OPT_rdynamic))
87+ CmdArgs.push_back("-export-dynamic");
88+
89+@@ -415,6 +422,8 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
90+ crt1 = "gcrt1.o";
91+ else if (IsPIE)
92+ crt1 = "Scrt1.o";
93++ else if (IsStaticPIE)
94++ crt1 = "rcrt1.o";
95+ else
96+ crt1 = "crt1.o";
97+ }
98+@@ -432,7 +441,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
99+ crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o";
100+ else if (Args.hasArg(options::OPT_shared))
101+ crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o";
102+- else if (IsPIE)
103++ else if (IsPIE || IsStaticPIE)
104+ crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o";
105+ else
106+ crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o";
107+@@ -483,7 +492,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
108+
109+ if (!Args.hasArg(options::OPT_nostdlib)) {
110+ if (!Args.hasArg(options::OPT_nodefaultlibs)) {
111+- if (Args.hasArg(options::OPT_static))
112++ if (Args.hasArg(options::OPT_static) || IsStaticPIE)
113+ CmdArgs.push_back("--start-group");
114+
115+ if (NeedsSanitizerDeps)
116+@@ -518,7 +527,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
117+ if (IsIAMCU)
118+ CmdArgs.push_back("-lgloss");
119+
120+- if (Args.hasArg(options::OPT_static))
121++ if (Args.hasArg(options::OPT_static) || IsStaticPIE)
122+ CmdArgs.push_back("--end-group");
123+ else
124+ AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
125+@@ -535,7 +544,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
126+ const char *crtend;
127+ if (Args.hasArg(options::OPT_shared))
128+ crtend = isAndroid ? "crtend_so.o" : "crtendS.o";
129+- else if (IsPIE)
130++ else if (IsPIE || IsStaticPIE)
131+ crtend = isAndroid ? "crtend_android.o" : "crtendS.o";
132+ else
133+ crtend = isAndroid ? "crtend_android.o" : "crtend.o";
134+diff --git a/test/Driver/linux-ld.c b/test/Driver/linux-ld.c
135+index 3ab81be490..800f782523 100644
136+--- a/test/Driver/linux-ld.c
137++++ b/test/Driver/linux-ld.c
138+@@ -176,6 +176,19 @@
139+ // CHECK-CLANG-NO-LIBGCC-STATIC: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
140+ // CHECK-CLANG-NO-LIBGCC-STATIC: "--start-group" "-lgcc" "-lgcc_eh" "-lc" "--end-group"
141+ //
142++// RUN: %clang -static-pie -no-canonical-prefixes %s -### -o %t.o 2>&1 \
143++// RUN: --target=x86_64-unknown-linux -rtlib=platform \
144++// RUN: --gcc-toolchain="" \
145++// RUN: --sysroot=%S/Inputs/basic_linux_tree \
146++// RUN: | FileCheck --check-prefix=CHECK-CLANG-LD-STATIC-PIE %s
147++// CHECK-CLANG-LD-STATIC-PIE: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
148++// CHECK-CLANG-LD-STATIC-PIE: "-static"
149++// CHECK-CLANG-LD-STATIC-PIE: "-pie"
150++// CHECK-CLANG-LD-STATIC-PIE: "--no-dynamic-linker"
151++// CHECK-CLANG-LD-STATIC-PIE: "-m" "elf_x86_64"
152++// CHECK-CLANG-LD-STATIC-PIE: "{{.*}}rcrt1.o"
153++// CHECK-CLANG-LD-STATIC-PIE: "--start-group" "-lgcc" "-lgcc_eh" "-lc" "--end-group"
154++//
155+ // RUN: %clang -dynamic -no-canonical-prefixes %s -### -o %t.o 2>&1 \
156+ // RUN: --target=x86_64-unknown-linux -rtlib=platform \
157+ // RUN: --gcc-toolchain="" \
pkgs/development/compilers/llvm/8/clang/unwindlib.patchnew file+372
@@ -0,0 +1,372 @@
1+commit cd5603a4767277a29d3e67a9c3f2a5d2129cd973
2+Author: Sterling Augustine <saugustine@google.com>
3+Date: Tue Mar 19 20:01:59 2019 +0000
4+
5+ Add --unwindlib=[libgcc|compiler-rt] to parallel --rtlib= [take 2]
6+
7+ "clang++ hello.cc --rtlib=compiler-rt"
8+
9+ now can works without specifying additional unwind or exception
10+ handling libraries.
11+
12+ This reworked version of the feature no longer modifies today's default
13+ unwind library for compiler-rt: which is nothing. Rather, a user
14+ can specify -DCLANG_DEFAULT_UNWINDLIB=libunwind when configuring
15+ the compiler.
16+
17+ This should address the issues from the previous version.
18+
19+ Update tests for new --unwindlib semantics.
20+
21+ Differential Revision: https://reviews.llvm.org/D59109
22+
23+ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356508 91177308-0d34-0410-b5e6-96231b3b80d8
24+ (cherry picked from commit 344aa82a52f2fae527f58284567ae305a314f7a8)
25+
26+diff --git a/CMakeLists.txt b/CMakeLists.txt
27+index c2016a45ca..edeb2b66a1 100644
28+--- a/CMakeLists.txt
29++++ b/CMakeLists.txt
30+@@ -261,6 +261,24 @@ if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
31+ "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE)
32+ endif()
33+
34++set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING
35++ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty to match runtime library.)")
36++if (CLANG_DEFAULT_UNWINDLIB STREQUAL "")
37++ if (CLANG_DEFAULT_RTLIB STREQUAL "libgcc")
38++ set (CLANG_DEFAULT_UNWINDLIB "libgcc" CACHE STRING "" FORCE)
39++ elseif (CLANG_DEFAULT_RTLIBS STREQUAL "libunwind")
40++ set (CLANG_DEFAULT_UNWINDLIB "none" CACHE STRING "" FORCE)
41++ endif()
42++endif()
43++
44++if (NOT(CLANG_DEFAULT_UNWINDLIB STREQUAL "none" OR
45++ CLANG_DEFAULT_UNWINDLIB STREQUAL "libgcc" OR
46++ CLANG_DEFAULT_UNWINDLIB STREQUAL "libunwind"))
47++ message(WARNING "Resetting default unwindlib to use platform default")
48++ set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING
49++ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty for none)" FORCE)
50++endif()
51++
52+ set(CLANG_DEFAULT_OBJCOPY "objcopy" CACHE STRING
53+ "Default objcopy executable to use.")
54+
55+diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td
56+index 5475e28ed7..15971210e4 100644
57+--- a/include/clang/Basic/DiagnosticDriverKinds.td
58++++ b/include/clang/Basic/DiagnosticDriverKinds.td
59+@@ -52,6 +52,10 @@ def err_drv_invalid_rtlib_name : Error<
60+ "invalid runtime library name in argument '%0'">;
61+ def err_drv_unsupported_rtlib_for_platform : Error<
62+ "unsupported runtime library '%0' for platform '%1'">;
63++def err_drv_invalid_unwindlib_name : Error<
64++ "invalid unwind library name in argument '%0'">;
65++def err_drv_incompatible_unwindlib : Error<
66++ "--rtlib=libgcc requires --unwindlib=libgcc">;
67+ def err_drv_invalid_stdlib_name : Error<
68+ "invalid library name in argument '%0'">;
69+ def err_drv_invalid_output_with_multiple_archs : Error<
70+diff --git a/include/clang/Config/config.h.cmake b/include/clang/Config/config.h.cmake
71+index 1d624450b9..2d4cb747e8 100644
72+--- a/include/clang/Config/config.h.cmake
73++++ b/include/clang/Config/config.h.cmake
74+@@ -23,6 +23,9 @@
75+ /* Default runtime library to use. */
76+ #define CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}"
77+
78++/* Default unwind library to use. */
79++#define CLANG_DEFAULT_UNWINDLIB "${CLANG_DEFAULT_UNWINDLIB}"
80++
81+ /* Default objcopy to use */
82+ #define CLANG_DEFAULT_OBJCOPY "${CLANG_DEFAULT_OBJCOPY}"
83+
84+diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
85+index 75a21e66c7..4da0e54965 100644
86+--- a/include/clang/Driver/Options.td
87++++ b/include/clang/Driver/Options.td
88+@@ -2570,6 +2570,8 @@ def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
89+ }]>;
90+ def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
91+ HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
92++def unwindlib_EQ : Joined<["-", "--"], "unwindlib=">, Flags<[CC1Option]>,
93++ HelpText<"Unwind library to use">, Values<"libgcc,unwindlib,platform">;
94+ def sub__library : JoinedOrSeparate<["-"], "sub_library">;
95+ def sub__umbrella : JoinedOrSeparate<["-"], "sub_umbrella">;
96+ def system_header_prefix : Joined<["--"], "system-header-prefix=">,
97+diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h
98+index d5f75b8271..4bedf760eb 100644
99+--- a/include/clang/Driver/ToolChain.h
100++++ b/include/clang/Driver/ToolChain.h
101+@@ -100,6 +100,12 @@ public:
102+ RLT_Libgcc
103+ };
104+
105++ enum UnwindLibType {
106++ UNW_None,
107++ UNW_CompilerRT,
108++ UNW_Libgcc
109++ };
110++
111+ enum RTTIMode {
112+ RM_Enabled,
113+ RM_Disabled,
114+@@ -368,6 +374,10 @@ public:
115+ return ToolChain::CST_Libstdcxx;
116+ }
117+
118++ virtual UnwindLibType GetDefaultUnwindLibType() const {
119++ return ToolChain::UNW_None;
120++ }
121++
122+ virtual std::string getCompilerRTPath() const;
123+
124+ virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
125+@@ -512,6 +522,10 @@ public:
126+ // given compilation arguments.
127+ virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
128+
129++ // GetUnwindLibType - Determine the unwind library type to use with the
130++ // given compilation arguments.
131++ virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const;
132++
133+ /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
134+ /// the include paths to use for the given C++ standard library type.
135+ virtual void
136+diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
137+index 88a627eab6..d82423f4a8 100644
138+--- a/lib/Driver/ToolChain.cpp
139++++ b/lib/Driver/ToolChain.cpp
140+@@ -680,6 +680,33 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
141+ return GetDefaultRuntimeLibType();
142+ }
143+
144++ToolChain::UnwindLibType ToolChain::GetUnwindLibType(
145++ const ArgList &Args) const {
146++ const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
147++ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;
148++
149++ if (LibName == "none")
150++ return ToolChain::UNW_None;
151++ else if (LibName == "platform" || LibName == "") {
152++ ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args);
153++ if (RtLibType == ToolChain::RLT_CompilerRT)
154++ return ToolChain::UNW_None;
155++ else if (RtLibType == ToolChain::RLT_Libgcc)
156++ return ToolChain::UNW_Libgcc;
157++ } else if (LibName == "libunwind") {
158++ if (GetRuntimeLibType(Args) == RLT_Libgcc)
159++ getDriver().Diag(diag::err_drv_incompatible_unwindlib);
160++ return ToolChain::UNW_CompilerRT;
161++ } else if (LibName == "libgcc")
162++ return ToolChain::UNW_Libgcc;
163++
164++ if (A)
165++ getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
166++ << A->getAsString(Args);
167++
168++ return GetDefaultUnwindLibType();
169++}
170++
171+ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
172+ const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
173+ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB;
174+diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp
175+index 85ffc1618d..9fd29726a4 100644
176+--- a/lib/Driver/ToolChains/CommonArgs.cpp
177++++ b/lib/Driver/ToolChains/CommonArgs.cpp
178+@@ -1132,47 +1132,80 @@ bool tools::isObjCAutoRefCount(const ArgList &Args) {
179+ return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false);
180+ }
181+
182+-static void AddLibgcc(const llvm::Triple &Triple, const Driver &D,
183+- ArgStringList &CmdArgs, const ArgList &Args) {
184+- bool isAndroid = Triple.isAndroid();
185+- bool isCygMing = Triple.isOSCygMing();
186+- bool IsIAMCU = Triple.isOSIAMCU();
187+- bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
188+- Args.hasArg(options::OPT_static) ||
189+- Args.hasArg(options::OPT_static_pie);
190+-
191+- bool SharedLibgcc = Args.hasArg(options::OPT_shared_libgcc);
192+- bool UnspecifiedLibgcc = !StaticLibgcc && !SharedLibgcc;
193+-
194+- // Gcc adds libgcc arguments in various ways:
195+- //
196+- // gcc <none>: -lgcc --as-needed -lgcc_s --no-as-needed
197+- // g++ <none>: -lgcc_s -lgcc
198+- // gcc shared: -lgcc_s -lgcc
199+- // g++ shared: -lgcc_s -lgcc
200+- // gcc static: -lgcc -lgcc_eh
201+- // g++ static: -lgcc -lgcc_eh
202+- // gcc static-pie: -lgcc -lgcc_eh
203+- // g++ static-pie: -lgcc -lgcc_eh
204+- //
205+- // Also, certain targets need additional adjustments.
206++enum class LibGccType { UnspecifiedLibGcc, StaticLibGcc, SharedLibGcc };
207++
208++static LibGccType getLibGccType(const ArgList &Args) {
209++ bool Static = Args.hasArg(options::OPT_static_libgcc) ||
210++ Args.hasArg(options::OPT_static) ||
211++ Args.hasArg(options::OPT_static_pie);
212++
213++ bool Shared = Args.hasArg(options::OPT_shared_libgcc);
214++ if (Shared)
215++ return LibGccType::SharedLibGcc;
216++ if (Static)
217++ return LibGccType::StaticLibGcc;
218++ return LibGccType::UnspecifiedLibGcc;
219++}
220+
221+- bool LibGccFirst = (D.CCCIsCC() && UnspecifiedLibgcc) || StaticLibgcc;
222+- if (LibGccFirst)
223+- CmdArgs.push_back("-lgcc");
224++// Gcc adds libgcc arguments in various ways:
225++//
226++// gcc <none>: -lgcc --as-needed -lgcc_s --no-as-needed
227++// g++ <none>: -lgcc_s -lgcc
228++// gcc shared: -lgcc_s -lgcc
229++// g++ shared: -lgcc_s -lgcc
230++// gcc static: -lgcc -lgcc_eh
231++// g++ static: -lgcc -lgcc_eh
232++// gcc static-pie: -lgcc -lgcc_eh
233++// g++ static-pie: -lgcc -lgcc_eh
234++//
235++// Also, certain targets need additional adjustments.
236++
237++static void AddUnwindLibrary(const ToolChain &TC, const Driver &D,
238++ ArgStringList &CmdArgs, const ArgList &Args) {
239++ ToolChain::UnwindLibType UNW = TC.GetUnwindLibType(Args);
240++ // Targets that don't use unwind libraries.
241++ if (TC.getTriple().isAndroid() || TC.getTriple().isOSIAMCU() ||
242++ TC.getTriple().isOSBinFormatWasm() ||
243++ UNW == ToolChain::UNW_None)
244++ return;
245+
246+- bool AsNeeded = D.CCCIsCC() && UnspecifiedLibgcc && !isAndroid && !isCygMing;
247++ LibGccType LGT = getLibGccType(Args);
248++ bool AsNeeded = D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc &&
249++ !TC.getTriple().isAndroid() && !TC.getTriple().isOSCygMing();
250+ if (AsNeeded)
251+ CmdArgs.push_back("--as-needed");
252+
253+- if ((UnspecifiedLibgcc || SharedLibgcc) && !isAndroid)
254+- CmdArgs.push_back("-lgcc_s");
255+-
256+- else if (StaticLibgcc && !isAndroid && !IsIAMCU)
257+- CmdArgs.push_back("-lgcc_eh");
258++ switch (UNW) {
259++ case ToolChain::UNW_None:
260++ return;
261++ case ToolChain::UNW_Libgcc: {
262++ LibGccType LGT = getLibGccType(Args);
263++ if (LGT == LibGccType::UnspecifiedLibGcc || LGT == LibGccType::SharedLibGcc)
264++ CmdArgs.push_back("-lgcc_s");
265++ else if (LGT == LibGccType::StaticLibGcc)
266++ CmdArgs.push_back("-lgcc_eh");
267++ break;
268++ }
269++ case ToolChain::UNW_CompilerRT:
270++ CmdArgs.push_back("-lunwind");
271++ break;
272++ }
273+
274+ if (AsNeeded)
275+ CmdArgs.push_back("--no-as-needed");
276++}
277++
278++static void AddLibgcc(const ToolChain &TC, const Driver &D,
279++ ArgStringList &CmdArgs, const ArgList &Args) {
280++ bool isAndroid = TC.getTriple().isAndroid();
281++
282++ LibGccType LGT = getLibGccType(Args);
283++ bool LibGccFirst = (D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc) ||
284++ LGT == LibGccType::StaticLibGcc;
285++ if (LibGccFirst)
286++ CmdArgs.push_back("-lgcc");
287++
288++ AddUnwindLibrary(TC, D, CmdArgs, Args);
289+
290+ if (!LibGccFirst)
291+ CmdArgs.push_back("-lgcc");
292+@@ -1182,7 +1215,7 @@ static void AddLibgcc(const llvm::Triple &Triple, const Driver &D,
293+ //
294+ // NOTE: This fixes a link error on Android MIPS as well. The non-static
295+ // libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl.
296+- if (isAndroid && !StaticLibgcc)
297++ if (isAndroid && getLibGccType(Args) != LibGccType::StaticLibGcc)
298+ CmdArgs.push_back("-ldl");
299+ }
300+
301+@@ -1194,6 +1227,7 @@ void tools::AddRunTimeLibs(const ToolChain &TC, const Driver &D,
302+ switch (RLT) {
303+ case ToolChain::RLT_CompilerRT:
304+ CmdArgs.push_back(TC.getCompilerRTArgString(Args, "builtins"));
305++ AddUnwindLibrary(TC, D, CmdArgs, Args);
306+ break;
307+ case ToolChain::RLT_Libgcc:
308+ // Make sure libgcc is not used under MSVC environment by default
309+@@ -1205,7 +1239,7 @@ void tools::AddRunTimeLibs(const ToolChain &TC, const Driver &D,
310+ << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "MSVC";
311+ }
312+ } else
313+- AddLibgcc(TC.getTriple(), D, CmdArgs, Args);
314++ AddLibgcc(TC, D, CmdArgs, Args);
315+ break;
316+ }
317+ }
318+diff --git a/test/Driver/compiler-rt-unwind.c b/test/Driver/compiler-rt-unwind.c
319+new file mode 100644
320+index 0000000000..00024dfa7e
321+--- /dev/null
322++++ b/test/Driver/compiler-rt-unwind.c
323+@@ -0,0 +1,49 @@
324++// General tests that the driver handles combinations of --rtlib=XXX and
325++// --unwindlib=XXX properly.
326++//
327++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
328++// RUN: --target=x86_64-unknown-linux \
329++// RUN: --gcc-toolchain="" \
330++// RUN: | FileCheck --check-prefix=RTLIB-EMPTY %s
331++// RTLIB-EMPTY: "{{.*}}lgcc"
332++// RTLIB-EMPTY: "{{.*}}-lgcc_s"
333++//
334++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
335++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc \
336++// RUN: --gcc-toolchain="" \
337++// RUN: | FileCheck --check-prefix=RTLIB-GCC %s
338++// RTLIB-GCC: "{{.*}}lgcc"
339++// RTLIB-GCC: "{{.*}}lgcc_s"
340++//
341++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
342++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \
343++// RUN: --gcc-toolchain="" \
344++// RUN: | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s
345++// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc"
346++// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"
347++//
348++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
349++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt \
350++// RUN: --gcc-toolchain="" \
351++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT %s
352++// RTLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a"
353++//
354++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
355++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \
356++// RUN: --gcc-toolchain="" \
357++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC %s
358++// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}libclang_rt.builtins-x86_64.a"
359++// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}lgcc_s"
360++//
361++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
362++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \
363++// RUN: -static --gcc-toolchain="" \
364++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC %s
365++// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}libclang_rt.builtins-x86_64.a"
366++// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}lgcc_eh"
367++//
368++// RUN: not %clang -no-canonical-prefixes %s -o %t.o 2> %t.err \
369++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \
370++// RUN: --gcc-toolchain="" \
371++// RUN: FileCheck --input-file=%t.err --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER_RT %s
372++// RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires --unwindlib=libgcc"
pkgs/development/compilers/llvm/8/compiler-rt.nix+2−2
@@ -55,9 +55,9 @@ stdenv.mkDerivation rec {
5555 # Hack around weird upsream RPATH bug
5656 postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
5757 ln -s "$out/lib"/*/* "$out/lib"
58− '' + stdenv.lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
58+ '' + stdenv.lib.optionalString (stdenv.hostPlatform.useLLVM or false) ''
5959 ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
60− ln -s $out/lib/*/cclang_rt.crtend-*.o $out/lib/crtend.o
60+ ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o
6161 ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
6262 ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
6363 '';
pkgs/development/compilers/llvm/8/default.nix+59−15
@@ -23,7 +23,7 @@ let
2323 ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
2424 ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
2525 echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
26− '' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc) ''
26+ '' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
2727 echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
2828 '';
2929 in {
@@ -78,48 +78,80 @@ let
7878
7979 lldb = callPackage ./lldb.nix {};
8080
81+ # Below, is the LLVM bootstrapping logic. It handles building a
82+ # fully LLVM toolchain from scratch. No GCC toolchain should be
83+ # pulled in. As a consequence, it is very quick to build different
84+ # targets provided by LLVM and we can also build for what GCC
85+ # doesn’t support like LLVM. Probably we should move to some other
86+ # file.
87+
8188 bintools = callPackage ./bintools.nix {};
8289
8390 lldClang = wrapCCWith rec {
8491 cc = tools.clang-unwrapped;
92+ libcxx = targetLlvmLibraries.libcxx;
93+ bintools = wrapBintoolsWith {
94+ inherit (tools) bintools;
95+ };
96+ extraPackages = [
97+ targetLlvmLibraries.libcxx
98+ targetLlvmLibraries.libcxxabi
99+ targetLlvmLibraries.compiler-rt
100+ targetLlvmLibraries.libunwind
101+ ];
102+ extraBuildCommands = ''
103+ echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
104+ echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
105+ echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
106+ echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
107+ '' + mkExtraBuildCommands cc;
108+ };
109+
110+ lldClangNoLibcxx = wrapCCWith rec {
111+ cc = tools.clang-unwrapped;
112+ libcxx = null;
85113 bintools = wrapBintoolsWith {
86114 inherit (tools) bintools;
87115 };
88116 extraPackages = [
89− # targetLlvmLibraries.libcxx
90− # targetLlvmLibraries.libcxxabi
91117 targetLlvmLibraries.compiler-rt
92118 ];
93119 extraBuildCommands = ''
94− echo "-target ${stdenv.targetPlatform.config} -rtlib=compiler-rt" >> $out/nix-support/cc-cflags
120+ echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
121+ echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
122+ echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
123+ echo "-nostdlib++" >> $out/nix-support/cc-cflags
95124 '' + mkExtraBuildCommands cc;
96125 };
97126
98127 lldClangNoLibc = wrapCCWith rec {
99128 cc = tools.clang-unwrapped;
129+ libcxx = null;
100130 bintools = wrapBintoolsWith {
101131 inherit (tools) bintools;
102132 libc = null;
103133 };
104134 extraPackages = [
105− # targetLlvmLibraries.libcxx
106− # targetLlvmLibraries.libcxxabi
107135 targetLlvmLibraries.compiler-rt
108136 ];
109137 extraBuildCommands = ''
110− echo "-target ${stdenv.targetPlatform.config} -rtlib=compiler-rt" >> $out/nix-support/cc-cflags
138+ echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
139+ echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
140+ echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
111141 '' + mkExtraBuildCommands cc;
112142 };
113143
114144 lldClangNoCompilerRt = wrapCCWith rec {
115145 cc = tools.clang-unwrapped;
146+ libcxx = null;
116147 bintools = wrapBintoolsWith {
117148 inherit (tools) bintools;
118149 libc = null;
119150 };
120151 extraPackages = [ ];
121152 extraBuildCommands = ''
122− echo "-nostartfiles -target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
153+ echo "-nostartfiles" >> $out/nix-support/cc-cflags
154+ echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
123155 '';
124156 };
125157
@@ -129,21 +161,33 @@ let
129161 callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python isl release_version version fetch; });
130162 in {
131163
132− compiler-rt = callPackage ./compiler-rt.nix {
133− stdenv = if stdenv.hostPlatform.useLLVM or false
134− then overrideCC stdenv buildLlvmTools.lldClangNoCompilerRt
135− else stdenv;
136− };
164+ compiler-rt = callPackage ./compiler-rt.nix ({} //
165+ (stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
166+ stdenv = overrideCC stdenv buildLlvmTools.lldClangNoCompilerRt;
167+ }));
137168
138169 stdenv = overrideCC stdenv buildLlvmTools.clang;
139170
140171 libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
141172
142− libcxx = callPackage ./libc++ {};
173+ libcxx = callPackage ./libc++ ({} //
174+ (stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
175+ stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
176+ }));
143177
144− libcxxabi = callPackage ./libc++abi.nix {};
178+ libcxxabi = callPackage ./libc++abi.nix ({} //
179+ (stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
180+ stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
181+ libunwind = libraries.libunwind;
182+ }));
145183
146184 openmp = callPackage ./openmp.nix {};
185+
186+ libunwind = callPackage ./libunwind.nix ({} //
187+ (stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
188+ stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
189+ }));
190+
147191 });
148192
149193in { inherit tools libraries; } // libraries // tools
pkgs/development/compilers/llvm/8/libc++/default.nix+2−1
@@ -30,7 +30,8 @@ stdenv.mkDerivation rec {
3030 "-DLIBCXX_LIBCXXABI_LIB_PATH=${libcxxabi}/lib"
3131 "-DLIBCXX_LIBCPPABI_VERSION=2"
3232 "-DLIBCXX_CXX_ABI=libcxxabi"
33− ] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1";
33+ ] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1"
34+ ++ stdenv.lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON";
3435
3536 enableParallelBuilding = true;
3637
pkgs/development/compilers/llvm/8/libc++abi.nix+6−1
@@ -8,10 +8,15 @@ stdenv.mkDerivation {
88 nativeBuildInputs = [ cmake ];
99 buildInputs = stdenv.lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) libunwind;
1010
11+ cmakeFlags = stdenv.lib.optionals (stdenv.hostPlatform.useLLVM or false) [
12+ "-DLLVM_ENABLE_LIBCXX=ON"
13+ "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
14+ ];
15+
1116 postUnpack = ''
1217 unpackFile ${libcxx.src}
1318 unpackFile ${llvm.src}
14− export cmakeFlags="-DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)"
19+ cmakeFlags+=" -DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)"
1520 '' + stdenv.lib.optionalString stdenv.isDarwin ''
1621 export TRIPLE=x86_64-apple-darwin
1722 '' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
pkgs/development/compilers/llvm/8/libunwind.nixnew file+22
@@ -0,0 +1,22 @@
1+{ stdenv, version, fetch, cmake, libcxx, fetchpatch }:
2+
3+stdenv.mkDerivation {
4+ name = "libunwind-${version}";
5+
6+ src = fetch "libunwind" "0q7ndlldid9wchnny0a936llwxj7zgb9gxp46wjjxvwwkik3l97z";
7+
8+ nativeBuildInputs = [ cmake ];
9+
10+ patches = [
11+ (fetchpatch {
12+ url = "https://github.com/llvm-mirror/libunwind/commit/34a45c630d4c79af403661d267db42fbe7de1178.patch";
13+ sha256 = "0n0pv6jvcky8pn3srhrf9x5kbnd0d2kia9xlx2g590f5q0bgwfhv";
14+ })
15+ (fetchpatch {
16+ url = "https://github.com/llvm-mirror/libunwind/commit/e050272d2eb57eb4e56a37b429a61df2ebb8aa3e.patch";
17+ sha256 = "1sxyx5xnax8k713jjcxgq3jq3cpnxygs2rcdf5vfja0f2k9jzldl";
18+ })
19+ ];
20+
21+ enableParallelBuilding = true;
22+}
pkgs/development/libraries/kerberos/krb5.nix+2−1
@@ -39,8 +39,9 @@ stdenv.mkDerivation rec {
3939 ++ optional (!libOnly) yacc
4040 # Provides the mig command used by the build scripts
4141 ++ optional stdenv.isDarwin bootstrap_cmds;
42+
4243 buildInputs = [ openssl ]
43− ++ optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.libc != "bionic") [ keyutils ]
44+ ++ optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.libc != "bionic" && !(stdenv.hostPlatform.useLLVM or false)) [ keyutils ]
4445 ++ optionals (!libOnly) [ openldap libedit ];
4546
4647 preConfigure = "cd ./src";
pkgs/stdenv/cross/default.nix+1−1
@@ -55,7 +55,7 @@ in lib.init bootStages ++ [
5555 else if crossSystem.useAndroidPrebuilt or false
5656 then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".clang
5757 else if crossSystem.useLLVM or false
58− then buildPackages.llvmPackages_7.lldClang
58+ then buildPackages.llvmPackages_8.lldClang
5959 else buildPackages.gcc;
6060
6161 extraNativeBuildInputs = old.extraNativeBuildInputs
pkgs/top-level/all-packages.nix+1−1
@@ -6989,7 +6989,7 @@ in
69896989
69906990 crossLibcStdenv = overrideCC stdenv
69916991 (if stdenv.targetPlatform.useLLVM or false
6992− then buildPackages.llvmPackages_7.lldClangNoLibc
6992+ then buildPackages.llvmPackages_8.lldClangNoLibc
69936993 else buildPackages.gccCrossStageStatic);
69946994
69956995 # The GCC used to build libc for the target platform. Normal gccs will be