Skip to content

Commit 5c4cf01

Browse files
MaskRaytstellar
authored andcommitted
[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 : #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 (cherry picked from commit afaefb6)
1 parent f3f90ec commit 5c4cf01

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
@@ -301,18 +301,12 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
301301

302302
Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
303303

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

317311
addPathIfExists(D, SysRoot + "/lib", Paths);
318312
addPathIfExists(D, SysRoot + "/usr/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 -### -o %t.o 2>&1 \

0 commit comments

Comments
 (0)