Commit | Line | Data |
---|---|---|
7f79358d MB |
1 | Clang attempts to guess file names based on the OS and distro (yes!), |
2 | but unfortunately, that doesn't work for us. | |
3 | ||
4 | This patch makes it easy to insert libc's $libdir so that Clang passes the | |
5 | correct absolute file name of crt1.o etc. to 'ld'. It also disables all | |
6 | the distro-specific stuff and removes the hard-coded FHS directory names | |
7 | to make sure Clang also works on non-Guix systems. | |
8 | ||
9 | diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp | |
10 | --- a/lib/Driver/ToolChains/Gnu.cpp | |
11 | +++ b/lib/Driver/ToolChains/Gnu.cpp | |
12 | @@ -2797,7 +2797,7 @@ void Generic_GCC::AddMultilibPaths(const Driver &D, | |
13 | // the cross. Note that GCC does include some of these directories in some | |
14 | // configurations but this seems somewhere between questionable and simply | |
15 | // a bug. | |
16 | - if (StringRef(LibPath).startswith(SysRoot)) { | |
17 | + if (0) { | |
18 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); | |
19 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); | |
20 | } | |
21 | @@ -2811,6 +2811,10 @@ void Generic_GCC::AddMultiarchPaths(const Driver &D, | |
22 | // Try walking via the GCC triple path in case of biarch or multiarch GCC | |
23 | // installations with strange symlinks. | |
24 | if (GCCInstallation.isValid()) { | |
25 | + | |
26 | +// The following code would end up adding things like | |
27 | +// "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path. | |
28 | +#if 0 | |
29 | addPathIfExists(D, | |
30 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + | |
31 | "/../../" + OSLibDir, | |
32 | @@ -2823,6 +2827,7 @@ void Generic_GCC::AddMultiarchPaths(const Driver &D, | |
33 | D, GCCInstallation.getInstallPath() + BiarchSibling.gccSuffix(), | |
34 | Paths); | |
35 | } | |
36 | +#endif // Guix | |
37 | ||
38 | // See comments above on the multilib variant for details of why this is | |
39 | // included even from outside the sysroot. | |
40 | diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp | |
41 | --- a/lib/Driver/ToolChains/Linux.cpp | |
42 | +++ b/lib/Driver/ToolChains/Linux.cpp | |
43 | @@ -219,6 +219,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
44 | ||
45 | Generic_GCC::PushPPaths(PPaths); | |
46 | ||
47 | +// Comment out the distro-specific tweaks so that they don't bite when | |
48 | +// using Guix on a foreign distro. | |
49 | +#if 0 | |
50 | Distro Distro(D.getVFS(), Triple); | |
51 | ||
52 | if (Distro.IsAlpineLinux() || Triple.isAndroid()) { | |
53 | @@ -284,6 +287,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
54 | ||
55 | if (IsAndroid || Distro.IsOpenSUSE()) | |
56 | ExtraOpts.push_back("--enable-new-dtags"); | |
57 | +#endif // Guix | |
58 | ||
59 | // The selection of paths to try here is designed to match the patterns which | |
60 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. | |
61 | @@ -310,6 +314,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
62 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); | |
63 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); | |
64 | ||
65 | +// This requires the commented distro tweaks above. | |
66 | +#if 0 | |
67 | if (IsAndroid) { | |
68 | // Android sysroots contain a library directory for each supported OS | |
69 | // version as well as some unversioned libraries in the usual multiarch | |
70 | @@ -338,6 +344,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
71 | addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths); | |
72 | addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths); | |
73 | } | |
74 | +#endif // Guix | |
75 | ||
76 | Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths); | |
77 | ||
78 | @@ -349,8 +356,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
79 | if (StringRef(D.Dir).startswith(SysRoot)) | |
80 | addPathIfExists(D, D.Dir + "/../lib", Paths); | |
81 | ||
82 | - addPathIfExists(D, SysRoot + "/lib", Paths); | |
83 | - addPathIfExists(D, SysRoot + "/usr/lib", Paths); | |
84 | + // Add libc's lib/ directory to the search path, so that crt1.o, crti.o, | |
85 | + // and friends can be found. | |
86 | + addPathIfExists(D, "@GLIBC_LIBDIR@", Paths); | |
87 | } | |
88 | ||
89 | ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const { |