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

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