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 @@ -212,6 +212,10 @@ /// The set of multilibs that the detected installation supports. MultilibSet Multilibs; + // Internal flags used to filter out /gcc and /gcc-cross. + bool HasGCCDir; + bool HasGCCCrossDir; + 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 @@ -1945,6 +1945,9 @@ const std::string LibDir = Prefix + Suffix.str(); if (!D.getVFS().exists(LibDir)) continue; + // Maybe filter out /gcc and /gcc-cross. + HasGCCDir = D.getVFS().exists(LibDir + "/gcc"); + HasGCCCrossDir = 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 +2466,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(), "../..", HasGCCDir}, // Debian puts cross-compilers in gcc-cross. - {"gcc-cross/" + CandidateTriple.str(), "../..", - TargetTriple.getOS() != llvm::Triple::Solaris}, + {"gcc-cross/" + CandidateTriple.str(), "../..", HasGCCCrossDir}, // The Freescale PPC SDK has the gcc libraries in // /usr/lib//x.y.z so have a look there as well. Only do