[PATCH] D18269: [ELF] - -rpath-link "implemented"

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 08:52:55 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

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();
}
```

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)

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>

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=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
<no errors here>
/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>

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.

http://reviews.llvm.org/D18269

Files:
  ELF/Options.td
  test/ELF/Inputs/rpath-link.s
  test/ELF/Inputs/rpath-link2.s
  test/ELF/rpath-link.s

Index: test/ELF/rpath-link.s
===================================================================
--- test/ELF/rpath-link.s
+++ test/ELF/rpath-link.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/rpath-link.s -o %tlink1.o
+# RUN: ld.lld -shared %tlink1.o -o %tlink1.so
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/rpath-link2.s -o %tlink2.o
+# RUN: ld.lld -shared %tlink2.o %tlink1.so -o %tlink2.so
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t %tlink1.so -o %t.out
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t %tlink1.so -o %t.out -rpath-link write_whatever_you_want_here
+
+.text
+.globl _start
+_start:
+  callq _Z1Av
Index: test/ELF/Inputs/rpath-link2.s
===================================================================
--- test/ELF/Inputs/rpath-link2.s
+++ test/ELF/Inputs/rpath-link2.s
@@ -0,0 +1,5 @@
+.text
+.globl _Z1Bv
+.type _Z1Bv, at function
+_Z1Bv:
+ retq
Index: test/ELF/Inputs/rpath-link.s
===================================================================
--- test/ELF/Inputs/rpath-link.s
+++ test/ELF/Inputs/rpath-link.s
@@ -0,0 +1,5 @@
+.text
+.globl _Z1Av
+.type _Z1Av, at function
+_Z1Av:
+  callq _Z1Bv at PLT
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -187,6 +187,7 @@
 def no_fatal_warnings : Flag<["--"], "no-fatal-warnings">;
 def no_warn_common : Flag<["--", "-"], "no-warn-common">;
 def no_warn_mismatch : Flag<["--"], "no-warn-mismatch">;
+def rpath_link : Separate<["-"], "rpath-link">;
 def version_script : Separate<["--"], "version-script">;
 def warn_shared_textrel : Flag<["--"], "warn-shared-textrel">;
 def G : Separate<["-"], "G">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18269.51028.patch
Type: text/x-patch
Size: 1822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160318/15580a5c/attachment.bin>


More information about the llvm-commits mailing list