[cfe-commits] r140995 - in /cfe/trunk: lib/Driver/ test/Driver/ test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/ test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/ test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0/ test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/ test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/4.6.0/

Chandler Carruth chandlerc at gmail.com
Mon Oct 3 01:02:58 PDT 2011


Author: chandlerc
Date: Mon Oct  3 03:02:58 2011
New Revision: 140995

URL: http://llvm.org/viewvc/llvm-project?rev=140995&view=rev
Log:
Teach the logic for locating an installed GCC about the system root.
This requires fixing a latent bug -- if we used the default host triple
instead of an autodetected triple to locate GCC's installation, we
didn't go back and fix the GCC triple. Correct that with a pile of
hacks. This entire routine needs a major refactoring which I'm saving
for a subsequent commit. Essentially, the detection of the GCC triple
should be hoisted into the same routine as we locate the GCC
installation: the first is intrinsically tied to the latter. Then the
routine will just return the triple and base directory.

Also start to bring the rest of the library search path logic under
test, including locating crtbegin.o. Still need to test the multilib and
other behaviors, but there are also bugs in the way of that.

Added:
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0/crtbegin.o
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/4.6.0/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/4.6.0/crtbegin.o
Modified:
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/test/Driver/linux-ld.c

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=140995&r1=140994&r2=140995&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Oct  3 03:02:58 2011
@@ -1483,8 +1483,12 @@
   return UnknownDistro;
 }
 
-static std::string findGCCBaseLibDir(const Driver &D,
-    const std::string &GccTriple) {
+/// \brief Find an installed GCC lib base directory.
+///
+/// Tries both the auto-detected GccTriple passed in as well as the
+/// Driver-specified default host triple. Sets the GccTriple to the triple
+/// actually used.
+static std::string findGCCBaseLibDir(const Driver &D, std::string &GccTriple) {
   // FIXME: Using CXX_INCLUDE_ROOT is here is a bit of a hack, but
   // avoids adding yet another option to configure/cmake.
   // It would probably be cleaner to break it in two variables
@@ -1519,13 +1523,14 @@
   bool Exists;
   llvm::SmallVector<std::string, 8> Paths(D.PrefixDirs.begin(),
       D.PrefixDirs.end());
-  Paths.push_back("/usr/");
-  const std::string *Triples[] = {&GccTriple, &D.DefaultHostTriple};
+  Paths.push_back(D.SysRoot + "/usr/");
+  const std::string Triples[] = {GccTriple, D.DefaultHostTriple};
   for (llvm::SmallVector<std::string, 8>::const_iterator it = Paths.begin(),
        ie = Paths.end(); it != ie; ++it) {
     for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) {
       for (unsigned j = 0; j < sizeof(Triples)/sizeof(Triples[0]); ++j) {
-        std::string Suffix = *Triples[j] + "/" + GccVersions[i];
+        GccTriple = Triples[j];
+        std::string Suffix = Triples[j] + "/" + GccVersions[i];
         std::string t1 = *it + "lib/gcc/" + Suffix;
         if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists)
           return t1;
@@ -1546,6 +1551,7 @@
       }
     }
   }
+  GccTriple.clear();
   return "";
 }
 
@@ -1710,7 +1716,7 @@
 
   // Add the non-multiplib suffixed paths (if potentially different).
   if (!Base.empty() && !GccTriple.empty()) {
-    if (!Suffix.empty())
+    if (!Suffix.empty() || !HasMultilib(Arch, Distro))
       addPathIfExists(Base, Paths);
     addPathIfExists(Base + "/../../../../" + GccTriple + "/lib", Paths);
     addPathIfExists(Base + "/../../..", Paths);

Added: cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0/crtbegin.o
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0/crtbegin.o?rev=140995&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/4.6.0/crtbegin.o
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/4.6.0/crtbegin.o?rev=140995&view=auto
==============================================================================
    (empty)

Modified: cfe/trunk/test/Driver/linux-ld.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-ld.c?rev=140995&r1=140994&r2=140995&view=diff
==============================================================================
--- cfe/trunk/test/Driver/linux-ld.c (original)
+++ cfe/trunk/test/Driver/linux-ld.c Mon Oct  3 03:02:58 2011
@@ -2,15 +2,23 @@
 // sysroot to make these tests independent of the host system.
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN:     -ccc-host-triple i386-unkown-linux \
+// RUN:     -ccc-host-triple i386-unknown-linux \
 // RUN:     --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-32 %s
 // CHECK-LD-32: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-LD-32: {{.*}} "-L[[SYSROOT]]/lib" "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-32: "[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/crtbegin.o"
+// CHECK-LD-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0"
+// CHECK-LD-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../.."
+// CHECK-LD-32: "-L[[SYSROOT]]/lib"
+// CHECK-LD-32: "-L[[SYSROOT]]/usr/lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     -ccc-host-triple x86_64-unknown-linux \
 // RUN:     --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-64 %s
 // CHECK-LD-64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-LD-64: {{.*}} "-L[[SYSROOT]]/lib" "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD-64: "[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/crtbegin.o"
+// CHECK-LD-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0"
+// CHECK-LD-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../.."
+// CHECK-LD-64: "-L[[SYSROOT]]/lib"
+// CHECK-LD-64: "-L[[SYSROOT]]/usr/lib"





More information about the cfe-commits mailing list