mgorny created this revision.
mgorny added reviewers: MaskRay, sunlin.
Herald added a subscriber: StephenFan.
Herald added a project: All.
mgorny requested review of this revision.

Change the code responsible for adding `../lib` directory relative
to the clang executable directory to apply only if clang is actually
run from the build directory.  According to the existing comment, this
is what the purpose of the code is.

Before, the addition was unconditional and therefore it was added
for installed clang as well.  Unfortunately, this meant that on 64-bit
Gentoo systems the effective `/usr/lib/llvm/*/lib` path would be added
implicitly and would take precedence over the correct
`/usr/lib/llvm/*/lib64` path if supplied by user.  Since `lib` contains
32-bit LLVM/Clang libraries, it would break the 64-bit apps trying
to link against them.


https://reviews.llvm.org/D122424

Files:
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -317,7 +317,11 @@
   if (StringRef(D.Dir).startswith(SysRoot)) {
     // Even if OSLibDir != "lib", this is needed for Clang in the build
     // directory (not installed) to find libc++.
-    addPathIfExists(D, D.Dir + "/../lib", Paths);
+    // Use the presence of build-specific files to detect whether we are
+    // dealing with the build tree and avoid adding 32-bit system "lib"
+    // directory otherwise.
+    if (D.getVFS().exists(D.Dir + "/../CMakeCache.txt"))
+      addPathIfExists(D, D.Dir + "/../lib", Paths);
     if (OSLibDir != "lib")
       addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
   }


Index: clang/lib/Driver/ToolChains/Linux.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -317,7 +317,11 @@
   if (StringRef(D.Dir).startswith(SysRoot)) {
     // Even if OSLibDir != "lib", this is needed for Clang in the build
     // directory (not installed) to find libc++.
-    addPathIfExists(D, D.Dir + "/../lib", Paths);
+    // Use the presence of build-specific files to detect whether we are
+    // dealing with the build tree and avoid adding 32-bit system "lib"
+    // directory otherwise.
+    if (D.getVFS().exists(D.Dir + "/../CMakeCache.txt"))
+      addPathIfExists(D, D.Dir + "/../lib", Paths);
     if (OSLibDir != "lib")
       addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to