[Bug ld/18992] New: Linking a library implicitly using relative DT_RPATH does not work
https://sourceware.org/bugzilla/show_bug.cgi?id=18992 Bug ID: 18992 Summary: Linking a library implicitly using relative DT_RPATH does not work Product: binutils Version: 2.24 Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: sourceware-bugzilla at jbeekman dot nl Target Milestone: --- I have a shared library ./dir/liba.so and a shared library ./libb.so with DT_RPATH "dir" and DT_NEEDED "liba.so". Now, if I compile an executable with -L. -lb, I get: "warning: liba.so, needed by ./libb.so, not found (try using -rpath or -rpath-link)". It works when using an absolute DT_RPATH or when using gold. The resulting binary works with a relative RPATH. Here's a test case: ===> a.c <=== void a() {} ===> b.c <=== extern void a(); void b() {a();} ===> main.c <=== extern void b(); void main() {b();} $ mkdir dir $ gcc -fPIC -shared a.c -o dir/liba.so # Make libb with relative RPATH $ gcc -fPIC -shared -Ldir -Wl,-rpath,dir b.c -la -o libb.so # Fail linking in relative-RPATH libb with ld.bfd $ gcc main.c -L. -Wl,-rpath,. -lb -o main /usr/bin/ld.bfd.real: warning: liba.so, needed by ./libb.so, not found (try using -rpath or -rpath-link) ./libb.so: undefined reference to `a' collect2: error: ld returned 1 exit status # Succeed linking in relative-RPATH libb with gold $ gcc main.c -fuse-ld=gold -L. -Wl,-rpath,. -lb -o main # Run binary with relative-RPATH libb $ ./main # Make libb with absolute RPATH $ gcc -fPIC -shared -Ldir -Wl,-rpath,$(pwd)/dir b.c -la -o libb.so # Succeed linking in absolute-RPATH libb with ld.bfd $ gcc main.c -L. -Wl,-rpath,. -lb -o main # Run binary with absolute-RPATH libb $ ./main # Make libb with relative RPATH $ gcc -fPIC -shared -Ldir -Wl,-rpath,dir b.c -la -o libb.so # Run binary with relative-RPATH libb $ ./main -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/18992] Linking a library implicitly using relative DT_RPATH does not work
https://sourceware.org/bugzilla/show_bug.cgi?id=18992 Jonathan Wakely changed: What|Removed |Added CC||jwakely.gcc at gmail dot com --- Comment #1 from Jonathan Wakely --- (In reply to Jethro Beekman from comment #0) > $ gcc main.c -L. -Wl,-rpath,. -lb -o main > /usr/bin/ld.bfd.real: warning: liba.so, needed by ./libb.so, not found (try > using -rpath or -rpath-link) > ./libb.so: undefined reference to `a' > collect2: error: ld returned 1 exit status I asked the reporter to file this bug, but I've just tried it with binutils-2.25-9.fc22.x86_64 and don't see this warning. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/18992] Linking a library implicitly using relative DT_RPATH does not work
https://sourceware.org/bugzilla/show_bug.cgi?id=18992 Jethro Beekman changed: What|Removed |Added Status|NEW |UNCONFIRMED Ever confirmed|1 |0 --- Comment #2 from Jethro Beekman --- I tried this on a variety of OS'es, including various versions of Debian, Ubuntu, RHEL and SunOS and so far I can only reproduce this on Ubuntu 14.04. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/18992] Linking a library implicitly using relative DT_RPATH does not work
https://sourceware.org/bugzilla/show_bug.cgi?id=18992 Mike Frysinger changed: What|Removed |Added CC||vapier at gentoo dot org --- Comment #3 from Mike Frysinger --- are you using gold there ? compare `ld --version | head -1`. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/18992] Linking a library implicitly using relative DT_RPATH does not work
https://sourceware.org/bugzilla/show_bug.cgi?id=18992 Alan Modra changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2015-09-23 CC||amodra at gmail dot com Ever confirmed|0 |1 --- Comment #4 from Alan Modra --- This will be because your linker is configured with a sysroot, and is prepending the sysroot to relative paths. I'm guessing --with-sysroot=/ -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/18992] Linking a library implicitly using relative DT_RPATH does not work
https://sourceware.org/bugzilla/show_bug.cgi?id=18992 --- Comment #5 from Jethro Beekman --- This indeed seems to be the case. In particular, on Ubuntu 14.04, this patch is not applied: http://apt-browse.org/browse/debian/wheezy/main/all/binutils-source/2.22-8/file/usr/src/binutils/patches/158_ld_system_root.patch . It is applied on all other versions of Debian/Ubuntu I have tested. On all these OS'es, the linker is invoked with --sysroot=/ but it only has any effect on Ubuntu 14.04, and from the strace log I can indeed see that the linker tries to access /dir/liba.so. I don't think the sysroot should be prepended to relative paths. Here's a patch to fix: diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index 682f5e5..a70b138 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -1282,9 +1282,12 @@ fragmentname); + char *tmpname = NULL, *name; + if (rp->name[0] == '/') + tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name); + name = tmpname ? tmpname : rp->name; found = (rp->by == l->by - && gld${EMULATION_NAME}_search_needed (tmpname, + && gld${EMULATION_NAME}_search_needed (name, &n, force)); free (tmpname); -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils