diff --git a/clang/include/clang/Driver/Distro.h b/clang/include/clang/Driver/Distro.h --- a/clang/include/clang/Driver/Distro.h +++ b/clang/include/clang/Driver/Distro.h @@ -91,6 +91,8 @@ /// Detects the distribution using specified VFS. explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost); + llvm::ArrayRef getDefaultGCCTriples(llvm::Triple::ArchType Arch); + bool operator==(const Distro &Other) const { return DistroVal == Other.DistroVal; } diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp --- a/clang/lib/Driver/Distro.cpp +++ b/clang/lib/Driver/Distro.cpp @@ -225,3 +225,53 @@ Distro::Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost) : DistroVal(GetDistro(VFS, TargetOrHost)) {} + +/// @return An array of triples that should be used first when searching for +/// a candidate gcc install on the system. +llvm::ArrayRef Distro::getDefaultGCCTriples(llvm::Triple::ArchType Arch) { + if (!IsRedhat()) + return None; + + static const std::array RedHatAArch64Triples = {{ + "aarch64-redhat-linux" + }}; + + static const std::array RedHatArmTriples = {{ + "armv7hl-redhat-linux-gnueabi" + }}; + + static const std::array RedHatPPC64LETriples = {{ + "ppc64le-redhat-linux" + }}; + + static const std::array RedHatSystemZTriples = {{ + "s390x-redhat-linux" + }}; + + static const std::array RedHatX86Triples = {{ + "i686-redhat-linux" + }}; + + static const std::array RedHatX86_64Triples = {{ + "x86_64-redhat-linux" + }}; + + switch (Arch) { + default: + break; + case llvm::Triple::aarch64: + return RedHatAArch64Triples; + case llvm::Triple::arm: + return RedHatArmTriples; + case llvm::Triple::ppc64le: + return RedHatPPC64LETriples; + case llvm::Triple::systemz: + return RedHatSystemZTriples; + case llvm::Triple::x86: + return RedHatX86Triples; + case llvm::Triple::x86_64: + return RedHatX86_64Triples; + } + + return None; +} diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -177,7 +177,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { - GCCInstallation.init(Triple, Args); + + Distro Distro(D.getVFS(), Triple); + GCCInstallation.init(Triple, Args, Distro.getDefaultGCCTriples(Triple.getArch())); Multilibs = GCCInstallation.getMultilibs(); SelectedMultilib = GCCInstallation.getMultilib(); llvm::Triple::ArchType Arch = Triple.getArch(); @@ -186,7 +188,6 @@ Generic_GCC::PushPPaths(PPaths); - Distro Distro(D.getVFS(), Triple); if (Distro.IsAlpineLinux() || Triple.isAndroid()) { ExtraOpts.push_back("-z");