Skip to content

Commit afaefb6

Browse files
committed
[Driver][Linux] Remove D.Dir+"/../lib" from default search paths for LLVM_ENABLE_RUNTIMES builds
The rule was added in 2014 to support -stdlib=libc++ and -lc++ without specifying -L, when D.Dir is not a well-known system library directory like /usr/lib /usr/lib64. This rule turns out to get in the way with (-m32 for 64-bit clang) or (-m64 for 32-bit clang) for Gentoo : llvm/llvm-project#54515 Nowadays LLVM_ENABLE_RUNTIMES is the only recommended way building libc++ and LLVM_ENABLE_PROJECTS=libc++ is deprecated. LLVM_ENABLE_RUNTIMES builds libc++ in D.Dir+"/../lib/${triple}/". The rule is unneeded. Also reverts D108286. Gentoo uses a modified LLVM_ENABLE_RUNTIMES that installs libc++.so in well-known paths like /usr/lib64 and /usr/lib which are already covered by nearby search paths. Implication: if a downstream package needs something like -lLLVM-15git and uses libLLVM-15git.so not in a well-known path, it needs to supply -L D.Dir+"/../lib" explicitly (e.g. via LLVMConfig.cmake), instead of relying on the previous default search path. Reviewed By: mgorny Differential Revision: https://reviews.llvm.org/D122444
1 parent 6c2be88 commit afaefb6

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,12 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
309309

310310
Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
311311

312-
// Similar to the logic for GCC above, if we are currently running Clang
313-
// inside of the requested system root, add its parent library path to those
314-
// searched.
315-
// FIXME: It's not clear whether we should use the driver's installed
316-
// directory ('Dir' below) or the ResourceDir.
317-
if (StringRef(D.Dir).startswith(SysRoot)) {
318-
// Even if OSLibDir != "lib", this is needed for Clang in the build
319-
// directory (not installed) to find libc++.
312+
// The deprecated -DLLVM_ENABLE_PROJECTS=libcxx configuration installs
313+
// libc++.so in D.Dir+"/../lib/". Detect this path.
314+
// TODO Remove once LLVM_ENABLE_PROJECTS=libcxx is unsupported.
315+
if (StringRef(D.Dir).startswith(SysRoot) &&
316+
D.getVFS().exists(D.Dir + "/../lib/libc++.so"))
320317
addPathIfExists(D, D.Dir + "/../lib", Paths);
321-
if (OSLibDir != "lib")
322-
addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
323-
}
324318

325319
if (!D.OverlayToolChainPath.empty()) {
326320
addPathIfExists(D, ExtraPath + "/lib", Paths);

clang/test/Driver/linux-ld.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@
530530
// CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
531531
// CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
532532
// CHECK-BASIC-LIBCXX-INSTALL: "--sysroot=[[SYSROOT]]"
533-
// CHECK-BASIC-LIBCXX-INSTALL: "-L[[SYSROOT]]/usr/bin/../lib"
534533
//
535534
// Test that we can use -stdlib=libc++ in a build system even when it
536535
// occasionally links C code instead of C++ code.
@@ -547,7 +546,6 @@
547546
// CHECK-BASIC-LIBCXX-C-LINK-NOT: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
548547
// CHECK-BASIC-LIBCXX-C-LINK: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
549548
// CHECK-BASIC-LIBCXX-C-LINK: "--sysroot=[[SYSROOT]]"
550-
// CHECK-BASIC-LIBCXX-C-LINK: "-L[[SYSROOT]]/usr/bin/../lib"
551549
//
552550
// Check multi arch support on Ubuntu 12.04 LTS.
553551
// RUN: %clang -no-canonical-prefixes %s -no-pie -### -o %t.o 2>&1 \

0 commit comments

Comments
 (0)