summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-02-15 01:13:54 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-02-15 01:13:54 +0000
commitd7c5ccec9cd767367796bd512c19b2a1c3225040 (patch)
tree52d0627529ed1b84c515e9b6ee8098397c76ca4b /clang/lib
parentaae04a9aa0af25ae725bbfc32feb4d6f7cbaa1df (diff)
downloadbcm5719-llvm-d7c5ccec9cd767367796bd512c19b2a1c3225040.tar.gz
bcm5719-llvm-d7c5ccec9cd767367796bd512c19b2a1c3225040.zip
Refactor GCC lib directory detection to make it easier to add lib directories
that are only checked for some targets. llvm-svn: 295139
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/ToolChains.cpp79
1 files changed, 45 insertions, 34 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp
index 44fb226d9e4..03db6ba2d24 100644
--- a/clang/lib/Driver/ToolChains.cpp
+++ b/clang/lib/Driver/ToolChains.cpp
@@ -2732,45 +2732,57 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
const llvm::Triple &TargetTriple, const ArgList &Args,
const std::string &LibDir, StringRef CandidateTriple,
bool NeedsBiarchSuffix) {
- llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
- // There are various different suffixes involving the triple we
- // check for. We also record what is necessary to walk from each back
- // up to the lib directory. Specifically, the number of "up" steps
- // in the second half of each row is 1 + the number of path separators
- // in the first half.
- const std::string LibAndInstallSuffixes[][2] = {
- {"/gcc/" + CandidateTriple.str(), "/../../.."},
-
- // Debian puts cross-compilers in gcc-cross
- {"/gcc-cross/" + CandidateTriple.str(), "/../../.."},
-
- {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(),
- "/../../../.."},
-
- // The Freescale PPC SDK has the gcc libraries in
- // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well.
- {"/" + CandidateTriple.str(), "/../.."},
-
- // Ubuntu has a strange mis-matched pair of triples that this happens to
- // match.
- // FIXME: It may be worthwhile to generalize this and look for a second
- // triple.
- {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}};
-
if (TargetTriple.getOS() == llvm::Triple::Solaris) {
scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple,
NeedsBiarchSuffix);
return;
}
- // Only look at the final, weird Ubuntu suffix for i386-linux-gnu.
- const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) -
- (TargetArch != llvm::Triple::x86));
- for (unsigned i = 0; i < NumLibSuffixes; ++i) {
- StringRef LibSuffix = LibAndInstallSuffixes[i][0];
+ llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
+ // Locations relative to the system lib directory where GCC's triple-specific
+ // directories might reside.
+ struct GCCLibSuffix {
+ // Path from system lib directory to GCC triple-specific directory.
+ std::string LibSuffix;
+ // Path from GCC triple-specific directory back to system lib directory.
+ // This is one '..' component per component in LibSuffix.
+ StringRef ReversePath;
+ // Whether this library suffix is relevant for the triple.
+ bool Active;
+ } Suffixes[] = {
+ // This is the normal place.
+ {"gcc/" + CandidateTriple.str(), "../..", true},
+
+ // Debian puts cross-compilers in gcc-cross.
+ {"gcc-cross/" + CandidateTriple.str(), "../..", true},
+
+ // The Freescale PPC SDK has the gcc libraries in
+ // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well.
+ // FIXME: Only do this on Freescale triples, since some systems put a *lot*
+ // of files in that location, not just GCC installation data.
+ {CandidateTriple.str(), "..", true},
+
+ // Natively multiarch systems sometimes put the GCC triple-specific
+ // directory within their multiarch lib directory, resulting in the
+ // triple appearing twice.
+ {CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), "../../..", true},
+
+ // Deal with cases (on Ubuntu) where the system architecture could be i386
+ // but the GCC target architecture could be (say) i686.
+ // FIXME: It may be worthwhile to generalize this and look for a second
+ // triple.
+ {"i386-linux-gnu/gcc/" + CandidateTriple.str(), "../../..",
+ TargetArch == llvm::Triple::x86}
+ };
+
+ for (auto &Suffix : Suffixes) {
+ if (!Suffix.Active)
+ continue;
+
+ StringRef LibSuffix = Suffix.LibSuffix;
std::error_code EC;
for (vfs::directory_iterator
- LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC),
+ LI = D.getVFS().dir_begin(LibDir + "/" + LibSuffix, EC),
LE;
!EC && LI != LE; LI = LI.increment(EC)) {
StringRef VersionText = llvm::sys::path::filename(LI->getName());
@@ -2792,9 +2804,8 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
// FIXME: We hack together the directory name here instead of
// using LI to ensure stable path separators across Windows and
// Linux.
- GCCInstallPath =
- LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str();
- GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1];
+ GCCInstallPath = (LibDir + "/" + LibSuffix + "/" + VersionText).str();
+ GCCParentLibPath = (GCCInstallPath + "/../" + Suffix.ReversePath).str();
IsValid = true;
}
}
OpenPOWER on IntegriCloud