[PATCH] D122424: [clang] [Driver] Add clang's relative `../lib` path only when in build tree

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 12:17:39 PDT 2022


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);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122424.418014.patch
Type: text/x-patch
Size: 820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220324/2aa02347/attachment.bin>


More information about the cfe-commits mailing list