Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -199,6 +199,8 @@ set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL "enable x86 relax relocations by default") +option(CLANG_PREFER_GCC_LIBRARIES "Prefer libraries installed next to GCC." ON) + set(CLANG_DEFAULT_LINKER "" CACHE STRING "Default linker to use (linker name or absolute path, empty for platform default)") Index: include/clang/Config/config.h.cmake =================================================================== --- include/clang/Config/config.h.cmake +++ include/clang/Config/config.h.cmake @@ -8,6 +8,9 @@ /* Bug report URL. */ #define BUG_REPORT_URL "${BUG_REPORT_URL}" +/* Prefer libraries installed next to GCC. */ +#cmakedefine CLANG_PREFER_GCC_LIBRARIES + /* Default linker to use. */ #define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}" Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -12,7 +12,7 @@ #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Version.h" #include "clang/Basic/VirtualFileSystem.h" -#include "clang/Config/config.h" // for GCC_INSTALL_PREFIX +#include "clang/Config/config.h" // for CLANG_PREFER_GCC_LIBRARIES and GCC_INSTALL_PREFIX #include "clang/Driver/Compilation.h" #include "clang/Driver/Distro.h" #include "clang/Driver/Driver.h" @@ -4161,6 +4161,19 @@ const std::string OSLibDir = getOSLibDir(Triple, Args); const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); +#ifndef CLANG_PREFER_GCC_LIBRARIES + // Similar to the logic for GCC below, if we currently running Clang inside + // of the requested system root, add its parent 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, D.Dir + "/../lib/" + MultiarchTriple, Paths); + addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); + addPathIfExists(D, D.Dir + "/../lib", Paths); + } +#endif + // Add the multilib suffixed paths where they are available. if (GCCInstallation.isValid()) { const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); @@ -4214,6 +4227,7 @@ } } +#ifdef CLANG_PREFER_GCC_LIBRARIES // Similar to the logic for GCC above, if we currently running Clang inside // of the requested system root, add its parent library paths to // those searched. @@ -4223,6 +4237,7 @@ addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); } +#endif addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); @@ -4260,6 +4275,7 @@ addPathIfExists(D, LibPath, Paths); } +#ifdef CLANG_PREFER_GCC_LIBRARIES // 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. @@ -4267,6 +4283,7 @@ // directory ('Dir' below) or the ResourceDir. if (StringRef(D.Dir).startswith(SysRoot)) addPathIfExists(D, D.Dir + "/../lib", Paths); +#endif addPathIfExists(D, SysRoot + "/lib", Paths); addPathIfExists(D, SysRoot + "/usr/lib", Paths);