From: Chandler Carruth Date: Tue, 21 Jan 2014 22:49:05 +0000 (+0000) Subject: Teach Clang to look in its installation libdir for libraries (such as X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a19edf4fd6500b256154f8b5e89e6231735f3ba7;p=clang Teach Clang to look in its installation libdir for libraries (such as libc++) when the installation is within the system root. This doesn't really help cross compiles much, but we don't (currently) have a great story around libc++, cross compiles, and who is responsible for building and/or installing the libraries. However, it handles the very common case of non-cross builds in a way entirely consistent with GCC, so I'm hopeful this won't really hose anyone. This is the second patch that I think should be backported to 3.4 to give folks an easy to checkout and install working Clang+libc++ toolchain. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199769 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index b8d9639e9c..b7cb874e07 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -2695,6 +2695,17 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) addPathIfExists(LibPath + "/../" + Multilib, Paths); } } + + // Similar to the logic for GCC above, if we currently running Clang inside + // of the requested system root, add its parent multilib library paths to + // those searched. + // FIXME: It's not clear whether we should use the driver's installed + // directory ('Dir' below) or the ResourceDir. + if (StringRef(D.Dir).startswith(SysRoot)) { + addPathIfExists(D.Dir + "/../lib/" + MultiarchTriple, Paths); + addPathIfExists(D.Dir + "/../" + Multilib, Paths); + } + addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths); addPathIfExists(SysRoot + "/lib/../" + Multilib, Paths); addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths); @@ -2723,6 +2734,15 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) if (StringRef(LibPath).startswith(SysRoot)) addPathIfExists(LibPath, Paths); } + + // Similar to the logic for GCC above, if we are currently running Clang + // inside of the requested system root, add its parent library path to those + // searched. + // FIXME: It's not clear whether we should use the driver's installed + // directory ('Dir' below) or the ResourceDir. + if (StringRef(D.Dir).startswith(SysRoot)) + addPathIfExists(D.Dir + "/../lib", Paths); + addPathIfExists(SysRoot + "/lib", Paths); addPathIfExists(SysRoot + "/usr/lib", Paths); } diff --git a/test/Driver/linux-ld.c b/test/Driver/linux-ld.c index 9e9aa3508d..52f015f362 100644 --- a/test/Driver/linux-ld.c +++ b/test/Driver/linux-ld.c @@ -214,6 +214,32 @@ // CHECK-GCC-VERSION4: "{{.*}}/Inputs/gcc_version_parsing4/bin/../lib/gcc/i386-unknown-linux/4.7.99{{/|\\\\}}crtbegin.o" // CHECK-GCC-VERSION4: "-L{{.*}}/Inputs/gcc_version_parsing4/bin/../lib/gcc/i386-unknown-linux/4.7.99" // +// Test a simulated installation of libc++ on Linux, both through sysroot and +// the installation path of Clang. +// RUN: %clangxx -no-canonical-prefixes -x c++ %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux-gnu \ +// RUN: -stdlib=libc++ \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree \ +// RUN: | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT %s +// CHECK-BASIC-LIBCXX-SYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-BASIC-LIBCXX-SYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" +// CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-BASIC-LIBCXX-SYSROOT: "--sysroot=[[SYSROOT]]" +// RUN: %clang -no-canonical-prefixes -x c++ %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-linux-gnu \ +// RUN: -stdlib=libc++ \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_libcxx_tree/usr/bin \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree \ +// RUN: | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-INSTALL %s +// CHECK-BASIC-LIBCXX-INSTALL: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-BASIC-LIBCXX-INSTALL: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1" +// CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-BASIC-LIBCXX-INSTALL: "--sysroot=[[SYSROOT]]" +// CHECK-BASIC-LIBCXX-INSTALL: "-L[[SYSROOT]]/usr/bin/../lib" +// // Test a very broken version of multiarch that shipped in Ubuntu 11.04. // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: --target=i386-unknown-linux \