[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 17:39:27 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: YunQiang Su (wzssyqa)
<details>
<summary>Changes</summary>
Currently, clang looks for compiler-rt only from the normalized triple subdir. While if we are configured with a non-normalized triple with -DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without vendor section, clang will fail to find compiler_rt.
Let's look for compiler_rt from the subdir with name from --target option, too.
To archive this, we add a new member called Origin to class Triple.
Fixes: #<!-- -->87150.
---
Full diff: https://github.com/llvm/llvm-project/pull/88334.diff
4 Files Affected:
- (modified) clang/lib/Driver/Driver.cpp (+1)
- (modified) clang/lib/Driver/ToolChain.cpp (+6)
- (modified) llvm/include/llvm/TargetParser/Triple.h (+6)
- (modified) llvm/lib/TargetParser/Triple.cpp (+3-3)
``````````diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e7335a61b10c53..4a0c939039eb31 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -516,6 +516,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
TargetTriple = A->getValue();
llvm::Triple Target(llvm::Triple::normalize(TargetTriple));
+ Target.setOrigin(TargetTriple);
// GNU/Hurd's triples should have been -hurd-gnu*, but were historically made
// -gnu* only, and we can not change this, so we have to detect that case as
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 237092ed07e5dc..57f27a61c4060b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -755,6 +755,12 @@ std::optional<std::string>
ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
auto getPathForTriple =
[&](const llvm::Triple &Triple) -> std::optional<std::string> {
+ if (!Triple.getOrigin().empty()) {
+ SmallString<128> Po(BaseDir);
+ llvm::sys::path::append(Po, Triple.getOrigin());
+ if (getVFS().exists(Po))
+ return std::string(Po);
+ }
SmallString<128> P(BaseDir);
llvm::sys::path::append(P, Triple.str());
if (getVFS().exists(P))
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index f256e2b205a889..a2fc28ada0ca31 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -298,6 +298,8 @@ class Triple {
private:
std::string Data;
+ StringRef Origin = StringRef();
+
/// The parsed arch type.
ArchType Arch{};
@@ -425,6 +427,8 @@ class Triple {
const std::string &getTriple() const { return Data; }
+ const StringRef getOrigin() const { return Origin; }
+
/// Get the architecture (first) component of the triple.
StringRef getArchName() const;
@@ -1058,6 +1062,8 @@ class Triple {
/// @name Mutators
/// @{
+ void setOrigin(StringRef Orig) { Origin = Orig; };
+
/// Set the architecture (first) component of the triple to a known type.
void setArch(ArchType Kind, SubArchType SubArch = NoSubArch);
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 624679ff507a7f..ce44903d0f7d70 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -928,9 +928,9 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
/// This stores the string representation and parses the various pieces into
/// enum members.
Triple::Triple(const Twine &Str)
- : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
- Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
- ObjectFormat(UnknownObjectFormat) {
+ : Data(Str.str()), Origin(Str.getSingleStringRef()), Arch(UnknownArch),
+ SubArch(NoSubArch), Vendor(UnknownVendor), OS(UnknownOS),
+ Environment(UnknownEnvironment), ObjectFormat(UnknownObjectFormat) {
// Do minimal parsing by hand here.
SmallVector<StringRef, 4> Components;
StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
``````````
</details>
https://github.com/llvm/llvm-project/pull/88334
More information about the llvm-commits
mailing list