diff --git a/clang/lib/Driver/ToolChains/Gnu.h b/clang/lib/Driver/ToolChains/Gnu.h --- a/clang/lib/Driver/ToolChains/Gnu.h +++ b/clang/lib/Driver/ToolChains/Gnu.h @@ -215,6 +215,10 @@ // Gentoo-specific toolchain configurations are stored here. const std::string GentooConfigDir = "/etc/env.d/gcc"; + // Internal flags used to filter out /gcc and /gcc-cross. + bool GCCDirExists; + bool GCCCrossDirExists; + public: explicit GCCInstallationDetector(const Driver &D) : IsValid(false), D(D) {} void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args, diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -1935,6 +1935,10 @@ return; } + // These should be set before calling ScanLibDirForGCCTriple(). + GCCDirExists = false; + GCCCrossDirExists = false; + // Loop over the various components which exist and select the best GCC // installation available. GCC installs are ranked by version number. Version = GCCVersion::Parse("0.0.0"); @@ -1945,6 +1949,9 @@ const std::string LibDir = Prefix + Suffix.str(); if (!D.getVFS().exists(LibDir)) continue; + // Maybe filter out /gcc and /gcc-cross. + GCCDirExists = D.getVFS().exists(LibDir + "/gcc"); + GCCCrossDirExists = D.getVFS().exists(LibDir + "/gcc-cross"); // Try to match the exact target triple first. ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str()); // Try rest of possible triples. @@ -2463,12 +2470,13 @@ // Whether this library suffix is relevant for the triple. bool Active; } Suffixes[] = { - // This is the normal place. - {"gcc/" + CandidateTriple.str(), "../..", true}, + // This is the normal place if Clang is installed alongside with GCC, + // probably with the same prefix. But it's likely does not exists in + // case of standalone Clang install. + {"gcc/" + CandidateTriple.str(), "../..", GCCDirExists}, // Debian puts cross-compilers in gcc-cross. - {"gcc-cross/" + CandidateTriple.str(), "../..", - TargetTriple.getOS() != llvm::Triple::Solaris}, + {"gcc-cross/" + CandidateTriple.str(), "../..", GCCCrossDirExists}, // The Freescale PPC SDK has the gcc libraries in // /usr/lib//x.y.z so have a look there as well. Only do