Skip to content

Commit a4d6590

Browse files
committed
Look for compiler-rt from subdir given by --target
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. To archive this, we add a new member called Origin to class Triple. Fixes: llvm#87150.
1 parent 938a734 commit a4d6590

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
516516
TargetTriple = A->getValue();
517517

518518
llvm::Triple Target(llvm::Triple::normalize(TargetTriple));
519+
Target.setOrigin(TargetTriple);
519520

520521
// GNU/Hurd's triples should have been -hurd-gnu*, but were historically made
521522
// -gnu* only, and we can not change this, so we have to detect that case as

clang/lib/Driver/ToolChain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,12 @@ std::optional<std::string>
755755
ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
756756
auto getPathForTriple =
757757
[&](const llvm::Triple &Triple) -> std::optional<std::string> {
758+
if (!Triple.getOrigin().empty()) {
759+
SmallString<128> Po(BaseDir);
760+
llvm::sys::path::append(Po, Triple.getOrigin());
761+
if (getVFS().exists(Po))
762+
return std::string(Po);
763+
}
758764
SmallString<128> P(BaseDir);
759765
llvm::sys::path::append(P, Triple.str());
760766
if (getVFS().exists(P))

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ class Triple {
298298
private:
299299
std::string Data;
300300

301+
StringRef Origin = StringRef();
302+
301303
/// The parsed arch type.
302304
ArchType Arch{};
303305

@@ -425,6 +427,8 @@ class Triple {
425427

426428
const std::string &getTriple() const { return Data; }
427429

430+
const StringRef getOrigin() const { return Origin; }
431+
428432
/// Get the architecture (first) component of the triple.
429433
StringRef getArchName() const;
430434

@@ -1058,6 +1062,8 @@ class Triple {
10581062
/// @name Mutators
10591063
/// @{
10601064

1065+
void setOrigin(StringRef Orig) { Origin = Orig; };
1066+
10611067
/// Set the architecture (first) component of the triple to a known type.
10621068
void setArch(ArchType Kind, SubArchType SubArch = NoSubArch);
10631069

llvm/lib/TargetParser/Triple.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,9 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
928928
/// This stores the string representation and parses the various pieces into
929929
/// enum members.
930930
Triple::Triple(const Twine &Str)
931-
: Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
932-
Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
933-
ObjectFormat(UnknownObjectFormat) {
931+
: Data(Str.str()), Origin(Str.getSingleStringRef()), Arch(UnknownArch),
932+
SubArch(NoSubArch), Vendor(UnknownVendor), OS(UnknownOS),
933+
Environment(UnknownEnvironment), ObjectFormat(UnknownObjectFormat) {
934934
// Do minimal parsing by hand here.
935935
SmallVector<StringRef, 4> Components;
936936
StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);

0 commit comments

Comments
 (0)