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

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