[cfe-commits] r140990 - in /cfe/trunk: lib/Driver/ToolChains.cpp test/Driver/Inputs/ test/Driver/Inputs/basic_linux_tree/ test/Driver/Inputs/basic_linux_tree/lib/ test/Driver/Inputs/basic_linux_tree/lib/.keep test/Driver/Inputs/basic_linux_tree/usr/ test/Driver/Inputs/basic_linux_tree/usr/lib/ test/Driver/Inputs/basic_linux_tree/usr/lib/.keep test/Driver/linux-ld.c

Chandler Carruth chandlerc at gmail.com
Sun Oct 2 23:41:08 PDT 2011


Author: chandlerc
Date: Mon Oct  3 01:41:08 2011
New Revision: 140990

URL: http://llvm.org/viewvc/llvm-project?rev=140990&view=rev
Log:
Add initial support for applying the sysroot to library search paths.
This is still very much a WIP, but sysroot was completely broken before
this so we are moving closer to correctness.

The crux of this is that 'ld' (on Linux, the only place I'm touching
here) doesn't apply the sysroot to any flags given to it. Instead, the
driver must translate all the paths it adds to the link step with the
system root. This is easily observed by building a GCC that supports
sysroot, and checking its driver output.

This patch just fixes the non-multilib library search paths. We should
also use this in many other places, but first things first.

This also allows us to make the Linux 'ld' test independent of the host
system. This in turn will allow me to check in test tree configurations
based on various different distro's configuration. Again, WIP.

Added:
    cfe/trunk/test/Driver/Inputs/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/lib/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/lib/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/
    cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/.keep
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=140990&r1=140989&r2=140990&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Oct  3 01:41:08 2011
@@ -1560,6 +1560,7 @@
   : Generic_ELF(Host, Triple) {
   llvm::Triple::ArchType Arch =
     llvm::Triple(getDriver().DefaultHostTriple).getArch();
+  const std::string &SysRoot = getDriver().SysRoot;
 
   bool Exists;
   std::string GccTriple = "";
@@ -1703,8 +1704,8 @@
                       Multilib, Paths);
       addPathIfExists(Base + "/../../../../" + Multilib, Paths);
     }
-    addPathIfExists("/lib/../" + Multilib, Paths);
-    addPathIfExists("/usr/lib/../" + Multilib, Paths);
+    addPathIfExists(SysRoot + "/lib/../" + Multilib, Paths);
+    addPathIfExists(SysRoot + "/usr/lib/../" + Multilib, Paths);
   }
 
   // Add the non-multiplib suffixed paths (if potentially different).
@@ -1714,11 +1715,11 @@
     addPathIfExists(Base + "/../../../../" + GccTriple + "/lib", Paths);
     addPathIfExists(Base + "/../../..", Paths);
   }
-  addPathIfExists("/lib", Paths);
-  addPathIfExists("/usr/lib", Paths);
+  addPathIfExists(SysRoot + "/lib", Paths);
+  addPathIfExists(SysRoot + "/usr/lib", Paths);
 
   if (Arch == getArch() && IsUbuntu(Distro))
-    Paths.push_back("/usr/lib/" + GccTriple);
+    Paths.push_back(SysRoot + "/usr/lib/" + GccTriple);
 }
 
 bool Linux::HasNativeLLVMSupport() const {

Added: cfe/trunk/test/Driver/Inputs/basic_linux_tree/lib/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_tree/lib/.keep?rev=140990&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_tree/usr/lib/.keep?rev=140990&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=140990&r1=140989&r2=140990&view=diff
==============================================================================
--- cfe/trunk/test/Driver/linux-ld.c (original)
+++ cfe/trunk/test/Driver/linux-ld.c Mon Oct  3 01:41:08 2011
@@ -1,9 +1,16 @@
-// General tests that ld invocations on Linux targets sane.
+// General tests that ld invocations on Linux targets sane. Note that we use
+// sysroot to make these tests independent of the host system.
 //
-// RUN: %clang -no-canonical-prefixes -ccc-host-triple i386-unknown-linux %s -### -o %t.o 2>&1 \
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -ccc-host-triple i386-unkown-linux \
+// RUN:     --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-32 %s
-// CHECK-LD-32: "{{.*}}ld{{(.exe)?}}" {{.*}} "-L/lib" "-L/usr/lib"
+// CHECK-LD-32: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-LD-32: {{.*}} "-L[[SYSROOT]]/lib" "-L[[SYSROOT]]/usr/lib"
 //
-// RUN: %clang -no-canonical-prefixes -ccc-host-triple x86_64-unknown-linux %s -### -o %t.o 2>&1 \
+// 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)?}}" {{.*}} "-L/lib" "-L/usr/lib"
+// CHECK-LD-64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-LD-64: {{.*}} "-L[[SYSROOT]]/lib" "-L[[SYSROOT]]/usr/lib"





More information about the cfe-commits mailing list