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

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