Index: include/clang/Driver/ToolChain.h =================================================================== --- include/clang/Driver/ToolChain.h +++ include/clang/Driver/ToolChain.h @@ -116,6 +116,9 @@ const RTTIMode CachedRTTIMode; + /// The list of toolchain specific path prefixes to search for libraries. + path_list LibraryPaths; + /// The list of toolchain specific path prefixes to search for files. path_list FilePaths; @@ -213,6 +216,9 @@ return EffectiveTriple; } + path_list &getLibraryPaths() { return LibraryPaths; } + const path_list &getLibraryPaths() const { return LibraryPaths; } + path_list &getFilePaths() { return FilePaths; } const path_list &getFilePaths() const { return FilePaths; } Index: lib/Driver/ToolChain.cpp =================================================================== --- lib/Driver/ToolChain.cpp +++ 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); @@ -762,6 +768,10 @@ void ToolChain::AddFilePathLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { + for (const auto &LibPath : getLibraryPaths()) + if(LibPath.length() > 0) + CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); + for (const auto &LibPath : getFilePaths()) if(LibPath.length() > 0) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));