clang/SOURCES/0002-Driver-Add-a-gcc-equivalent-triple-to-the-list-of-tr.patch

59 lines
2.5 KiB
Diff
Raw Normal View History

2023-03-28 09:52:03 +00:00
From ccf3e4407e7a5c4c1f2e41c89aad9f86a9c7d81d Mon Sep 17 00:00:00 2001
2021-12-07 18:02:16 +00:00
From: Tom Stellard <tstellar@redhat.com>
Date: Wed, 6 Oct 2021 05:32:44 +0000
2023-03-28 09:52:03 +00:00
Subject: Driver: Add a gcc equivalent triple to the list of triples to search
2021-12-07 18:02:16 +00:00
There are some gcc triples, like x86_64-redhat-linux, that provide the
same behavior as a clang triple with a similar name (e.g.
x86_64-redhat-linux-gnu). When searching for a gcc install, also search
for a gcc equivalent triple if one exists.
Differential Revision: https://reviews.llvm.org/D111207
---
clang/lib/Driver/ToolChains/Gnu.cpp | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
2023-03-28 09:52:03 +00:00
index f203cae1d329..12fa2da3187e 100644
2021-12-07 18:02:16 +00:00
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
2023-03-28 09:52:03 +00:00
@@ -1969,6 +1969,18 @@ static llvm::StringRef getGCCToolchainDir(const ArgList &Args,
2021-12-07 18:02:16 +00:00
return GCC_INSTALL_PREFIX;
}
+/// This function takes a 'clang' triple and converts it to an equivalent gcc
+/// triple.
+static const char *ConvertToGccTriple(StringRef CandidateTriple) {
+ return llvm::StringSwitch<const char *>(CandidateTriple)
+ .Case("aarch64-redhat-linux-gnu", "aarch64-redhat-linux")
+ .Case("i686-redhat-linux-gnu", "i686-redhat-linux")
+ .Case("ppc64le-redhat-linux-gnu", "ppc64le-redhat-linux")
+ .Case("s390x-redhat-linux-gnu", "s390x-redhat-linux")
+ .Case("x86_64-redhat-linux-gnu", "x86_64-redhat-linux")
+ .Default(NULL);
+}
+
/// Initialize a GCCInstallationDetector from the driver.
///
/// This performs all of the autodetection and sets up the various paths.
2023-03-28 09:52:03 +00:00
@@ -1989,6 +2001,16 @@ void Generic_GCC::GCCInstallationDetector::init(
2021-12-07 18:02:16 +00:00
// The compatible GCC triples for this particular architecture.
SmallVector<StringRef, 16> CandidateTripleAliases;
SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
+
+ // In some cases gcc uses a slightly different triple than clang for the
+ // same target. Convert the clang triple to the gcc equivalent and use that
+ // to search for the gcc install.
+ const char *ConvertedTriple = ConvertToGccTriple(TargetTriple.str());
+ if (ConvertedTriple) {
+ CandidateTripleAliases.push_back(ConvertedTriple);
+ CandidateBiarchTripleAliases.push_back(ConvertedTriple);
+ }
+
CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
CandidateTripleAliases, CandidateBiarchLibDirs,
CandidateBiarchTripleAliases);
--
2023-03-28 09:52:03 +00:00
2.37.1
2021-12-07 18:02:16 +00:00