Commit | Line | Data |
---|---|---|
d199a4c7 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-GuixSD systems. | |
8 | ||
9 | --- a/lib/Driver/ToolChains/Linux.cpp | |
10 | +++ b/lib/Driver/ToolChains/Linux.cpp | |
11 | @@ -225,7 +225,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
12 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + | |
13 | GCCInstallation.getTriple().str() + "/bin") | |
14 | .str()); | |
15 | - | |
16 | + // Comment out the distro-specific tweaks so that they don't bite when | |
17 | + // using Guix on a foreign distro. | |
18 | +#if 0 | |
19 | Distro Distro(D.getVFS()); | |
20 | ||
21 | if (Distro.IsAlpineLinux()) { | |
22 | @@ -284,6 +286,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
23 | ||
24 | if (IsAndroid || Distro.IsOpenSUSE()) | |
25 | ExtraOpts.push_back("--enable-new-dtags"); | |
26 | +#endif | |
27 | ||
28 | // The selection of paths to try here is designed to match the patterns which | |
29 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. | |
30 | @@ -342,7 +345,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
31 | // the cross. Note that GCC does include some of these directories in some | |
32 | // configurations but this seems somewhere between questionable and simply | |
33 | // a bug. | |
34 | - if (StringRef(LibPath).startswith(SysRoot)) { | |
35 | + if (0) { | |
36 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); | |
37 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); | |
38 | } | |
39 | @@ -361,6 +364,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
40 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); | |
41 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); | |
42 | ||
43 | + // This requires the commented distro tweaks above. | |
44 | +#if 0 | |
45 | if (IsAndroid) { | |
46 | // Android sysroots contain a library directory for each supported OS | |
47 | // version as well as some unversioned libraries in the usual multiarch | |
48 | @@ -389,10 +394,14 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
49 | addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths); | |
50 | addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths); | |
51 | } | |
52 | +#endif | |
53 | ||
54 | // Try walking via the GCC triple path in case of biarch or multiarch GCC | |
55 | // installations with strange symlinks. | |
56 | if (GCCInstallation.isValid()) { | |
57 | + // The following code would end up adding things like | |
58 | + // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path. | |
59 | +#if 0 | |
60 | addPathIfExists(D, | |
61 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + | |
62 | "/../../" + OSLibDir, | |
63 | @@ -405,6 +414,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
64 | BiarchSibling.gccSuffix(), | |
65 | Paths); | |
66 | } | |
67 | +#endif | |
68 | ||
69 | // See comments above on the multilib variant for details of why this is | |
70 | // included even from outside the sysroot. | |
71 | @@ -429,8 +439,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | |
72 | if (StringRef(D.Dir).startswith(SysRoot)) | |
73 | addPathIfExists(D, D.Dir + "/../lib", Paths); | |
74 | ||
75 | - addPathIfExists(D, SysRoot + "/lib", Paths); | |
76 | - addPathIfExists(D, SysRoot + "/usr/lib", Paths); | |
77 | + // Add libc's lib/ directory to the search path, so that crt1.o, crti.o, | |
78 | + // and friends can be found. | |
79 | + addPathIfExists(D, "@GLIBC_LIBDIR@", Paths); | |
80 | } | |
81 | ||
82 | bool Linux::HasNativeLLVMSupport() const { return true; } |