http://sourceware.org/bugzilla/show_bug.cgi?id=15096

             Bug #: 15096
           Summary: DT_RPATH != DT_RUNPATH
           Product: binutils
           Version: 2.24 (HEAD)
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
        AssignedTo: unassig...@sourceware.org
        ReportedBy: hjl.to...@gmail.com
    Classification: Unclassified


According to gABI,

The set of directories specified by a given DT_RUNPATH entry is used to
find only the immediate dependencies of the executable or shared object
containing the DT_RUNPATH entry. That is, it is used only for those
dependencies contained in the DT_NEEDED entries of the dynamic structure
containing the DT_RUNPATH entry, itself. One object's DT_RUNPATH entry
does not affect the search for any other object's dependencies.

That means DT_RUNPATH on executable doesn't apply to shared objects
which executable depends on:

[hjl@gnu-6 runpath]$ cat foo.c
#include <dlfcn.h>

int
main ()
{
  void* handle = dlopen("libso1.so", RTLD_LAZY);
  typedef int (*hello_t)();
  hello_t hello1 = (hello_t)dlsym(handle, "hello1");
  hello1();
  return 0;
}
[hjl@gnu-6 runpath]$ cat so1.c
extern void hello2 (void);

void 
hello1 (void)
{
  hello2();
}
[hjl@gnu-6 runpath]$ cat so2.c
#include <stdio.h>

void
hello2 ()
{
  printf ("hello\n");
}
[hjl@gnu-6 runpath]$ make
gcc -fPIC -O2 -shared -o libso2.so so2.c
gcc -fPIC -O2 -shared -o libso1.so so1.c libso2.so
gcc -o foo1 foo.c libso1.so -Wl,-rpath,. -ldl
gcc -B./ -o foo2 foo.c libso1.so -Wl,-rpath,. -ldl
readelf -d foo1

Dynamic section at offset 0x8b0 contains 27 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libso1.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000f (RPATH)              Library rpath: [.]
 0x000000000000000c (INIT)               0x400558
 0x000000000000000d (FINI)               0x400794
 0x0000000000000019 (INIT_ARRAY)         0x600898
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x6008a0
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x400260
 0x0000000000000005 (STRTAB)             0x4003d0
 0x0000000000000006 (SYMTAB)             0x400298
 0x000000000000000a (STRSZ)              202 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x600ab8
 0x0000000000000002 (PLTRELSZ)           72 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x400510
 0x0000000000000007 (RELA)               0x4004f8
 0x0000000000000008 (RELASZ)             24 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x4004b8
 0x000000006fffffff (VERNEEDNUM)         2
 0x000000006ffffff0 (VERSYM)             0x40049a
 0x0000000000000000 (NULL)               0x0
./foo1
hello
readelf -d foo2

Dynamic section at offset 0x8b0 contains 27 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libso1.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [.]
 0x000000000000000c (INIT)               0x400558
 0x000000000000000d (FINI)               0x400794
 0x0000000000000019 (INIT_ARRAY)         0x600898
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x6008a0
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x400260
 0x0000000000000005 (STRTAB)             0x4003d0
 0x0000000000000006 (SYMTAB)             0x400298
 0x000000000000000a (STRSZ)              202 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x600ab8
 0x0000000000000002 (PLTRELSZ)           72 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x400510
 0x0000000000000007 (RELA)               0x4004f8
 0x0000000000000008 (RELASZ)             24 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x4004b8
 0x000000006fffffff (VERNEEDNUM)         2
 0x000000006ffffff0 (VERSYM)             0x40049a
 0x0000000000000000 (NULL)               0x0
./foo2
./foo2: error while loading shared libraries: libso2.so: cannot open shared
object file: No such file or directory
make: *** [all] Error 127
[hjl@gnu-6 runpath]$

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- 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

Reply via email to