Skip to content

[LLD][ELF] ignore ".so" in search path when relocatable set #94965

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

Closed
wants to merge 1 commit into from
Closed

[LLD][ELF] ignore ".so" in search path when relocatable set #94965

wants to merge 1 commit into from

Conversation

paparodeo
Copy link
Contributor

@paparodeo paparodeo commented Jun 10, 2024

closes: #94958

fixes:

$ lld -r test.o -o test -L./libs -ltest
lld: error: attempted static link of dynamic object ./libs/libtest.so

when both libtest.a and libtest.so exist in the search path

test:

mkdir libs
echo void empty(void) { } > test.c
clang test.c -c
clang test.c --shared -o libs/libtest.so
ar rc libs/libtest.a test.o
lld -r test.o -o test -L./libs -ltest

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2024

@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld

Author: Reno Dakota (paparodeo)

Changes

closes: #94958

fixes:

$ lld -r test.o -o test -L./libs -ltest
lld: error: attempted static link of dynamic object ./libs/libtest.so

when both libtest.a and libtest.so exist in the search path

test:

echo void empty(void) { } > test.c
clang test.c -c
ar rc libs/libtest.a test.o
clang test.c --shared -o libs/libtest.so
lld -r test.o -o test -L./libs -ltest

Full diff: https://github.com/llvm/llvm-project/pull/94965.diff

1 Files Affected:

  • (modified) lld/ELF/DriverUtils.cpp (+1-1)
diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp
index ac74604408152..77214aa362459 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"))

@paparodeo paparodeo changed the title [LLD][ELF] ignore ".so" when relocatable set [LLD][ELF] ignore ".so" in search path when relocatable set Jun 14, 2024
fixes:
```
$ lld -r test.o -o test -L./libs -ltest
lld: error: attempted static link of dynamic object ./libs/libtest.so
```

when both libtest.a and libtest.so exist in the search path

test:
```
echo void empty(void) { } > test.c
clang test.c -c
ar rc libs/libtest.a test.o
clang test.c --shared -o libs/libtest.so
lld -r test.o -o test -L./libs -ltest
```
@MaskRay
Copy link
Member

MaskRay commented Jun 14, 2024

You need to turn off the hidden email for your contribution to be accepted
https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it/74223

The word after the tags ("[LLD][ELF]") are usually capitalized. "Ignore "

I'd not use "fixes". I'd say that GNU ld does XXXX and we decide to follow suite.
I don't think there is any bug involved here. It's just some behavior difference that we don't have a strong opinion on.
The current lld behavior is like gold.

@paparodeo paparodeo closed this Jun 14, 2024
@paparodeo paparodeo deleted the lld-relocatable-ignore-so branch June 14, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lld][ELF] --relocatable library search prefers shared objects over archives leading to errors
3 participants