From 442874b97b7d00e027d2e95398e6b04a220c8d66 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Thu, 10 Aug 2017 04:16:38 +0000 Subject: [PATCH] [Driver] Search compiler-rt paths in -print-file-name= This makes it possible to print the name of compiler-rt libraries by using simply clang -print-file-name=libclang_rt.${runtime}-${arch}.so same as other libraries, without having to know the details of the resource directory organization. Differential Revision: https://reviews.llvm.org/D35820 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310548 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/ToolChain.h | 2 ++ lib/Driver/Driver.cpp | 7 ++++++- lib/Driver/ToolChain.cpp | 11 ++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index d74d1e0e58..e354acb6d0 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -309,6 +309,8 @@ public: return ToolChain::CST_Libstdcxx; } + virtual std::string getCompilerRTPath() const; + virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, bool Shared = false) const; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index e1c632569d..b11629aace 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -3682,7 +3682,12 @@ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const { return P.str(); } - SmallString<128> P(ResourceDir); + SmallString<128> R(ResourceDir); + llvm::sys::path::append(R, Name); + if (llvm::sys::fs::exists(Twine(R))) + return R.str(); + + SmallString<128> P(TC.getCompilerRTPath()); llvm::sys::path::append(P, Name); if (llvm::sys::fs::exists(Twine(P))) return P.str(); diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 10fad752cf..c7c377971e 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -308,6 +308,13 @@ static StringRef getArchNameForCompilerRTLib(const ToolChain &TC, return TC.getArchName(); } +std::string ToolChain::getCompilerRTPath() const { + SmallString<128> Path(getDriver().ResourceDir); + StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS(); + llvm::sys::path::append(Path, "lib", OSLibName); + return Path.str(); +} + std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, bool Shared) const { const llvm::Triple &TT = getTriple(); @@ -320,9 +327,7 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); - SmallString<128> Path(getDriver().ResourceDir); - StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS(); - llvm::sys::path::append(Path, "lib", OSLibName); + SmallString<128> Path(getCompilerRTPath()); llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" + Arch + Env + Suffix); return Path.str(); -- 2.40.0