This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - -rpath-link "implemented"
ClosedPublic

Authored by grimar on Mar 18 2016, 8:52 AM.

Details

Summary

I think we can just ingnore the "-rpath-link" option. And that can be considered as expected implementation.
My arguments for that below.

Consider we have following sources:

shared2.cpp:

int B() {
 return 0;
}

shared.cpp:

int B();
int A() { 
 return B();
}

main.cpp:

int A();
int main() {
 return A();
}
  1. If I link this using bfd (from path /home/umb/tests/59rpath), I get an error:

/home/umb/LLVM/build/bin/clang -shared -fuse-ld=bfd -fPIC shared2.cpp -o shared2.so
/home/umb/LLVM/build/bin/clang -shared -fuse-ld=bfd -fPIC shared.cpp shared2.so -o shared.so
/home/umb/LLVM/build/bin/clang -fuse-ld=bfd main.cpp shared.so -o test

++ /home/umb/LLVM/build/bin/clang -fuse-ld=bfd main.cpp shared.so -o test
/usr/local/bin/ld.bfd: warning: ./shared/shared2.so, needed by shared.so, not found (try using -rpath or -rpath-link)
shared.so: undefined reference to `B()'
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)

  1. When I add the -rpath-link to commandline, it links fine as expected:

/home/umb/LLVM/build/bin/clang -shared -fuse-ld=bfd -fPIC shared2.cpp -o shared2.so
/home/umb/LLVM/build/bin/clang -shared -fuse-ld=bfd -fPIC shared.cpp shared2.so -o shared.so
/home/umb/LLVM/build/bin/clang -fuse-ld=bfd main.cpp shared.so -o test -Wl,-rpath-link,/home/umb/tests/59rpath
<no errors here>

  1. But at the same time if I link the same using gold then with or without -rpath-link, it is also fine for me.

/home/umb/LLVM/build/bin/clang -shared -fuse-ld=gold -fPIC shared2.cpp -o shared2.so
/home/umb/LLVM/build/bin/clang -shared -fuse-ld=gold -fPIC shared.cpp shared2.so -o shared.so
/home/umb/LLVM/build/bin/clang -fuse-ld=gold main.cpp shared.so -o test
<no errors here>
/home/umb/LLVM/build/bin/clang -shared -fuse-ld=gold -fPIC shared2.cpp -o shared2.so
/home/umb/LLVM/build/bin/clang -shared -fuse-ld=gold -fPIC shared.cpp shared2.so -o shared.so
/home/umb/LLVM/build/bin/clang -fuse-ld=gold main.cpp shared.so -o test -Wl,-rpath-link,/home/umb/tests/59rpath
<no errors here>

So I think we can ignore that in the same way as gold do. And that is 'natural' support in lld. I mean 'natural' is that we do not change anything
to have the same behavior.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 51028.Mar 18 2016, 8:52 AM
grimar retitled this revision from to [ELF] - -rpath-link "implemented".
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar updated this object.Mar 18 2016, 11:48 PM
ruiu edited edge metadata.Mar 19 2016, 3:16 AM

I agree with your argument that we should ignore that option. gold completely ignores that option, and the GNU ld's behavior to try to resolve undefined symbols in all shared object files at (static-)link time seems broken to me.

I don't think you need a test for this. Intended behavior of this patch is ignoring that option and it is trivially achieved by your change.

ELF/Options.td
190 ↗(On Diff #51028)

I think both -rpath-link and --rpath-link are valid.

grimar updated this revision to Diff 51110.Mar 19 2016, 4:13 AM
grimar edited edge metadata.
  • Addressed review comments.

Patch reduced to trivial single line, that just ignores the option.

ELF/Options.td
190 ↗(On Diff #51028)

Agree.
gold accepts both, ld only -rpath-link.
I think we dont miss anything if will either suport both variants.

This revision was automatically updated to reflect the committed changes.