diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-06-27 07:26:28 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-06-27 07:26:28 +0000 |
| commit | 20d8d55b052c1067070b5ca83821c74b01952414 (patch) | |
| tree | 2231b31ab6b25a257101e120084dc946cb71e8cc | |
| parent | 7357849dca66796b1f5c454cda010e8d2ef55fd6 (diff) | |
| download | bcm5719-llvm-20d8d55b052c1067070b5ca83821c74b01952414.tar.gz bcm5719-llvm-20d8d55b052c1067070b5ca83821c74b01952414.zip | |
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.
llvm-svn: 273846
| -rw-r--r-- | lld/ELF/DriverUtils.cpp | 13 | ||||
| -rw-r--r-- | lld/test/ELF/libsearch.s | 6 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index 4c3bd813c2b..c32429e900f 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -244,12 +244,17 @@ std::string elf::findFromSearchPaths(StringRef Path) { 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. diff --git a/lld/test/ELF/libsearch.s b/lld/test/ELF/libsearch.s index 75ad0fb43aa..782d755f734 100644 --- a/lld/test/ELF/libsearch.s +++ b/lld/test/ELF/libsearch.s @@ -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 |

