Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -362,6 +362,10 @@ StringRef Component, bool Shared = false) const; + // Returns /lib/. This is used by runtimes to find + // per-target libraries. + Optional getTargetLibPath() const; + // Returns /lib//. This is used by runtimes (such // as OpenMP) to find arch-specific libraries. std::string getArchSpecificLibPath() const; Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -74,10 +74,8 @@ const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, D.getTargetTriple(), "lib"); - if (getVFS().exists(P)) - getFilePaths().push_back(P.str()); + if (llvm::Optional TargetLibPath = getTargetLibPath()) + getFilePaths().push_back(*TargetLibPath); std::string CandidateLibPath = getArchSpecificLibPath(); if (getVFS().exists(CandidateLibPath)) @@ -362,10 +360,8 @@ 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)) { + if (llvm::Optional TargetLibPath = getTargetLibPath()) { + SmallString<128> P(*TargetLibPath); llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); return P.str(); } @@ -384,6 +380,21 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +Optional ToolChain::getTargetLibPath() const { + const Driver &D = getDriver(); + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, D.getTargetTriple(), "lib"); + if (getVFS().exists(P)) { + return std::string(P.str()); + } else { + P.assign(D.ResourceDir); + llvm::sys::path::append(P, Triple.str(), "lib"); + if (getVFS().exists(P)) + return std::string(P.str()); + } + return None; +} + std::string ToolChain::getArchSpecificLibPath() const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getOSLibName(),