Skip to content

Commit bc868da

Browse files
committed
[Driver] Filter out <libdir>/gcc and <libdir>/gcc-cross if they do not exists
Differential Revision: https://reviews.llvm.org/D87901
1 parent 82da0ca commit bc868da

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,27 +1939,36 @@ void Generic_GCC::GCCInstallationDetector::init(
19391939
// installation available. GCC installs are ranked by version number.
19401940
Version = GCCVersion::Parse("0.0.0");
19411941
for (const std::string &Prefix : Prefixes) {
1942-
if (!D.getVFS().exists(Prefix))
1942+
auto &VFS = D.getVFS();
1943+
if (!VFS.exists(Prefix))
19431944
continue;
19441945
for (StringRef Suffix : CandidateLibDirs) {
19451946
const std::string LibDir = Prefix + Suffix.str();
1946-
if (!D.getVFS().exists(LibDir))
1947+
if (!VFS.exists(LibDir))
19471948
continue;
1949+
// Maybe filter out <libdir>/gcc and <libdir>/gcc-cross.
1950+
bool GCCDirExists = VFS.exists(LibDir + "/gcc");
1951+
bool GCCCrossDirExists = VFS.exists(LibDir + "/gcc-cross");
19481952
// Try to match the exact target triple first.
1949-
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str());
1953+
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str(),
1954+
false, GCCDirExists, GCCCrossDirExists);
19501955
// Try rest of possible triples.
19511956
for (StringRef Candidate : ExtraTripleAliases) // Try these first.
1952-
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
1957+
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, false,
1958+
GCCDirExists, GCCCrossDirExists);
19531959
for (StringRef Candidate : CandidateTripleAliases)
1954-
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
1960+
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, false,
1961+
GCCDirExists, GCCCrossDirExists);
19551962
}
19561963
for (StringRef Suffix : CandidateBiarchLibDirs) {
19571964
const std::string LibDir = Prefix + Suffix.str();
1958-
if (!D.getVFS().exists(LibDir))
1965+
if (!VFS.exists(LibDir))
19591966
continue;
1967+
bool GCCDirExists = VFS.exists(LibDir + "/gcc");
1968+
bool GCCCrossDirExists = VFS.exists(LibDir + "/gcc-cross");
19601969
for (StringRef Candidate : CandidateBiarchTripleAliases)
1961-
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate,
1962-
/*NeedsBiarchSuffix=*/ true);
1970+
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, true,
1971+
GCCDirExists, GCCCrossDirExists);
19631972
}
19641973
}
19651974
}
@@ -2450,7 +2459,7 @@ bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
24502459
void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
24512460
const llvm::Triple &TargetTriple, const ArgList &Args,
24522461
const std::string &LibDir, StringRef CandidateTriple,
2453-
bool NeedsBiarchSuffix) {
2462+
bool NeedsBiarchSuffix, bool GCCDirExists, bool GCCCrossDirExists) {
24542463
llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
24552464
// Locations relative to the system lib directory where GCC's triple-specific
24562465
// directories might reside.
@@ -2464,11 +2473,10 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
24642473
bool Active;
24652474
} Suffixes[] = {
24662475
// This is the normal place.
2467-
{"gcc/" + CandidateTriple.str(), "../..", true},
2476+
{"gcc/" + CandidateTriple.str(), "../..", GCCDirExists},
24682477

24692478
// Debian puts cross-compilers in gcc-cross.
2470-
{"gcc-cross/" + CandidateTriple.str(), "../..",
2471-
TargetTriple.getOS() != llvm::Triple::Solaris},
2479+
{"gcc-cross/" + CandidateTriple.str(), "../..", GCCCrossDirExists},
24722480

24732481
// The Freescale PPC SDK has the gcc libraries in
24742482
// <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. Only do

clang/lib/Driver/ToolChains/Gnu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
270270
const llvm::opt::ArgList &Args,
271271
const std::string &LibDir,
272272
StringRef CandidateTriple,
273-
bool NeedsBiarchSuffix = false);
273+
bool NeedsBiarchSuffix, bool GCCDirExists,
274+
bool GCCCrossDirExists);
274275

275276
bool ScanGentooConfigs(const llvm::Triple &TargetTriple,
276277
const llvm::opt::ArgList &Args,

0 commit comments

Comments
 (0)