| 1 |
From b57ff6da9c8b281ae9312e245fd3372e7ffaff28 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Mike Hommey <[email protected]> |
| 3 |
Date: Thu, 23 Mar 2023 06:52:28 +0900 |
| 4 |
Subject: [PATCH] Apply the same fallbacks as runtimes search for stdlib search |
| 5 |
|
| 6 |
When building clang with e.g. LLVM_ENABLE_RUNTIMES=libcxx;libunwind, |
| 7 |
those runtimes end up in the stdlib search directory, and when |
| 8 |
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is set, that ends up in a |
| 9 |
target-specific subdirectory. The stdlib search does handle the |
| 10 |
situation, but when the target in question is Android, the same issues |
| 11 |
as those that required fallbacks for runtimes search apply. |
| 12 |
|
| 13 |
Traditionally, those libraries are shipped as part of the Android NDK, |
| 14 |
but when one builds their own clang for Android, they may want to use |
| 15 |
the runtimes from the same version rather than the ones from the NDK. |
| 16 |
|
| 17 |
Differential Revision: https://reviews.llvm.org/D146664 |
| 18 |
--- |
| 19 |
clang/lib/Driver/ToolChain.cpp | 42 +++++++++++++++++++--------------- |
| 20 |
1 file changed, 24 insertions(+), 18 deletions(-) |
| 21 |
|
| 22 |
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp |
| 23 |
index 2dba975a5a8f..9052099cad5e 100644 |
| 24 |
--- a/clang/lib/Driver/ToolChain.cpp |
| 25 |
+++ b/clang/lib/Driver/ToolChain.cpp |
| 26 |
@@ -569,15 +569,9 @@ const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args, |
| 27 |
return Args.MakeArgString(getCompilerRT(Args, Component, Type)); |
| 28 |
} |
| 29 |
|
| 30 |
-ToolChain::path_list ToolChain::getRuntimePaths() const { |
| 31 |
- path_list Paths; |
| 32 |
- auto addPathForTriple = [this, &Paths](const llvm::Triple &Triple) { |
| 33 |
- SmallString<128> P(D.ResourceDir); |
| 34 |
- llvm::sys::path::append(P, "lib", Triple.str()); |
| 35 |
- Paths.push_back(std::string(P.str())); |
| 36 |
- }; |
| 37 |
- |
| 38 |
- addPathForTriple(getTriple()); |
| 39 |
+template <typename F> |
| 40 |
+static void fillPaths(const ToolChain &TC, F addPathForTriple) { |
| 41 |
+ addPathForTriple(TC.getTriple()); |
| 42 |
|
| 43 |
// When building with per target runtime directories, various ways of naming |
| 44 |
// the Arm architecture may have been normalised to simply "arm". |
| 45 |
@@ -594,30 +588,42 @@ ToolChain::path_list ToolChain::getRuntimePaths() const { |
| 46 |
// |
| 47 |
// M profile Arm is bare metal and we know they will not be using the per |
| 48 |
// target runtime directory layout. |
| 49 |
- if (getTriple().getArch() == Triple::arm && !getTriple().isArmMClass()) { |
| 50 |
- llvm::Triple ArmTriple = getTriple(); |
| 51 |
+ if (TC.getTriple().getArch() == Triple::arm && |
| 52 |
+ !TC.getTriple().isArmMClass()) { |
| 53 |
+ llvm::Triple ArmTriple = TC.getTriple(); |
| 54 |
ArmTriple.setArch(Triple::arm); |
| 55 |
addPathForTriple(ArmTriple); |
| 56 |
} |
| 57 |
|
| 58 |
// Android targets may include an API level at the end. We still want to fall |
| 59 |
// back on a path without the API level. |
| 60 |
- if (getTriple().isAndroid() && |
| 61 |
- getTriple().getEnvironmentName() != "android") { |
| 62 |
- llvm::Triple TripleWithoutLevel = getTriple(); |
| 63 |
+ if (TC.getTriple().isAndroid() && |
| 64 |
+ TC.getTriple().getEnvironmentName() != "android") { |
| 65 |
+ llvm::Triple TripleWithoutLevel = TC.getTriple(); |
| 66 |
TripleWithoutLevel.setEnvironmentName("android"); |
| 67 |
addPathForTriple(TripleWithoutLevel); |
| 68 |
} |
| 69 |
+} |
| 70 |
|
| 71 |
+ToolChain::path_list ToolChain::getRuntimePaths() const { |
| 72 |
+ path_list Paths; |
| 73 |
+ auto addPathForTriple = [this, &Paths](const llvm::Triple &Triple) { |
| 74 |
+ SmallString<128> P(D.ResourceDir); |
| 75 |
+ llvm::sys::path::append(P, "lib", Triple.str()); |
| 76 |
+ Paths.push_back(std::string(P.str())); |
| 77 |
+ }; |
| 78 |
+ fillPaths(*this, addPathForTriple); |
| 79 |
return Paths; |
| 80 |
} |
| 81 |
|
| 82 |
ToolChain::path_list ToolChain::getStdlibPaths() const { |
| 83 |
path_list Paths; |
| 84 |
- SmallString<128> P(D.Dir); |
| 85 |
- llvm::sys::path::append(P, "..", "lib", getTripleString()); |
| 86 |
- Paths.push_back(std::string(P.str())); |
| 87 |
- |
| 88 |
+ auto addPathForTriple = [this, &Paths](const llvm::Triple &Triple) { |
| 89 |
+ SmallString<128> P(D.Dir); |
| 90 |
+ llvm::sys::path::append(P, "..", "lib", Triple.str()); |
| 91 |
+ Paths.push_back(std::string(P.str())); |
| 92 |
+ }; |
| 93 |
+ fillPaths(*this, addPathForTriple); |
| 94 |
return Paths; |
| 95 |
} |
| 96 |
|
| 97 |
-- |
| 98 |
2.39.0.1.g6739ec1790 |
| 99 |
|