[PATCH] D118498: [ELF] Don't consider directories of the same name as libraries
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 28 11:18:28 PST 2022
phosek created this revision.
phosek added a reviewer: MaskRay.
Herald added subscribers: arichardson, emaste.
phosek requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When processing dependent libraries, if there's a directory of the same
name as the library being searched for, either in the current directory
or earlier in the search order, LLD will try to open it and report an
error. This is because LLD uses file existence check. To address this
issue we reverse the order, searching the library by basename first
and only considering search paths later.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118498
Files:
lld/ELF/InputFiles.cpp
lld/test/ELF/deplibs.s
Index: lld/test/ELF/deplibs.s
===================================================================
--- lld/test/ELF/deplibs.s
+++ lld/test/ELF/deplibs.s
@@ -35,23 +35,24 @@
# CMDLINE-NEXT: {{^libcmdline\.a}}
## LLD tries to resolve dependent library specifiers in the following order:
-## 1) The literal name in the current working directory.
-## 2) The literal name in a library search path.
-## 3) The name, prefixed with "lib" and suffixed with ".so" or ".a" in a
+## 1) The name, prefixed with "lib" and suffixed with ".so" or ".a" in a
## library search path. This means that a directive of "foo.a" could lead
## to a library named "libfoo.a.a" being linked in.
+## 2) The literal name in a library search path.
+## 3) The literal name in the current working directory.
## When using library search paths for dependent libraries, LLD follows the same
## rules as for libraries specified on the command line.
# RUN: cp %t.dir/foo.a %t.cwd/foo.a
# RUN: cp %t.dir/foo.a %t.dir/libfoo.a.a
+
# RUN: ld.lld %t.o -o /dev/null -L %t.dir --trace 2>&1 | \
-# RUN: FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=CWD \
+# RUN: FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=LIBA-DIR \
# RUN: --implicit-check-not=foo.a --implicit-check-not=libbar.so
-# CWD: [[OBJ]]
-# CWD-NEXT: {{^foo\.a}}
+# LIBA-DIR: [[OBJ]]
+# LIBA-DIR-NEXT: [[DIR]]{{[\\/]}}libfoo.a.a
-# RUN: rm %t.cwd/foo.a
+# RUN: rm %t.dir/libfoo.a.a
# RUN: ld.lld %t.o -o /dev/null -L %t.dir --trace 2>&1 | \
# RUN: FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=PLAIN-DIR \
# RUN: --implicit-check-not=foo.a --implicit-check-not=libbar.so
@@ -61,11 +62,11 @@
# RUN: rm %t.dir/foo.a
# RUN: ld.lld %t.o -o /dev/null -L %t.dir --trace 2>&1 | \
-# RUN: FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=LIBA-DIR \
+# RUN: FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=CWD \
# RUN: --implicit-check-not=foo.a --implicit-check-not=libbar.so
-# LIBA-DIR: [[OBJ]]
-# LIBA-DIR-NEXT: [[DIR]]{{[\\/]}}libfoo.a.a
+# CWD: [[OBJ]]
+# CWD-NEXT: {{^foo\.a}}
call foo
.section ".deplibs","MS", at llvm_dependent_libraries,1
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -490,12 +490,12 @@
static void addDependentLibrary(StringRef specifier, const InputFile *f) {
if (!config->dependentLibraries)
return;
- if (fs::exists(specifier))
- driver->addFile(specifier, /*withLOption=*/false);
- else if (Optional<std::string> s = findFromSearchPaths(specifier))
+ if (Optional<std::string> s = searchLibraryBaseName(specifier))
driver->addFile(*s, /*withLOption=*/true);
- else if (Optional<std::string> s = searchLibraryBaseName(specifier))
+ else if (Optional<std::string> s = findFromSearchPaths(specifier))
driver->addFile(*s, /*withLOption=*/true);
+ else if (fs::exists(specifier))
+ driver->addFile(specifier, /*withLOption=*/false);
else
error(toString(f) +
": unable to find library from dependent library specifier: " +
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118498.404101.patch
Type: text/x-patch
Size: 3170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220128/c32f2df8/attachment.bin>
More information about the llvm-commits
mailing list