[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 21 14:21:51 PDT 2018


phosek updated this revision to Diff 161818.

Repository:
  rC Clang

https://reviews.llvm.org/D50547

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp


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<std::string> 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<std::string> 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<std::string> 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(),
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 <ResourceDir>/lib/<Triple>. This is used by runtimes to find
+  // per-target libraries.
+  Optional<std::string> getTargetLibPath() const;
+
   // Returns <ResourceDir>/lib/<OSName>/<arch>.  This is used by runtimes (such
   // as OpenMP) to find arch-specific libraries.
   std::string getArchSpecificLibPath() const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50547.161818.patch
Type: text/x-patch
Size: 2703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180821/6044c82e/attachment.bin>


More information about the cfe-commits mailing list