[PATCH] D146664: Apply the same fallbacks as runtimes search for stdlib search

Mike Hommey via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 22 15:10:11 PDT 2023


glandium created this revision.
glandium added a reviewer: thakis.
Herald added a project: All.
glandium requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

When building clang with e.g. LLVM_ENABLE_RUNTIMES=libcxx;libunwind,
those runtimes end up in the stdlib search directory, and when
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is set, that ends up in a
target-specific subdirectory. The stdlib search does handle the
situation, but when the target in question is Android, the same issues
as those that required fallbacks for runtimes search apply.

Traditionally, those libraries are shipped as part of the Android NDK,
but when one builds their own clang for Android, they may want to use
the runtimes from the same version rather than the ones from the NDK.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146664

Files:
  clang/lib/Driver/ToolChain.cpp


Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -569,15 +569,9 @@
   return Args.MakeArgString(getCompilerRT(Args, Component, Type));
 }
 
-ToolChain::path_list ToolChain::getRuntimePaths() const {
-  path_list Paths;
-  auto addPathForTriple = [this, &Paths](const llvm::Triple &Triple) {
-    SmallString<128> P(D.ResourceDir);
-    llvm::sys::path::append(P, "lib", Triple.str());
-    Paths.push_back(std::string(P.str()));
-  };
-
-  addPathForTriple(getTriple());
+template <typename F>
+static void fillPaths(const ToolChain &TC, F addPathForTriple) {
+  addPathForTriple(TC.getTriple());
 
   // When building with per target runtime directories, various ways of naming
   // the Arm architecture may have been normalised to simply "arm".
@@ -594,30 +588,42 @@
   //
   // M profile Arm is bare metal and we know they will not be using the per
   // target runtime directory layout.
-  if (getTriple().getArch() == Triple::arm && !getTriple().isArmMClass()) {
-    llvm::Triple ArmTriple = getTriple();
+  if (TC.getTriple().getArch() == Triple::arm &&
+      !TC.getTriple().isArmMClass()) {
+    llvm::Triple ArmTriple = TC.getTriple();
     ArmTriple.setArch(Triple::arm);
     addPathForTriple(ArmTriple);
   }
 
   // Android targets may include an API level at the end. We still want to fall
   // back on a path without the API level.
-  if (getTriple().isAndroid() &&
-      getTriple().getEnvironmentName() != "android") {
-    llvm::Triple TripleWithoutLevel = getTriple();
+  if (TC.getTriple().isAndroid() &&
+      TC.getTriple().getEnvironmentName() != "android") {
+    llvm::Triple TripleWithoutLevel = TC.getTriple();
     TripleWithoutLevel.setEnvironmentName("android");
     addPathForTriple(TripleWithoutLevel);
   }
+}
 
+ToolChain::path_list ToolChain::getRuntimePaths() const {
+  path_list Paths;
+  auto addPathForTriple = [this, &Paths](const llvm::Triple &Triple) {
+    SmallString<128> P(D.ResourceDir);
+    llvm::sys::path::append(P, "lib", Triple.str());
+    Paths.push_back(std::string(P.str()));
+  };
+  fillPaths(*this, addPathForTriple);
   return Paths;
 }
 
 ToolChain::path_list ToolChain::getStdlibPaths() const {
   path_list Paths;
-  SmallString<128> P(D.Dir);
-  llvm::sys::path::append(P, "..", "lib", getTripleString());
-  Paths.push_back(std::string(P.str()));
-
+  auto addPathForTriple = [this, &Paths](const llvm::Triple &Triple) {
+    SmallString<128> P(D.Dir);
+    llvm::sys::path::append(P, "..", "lib", Triple.str());
+    Paths.push_back(std::string(P.str()));
+  };
+  fillPaths(*this, addPathForTriple);
   return Paths;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146664.507522.patch
Type: text/x-patch
Size: 2728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230322/d52b8320/attachment.bin>


More information about the cfe-commits mailing list