Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -122,6 +122,9 @@ /// The list of toolchain specific path prefixes to search for programs. path_list ProgramPaths; + /// The list of toolchain specific path prefixes to search for libraries. + path_list LibraryPaths; + mutable std::unique_ptr Clang; mutable std::unique_ptr Assemble; mutable std::unique_ptr Link; @@ -219,6 +222,9 @@ path_list &getProgramPaths() { return ProgramPaths; } const path_list &getProgramPaths() const { return ProgramPaths; } + path_list &getLibraryPaths() { return LibraryPaths; } + const path_list &getLibraryPaths() const { return LibraryPaths; } + const MultilibSet &getMultilibs() const { return Multilibs; } const SanitizerArgs& getSanitizerArgs() const; Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,17 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); + SmallString<128> P; + + P.assign(D.ResourceDir); llvm::sys::path::append(P, D.getTargetTriple(), "lib"); if (getVFS().exists(P)) - getFilePaths().push_back(P.str()); + getLibraryPaths().push_back(P.str()); + + P.assign(D.ResourceDir); + llvm::sys::path::append(P, Triple.str(), "lib"); + if (getVFS().exists(P)) + getLibraryPaths().push_back(P.str()); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,12 +369,11 @@ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - const Driver &D = getDriver(); - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) { + for (const auto &LibPath : getLibraryPaths()) { + SmallString<128> P(LibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); - return P.str(); + if (getVFS().exists(P)) + return P.str(); } StringRef Arch = getArchNameForCompilerRTLib(*this, Args); @@ -765,6 +771,10 @@ for (const auto &LibPath : getFilePaths()) if(LibPath.length() > 0) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); + + for (const auto &LibPath : getLibraryPaths()) + if(LibPath.length() > 0) + CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); } void ToolChain::AddCCKextLibArgs(const ArgList &Args,