aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/ToolChain.cpp
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2019-05-26 03:39:07 +0000
committerPetr Hosek <phosek@chromium.org>2019-05-26 03:39:07 +0000
commit2db79ef32c66035a89b5da409b8501945166c2a3 (patch)
treebd8eaabca9a165c595ce73845c036960a918eca4 /clang/lib/Driver/ToolChain.cpp
parentd4a9cae96500761f0933fb0eb0155a2848e70452 (diff)
downloadllvm-2db79ef32c66035a89b5da409b8501945166c2a3.zip
llvm-2db79ef32c66035a89b5da409b8501945166c2a3.tar.gz
llvm-2db79ef32c66035a89b5da409b8501945166c2a3.tar.bz2
[Driver] Update handling of c++ and runtime directories
This is a follow up to r361432 and r361504 which addresses issues introduced by those changes. Specifically, it avoids duplicating file and runtime paths in case when the effective triple is the same as the cannonical one. Furthermore, it fixes the broken multilib setup in the Fuchsia driver and deduplicates some of the code. Differential Revision: https://reviews.llvm.org/D62442 llvm-svn: 361709
Diffstat (limited to 'clang/lib/Driver/ToolChain.cpp')
-rw-r--r--clang/lib/Driver/ToolChain.cpp65
1 files changed, 41 insertions, 24 deletions
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 08d1ebb..01fb818 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -73,29 +73,13 @@ ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
const ArgList &Args)
: D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
- SmallString<128> P;
-
if (D.CCCIsCXX()) {
- P.assign(D.Dir);
- llvm::sys::path::append(P, "..", "lib", D.getTargetTriple(), "c++");
- if (getVFS().exists(P))
- getLibraryPaths().push_back(P.str());
-
- P.assign(D.Dir);
- llvm::sys::path::append(P, "..", "lib", Triple.str(), "c++");
- if (getVFS().exists(P))
- getLibraryPaths().push_back(P.str());
+ if (auto CXXStdlibPath = getCXXStdlibPath())
+ getFilePaths().push_back(*CXXStdlibPath);
}
- P.assign(D.ResourceDir);
- llvm::sys::path::append(P, D.getTargetTriple(), "lib");
- if (getVFS().exists(P))
- 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());
+ if (auto RuntimePath = getRuntimePath())
+ getLibraryPaths().push_back(*RuntimePath);
std::string CandidateLibPath = getArchSpecificLibPath();
if (getVFS().exists(CandidateLibPath))
@@ -421,6 +405,43 @@ const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
return Args.MakeArgString(getCompilerRT(Args, Component, Type));
}
+
+Optional<std::string> ToolChain::getRuntimePath() const {
+ SmallString<128> P;
+
+ // First try the triple passed to driver as --target=<triple>.
+ P.assign(D.ResourceDir);
+ llvm::sys::path::append(P, D.getTargetTriple(), "lib");
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ // Second try the normalized triple.
+ P.assign(D.ResourceDir);
+ llvm::sys::path::append(P, Triple.str(), "lib");
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ return None;
+}
+
+Optional<std::string> ToolChain::getCXXStdlibPath() const {
+ SmallString<128> P;
+
+ // First try the triple passed to driver as --target=<triple>.
+ P.assign(D.Dir);
+ llvm::sys::path::append(P, "..", "lib", D.getTargetTriple(), "c++");
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ // Second try the normalized triple.
+ P.assign(D.Dir);
+ llvm::sys::path::append(P, "..", "lib", Triple.str(), "c++");
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ return None;
+}
+
std::string ToolChain::getArchSpecificLibPath() const {
SmallString<128> Path(getDriver().ResourceDir);
llvm::sys::path::append(Path, "lib", getOSLibName(),
@@ -833,10 +854,6 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
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));