[PATCH] D26244: [Driver] Prefer libraries installed next to Clang over those from GCC

Jonas Hahnfeld via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 10 02:07:47 PST 2017


Hahnfeld updated this revision to Diff 83784.
Hahnfeld added a comment.

Add test case to check that

- `bin/../lib` is the first library path by default
- user-specified `-L` preceeds


https://reviews.llvm.org/D26244

Files:
  lib/Driver/ToolChains.cpp
  test/Driver/clang-libraries.c


Index: test/Driver/clang-libraries.c
===================================================================
--- /dev/null
+++ test/Driver/clang-libraries.c
@@ -0,0 +1,24 @@
+// Check that libraries installed next to Clang are preferred over those from GCC.
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     --target=x86_64-unknown-linux --gcc-toolchain=%S/Inputs/basic_linux_tree/usr \
+// RUN:   | FileCheck --check-prefix=CHECK-DEFAULT %s
+
+// CHECK-DEFAULT: "[[CLANG_BIN:[^"]+]]/clang"
+// CHECK-DEFAULT: "{{.*}}ld{{(.exe)?}}"
+// CHECK-DEFAULT-NOT: "-L
+// CHECK-DEFAULT: "-L[[CLANG_BIN]]/../lib
+
+
+// Check that manual library paths preceed the default ones.
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     --target=x86_64-unknown-linux --gcc-toolchain=%S/Inputs/basic_linux_tree/usr \
+// RUN:     -L%S/Inputs/basic_linux_tree/usr/lib \
+// RUN:   | FileCheck --check-prefix=CHECK-MANUAL %s
+
+// CHECK-MANUAL: "[[CLANG_BIN:[^"]+]]/clang"
+// CHECK-MANUAL: "{{.*}}ld{{(.exe)?}}"
+// CHECK-MANUAL: "-L{{[^"]*}}Inputs/basic_linux_tree/usr/lib
+// CHECK-MANUAL-NOT: "-L
+// CHECK-MANUAL: "-L[[CLANG_BIN]]/../lib
Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4161,6 +4161,17 @@
   const std::string OSLibDir = getOSLibDir(Triple, Args);
   const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
 
+  // Similar to the logic for GCC below, if we currently running Clang inside
+  // of the requested system root, add its parent library paths to those
+  // searched.
+  // FIXME: It's not clear whether we should use the driver's installed
+  // directory ('Dir' below) or the ResourceDir.
+  if (StringRef(D.Dir).startswith(SysRoot)) {
+    addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths);
+    addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
+    addPathIfExists(D, D.Dir + "/../lib", Paths);
+  }
+
   // Add the multilib suffixed paths where they are available.
   if (GCCInstallation.isValid()) {
     const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
@@ -4214,16 +4225,6 @@
     }
   }
 
-  // Similar to the logic for GCC above, if we currently running Clang inside
-  // of the requested system root, add its parent library paths to
-  // those searched.
-  // FIXME: It's not clear whether we should use the driver's installed
-  // directory ('Dir' below) or the ResourceDir.
-  if (StringRef(D.Dir).startswith(SysRoot)) {
-    addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths);
-    addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
-  }
-
   addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
   addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);
   addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
@@ -4260,14 +4261,6 @@
       addPathIfExists(D, LibPath, Paths);
   }
 
-  // Similar to the logic for GCC above, if we are currently running Clang
-  // inside of the requested system root, add its parent library path to those
-  // searched.
-  // FIXME: It's not clear whether we should use the driver's installed
-  // directory ('Dir' below) or the ResourceDir.
-  if (StringRef(D.Dir).startswith(SysRoot))
-    addPathIfExists(D, D.Dir + "/../lib", Paths);
-
   addPathIfExists(D, SysRoot + "/lib", Paths);
   addPathIfExists(D, SysRoot + "/usr/lib", Paths);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26244.83784.patch
Type: text/x-patch
Size: 3469 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170110/873de983/attachment-0001.bin>


More information about the cfe-commits mailing list