aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/ToolChains.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-10-04 09:47:17 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-10-04 09:47:17 +0000
commita24b9802d3009c448387174f70bcd9ab44b8a7ea (patch)
treeca2683c4c274a6b06ae3b66047c8d185b7bddbe6 /lib/Driver/ToolChains.cpp
parent810e08126fc5d270976e5513baa1810882301bb0 (diff)
Invert the loop for detecting installed GCC trees. This make the loop
find the newest GCC available, among other goodness. It makes the entire system much less prone to error from prefixes and/or system roots pruning early the set of triples and GCC versions available. Also, improve some comments and simplify the forms of some of the loops. This causes the driver to stat directories more often than is strictly necessary, but the alternatives which I looked at that still accomplished this goal needed quite a bit more code and were likely not much faster. Test cases for this, now that our behavior here is significantly more principled and predictable, should come tomorrow as I walk back through VMs looking for edge cases that are missed after this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/ToolChains.cpp')
-rw-r--r--lib/Driver/ToolChains.cpp55
1 files changed, 19 insertions, 36 deletions
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 4da5622d96..dd84992a9c 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -1537,7 +1537,7 @@ public:
llvm::Triple::ArchType HostArch = llvm::Triple(GccTriple).getArch();
// The library directories which may contain GCC installations.
- SmallVector<StringRef, 2> CandidateLibDirs;
+ SmallVector<StringRef, 4> CandidateLibDirs;
// The compatible GCC triples for this particular architecture.
SmallVector<StringRef, 10> CandidateTriples;
if (HostArch == llvm::Triple::arm || HostArch == llvm::Triple::thumb) {
@@ -1600,6 +1600,11 @@ public:
// specific triple is detected.
CandidateTriples.push_back(D.DefaultHostTriple);
+ // Loop over the various components which exist and select the best GCC
+ // installation available. GCC installs are ranked based on age, triple
+ // accuracy, and architecture specificity in that order. The inverted walk
+ // requires testing the filesystem more times than is ideal, but shouldn't
+ // matter in practice as this is once on startup.
static const char* GccVersions[] = {
"4.6.1", "4.6.0", "4.6",
"4.5.3", "4.5.2", "4.5.1", "4.5",
@@ -1607,50 +1612,28 @@ public:
"4.3.4", "4.3.3", "4.3.2", "4.3",
"4.2.4", "4.2.3", "4.2.2", "4.2.1", "4.2",
"4.1.1"};
-
- // Set this as valid so we can early exit from the loops if we find
- // a viable installation.
- IsValid = true;
-
SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(),
D.PrefixDirs.end());
Prefixes.push_back(D.SysRoot + "/usr");
- // FIXME: This entire nested loop structure is broken. The structure is
- // well suited to quickly pruning impossible (non-existent) sub-trees, but
- // doesn't find all viable GCC installations and choose the best one. We
- // should invert this, and prune the impossible subtrees bottom-up, but
- // then select the best GCC installation top-down so that we prefer the
- // newest GCC, the most accurate triple, and only at the end select the lib
- // and prefix directories containing that installation.
- for (SmallVectorImpl<std::string>::const_iterator PI = Prefixes.begin(),
- PE = Prefixes.end();
- PI != PE; ++PI) {
- if (!PathExists(*PI))
- continue;
+ IsValid = true;
+ for (unsigned i = 0; i < llvm::array_lengthof(GccVersions); ++i) {
+ for (unsigned j = 0, je = CandidateTriples.size(); j < je; ++j) {
+ GccTriple = CandidateTriples[j];
+ for (unsigned k = 0, ke = CandidateLibDirs.size(); k < ke; ++k) {
+ const std::string LibDir = CandidateLibDirs[k].str() + "/";
+ for (unsigned l = 0, le = Prefixes.size(); l < le; ++l) {
+ if (!PathExists(Prefixes[l]))
+ continue;
- // First finds the 'prefix' which exists beneath the system root. Second,
- // finds the first triple which exists beneath that prefix.
- StringRef DetectedGccPrefix, DetectedGccTriple;
- for (unsigned i = 0, ie = CandidateLibDirs.size(); i < ie; ++i) {
- const std::string LibDir = *PI + CandidateLibDirs[i].str();
- if (!PathExists(LibDir))
- continue;
-
- for (unsigned j = 0, je = CandidateTriples.size(); j < je; ++j) {
- GccTriple = CandidateTriples[j];
- const std::string TripleDir = LibDir + "/" + GccTriple;
- if (!PathExists(TripleDir))
- continue;
-
- for (unsigned k = 0; k < llvm::array_lengthof(GccVersions); ++k) {
- GccInstallPath = TripleDir + "/" + GccVersions[k];
+ const std::string TripleDir = Prefixes[l] + LibDir + GccTriple;
+ GccInstallPath = TripleDir + "/" + GccVersions[i];
GccParentLibPath = GccInstallPath + "/../../..";
if (PathExists(GccInstallPath + "/crtbegin.o"))
return;
// Try an install directory with an extra triple in it.
GccInstallPath =
- TripleDir + "/gcc/" + GccTriple + "/" + GccVersions[k];
+ TripleDir + "/gcc/" + GccTriple + "/" + GccVersions[i];
GccParentLibPath = GccInstallPath + "/../../../..";
if (PathExists(GccInstallPath + "/crtbegin.o"))
return;
@@ -1660,7 +1643,7 @@ public:
// Ubuntu 11.04 uses an unusual path.
GccInstallPath =
- TripleDir + "/gcc/i686-linux-gnu/" + GccVersions[k];
+ TripleDir + "/gcc/i686-linux-gnu/" + GccVersions[i];
GccParentLibPath = GccInstallPath + "/../../../..";
if (PathExists(GccInstallPath + "/crtbegin.o"))
return;