[lld] r273846 - Fix library search order.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 27 00:26:28 PDT 2016
Author: ruiu
Date: Mon Jun 27 02:26:28 2016
New Revision: 273846
URL: http://llvm.org/viewvc/llvm-project?rev=273846&view=rev
Log:
Fix library search order.
Previously, we searched for a .so file from all library paths and
then searched for a .a file. That logic is wrong. What we need to
do is to look for a .so and a .a for each library path.
Modified:
lld/trunk/ELF/DriverUtils.cpp
lld/trunk/test/ELF/libsearch.s
Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=273846&r1=273845&r2=273846&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Mon Jun 27 02:26:28 2016
@@ -244,12 +244,17 @@ std::string elf::findFromSearchPaths(Str
std::string elf::searchLibrary(StringRef Path) {
if (Path.startswith(":"))
return findFromSearchPaths(Path.substr(1));
- if (!Config->Static) {
- std::string S = findFromSearchPaths(("lib" + Path + ".so").str());
- if (!S.empty())
+ for (StringRef Dir : Config->SearchPaths) {
+ if (!Config->Static) {
+ std::string S = buildSysrootedPath(Dir, ("lib" + Path + ".so").str());
+ if (fs::exists(S))
+ return S;
+ }
+ std::string S = buildSysrootedPath(Dir, ("lib" + Path + ".a").str());
+ if (fs::exists(S))
return S;
}
- return findFromSearchPaths(("lib" + Path + ".a").str());
+ return "";
}
// Makes a path by concatenating Dir and File.
Modified: lld/trunk/test/ELF/libsearch.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/libsearch.s?rev=273846&r1=273845&r2=273846&view=diff
==============================================================================
--- lld/trunk/test/ELF/libsearch.s (original)
+++ lld/trunk/test/ELF/libsearch.s Mon Jun 27 02:26:28 2016
@@ -44,6 +44,12 @@
// RUN: ld.lld -o %t3 %t.o -L%t.dir -lls
// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// Check for library search order
+// RUN: mkdir -p %t.dir2
+// RUN: cp %t.dir/libls.a %t.dir2
+// RUN: ld.lld -o %t3 %t.o -L%t.dir2 -L%t.dir -lls
+// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+
// -L can be placed after -l
// RUN: ld.lld -o %t3 %t.o -lls -L%t.dir
More information about the llvm-commits
mailing list