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

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