-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lld][ELF] --relocatable library search prefers shared objects over archives leading to errors #94958
Labels
Comments
This was referenced Jun 10, 2024
@llvm/issue-subscribers-lld-elf Author: Reno Dakota (paparodeo)
on linux with llvm-17 (tho source looks the same in main)
```
$ lld -r test.o -o test -L./libs -ltest
lld: error: attempted static link of dynamic object ./libs/libtest.so
```
fails when both `libtest.a` and `libtest.so` exist
the following patch fixes the search path: diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp
index ac7460440..7a180bad9 100644
--- a/lld/ELF/DriverUtils.cpp
+++ b/lld/ELF/DriverUtils.cpp
@@ -234,7 +234,7 @@ std::optional<std::string> elf::findFromSearchPaths(StringRef path) {
// search paths.
std::optional<std::string> elf::searchLibraryBaseName(StringRef name) {
for (StringRef dir : config->searchPaths) {
- if (!config->isStatic)
+ if (!(config->isStatic || config->relocatable))
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".so"))
return s;
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".a")) test: $ mkdir libs
$ echo void empty(void) { } > test.c
$ clang test.c -c
$ ar rc libs/libtest.a test.o
# this works
$ lld -r test.o -o test -L./libs -ltest
# but create a shared lib
clang test.c --shared -o libs/libtest.so
# this fails without patch
$ lld -r test.o -o test -L./libs -ltest
lld: error: attempted static link of dynamic object ./libs/libtest.so
# succeeds with patch
$ lld -r test.o -o test -L./libs -ltest |
The patch looks good, but it needs a test |
thanks @MaskRay! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on linux with llvm-17 (tho source looks the same in main)
fails when both
libtest.a
andlibtest.so
existthe following patch aligns the search path behavior to that of GNU ld:
The text was updated successfully, but these errors were encountered: