[PATCH] Honor executables DT_RUNPATH for dlopen
Jakub Jelinek
jakub@redhat.com
Thu Oct 10 23:42:00 GMT 2002
Hi!
echo 'void f () {}' | gcc -fpic -shared -xc - -o libbar.so
gcc -Wl,-rpath,.,--enable-new-dtags -xc - -ldl -o bar <<"EOF"
#include <dlfcn.h>
int main () {
void *p = dlopen ("libbar.so", RTLD_NOW);
if (!p)
puts (dlerror ());
return !p;
}
EOF
./bar
test fails, because for dlopen DT_RUNPATH of the executable is not searched.
Unfortunately the patch does a bunch of tests in the common path, maybe
it should be reordered to check l->l_runpath_dirs.dirs != -1 right before
l->l_type != lt_loaded test.
2002-10-10 Jakub Jelinek <jakub@redhat.com>
* elf/dl-load.c (_dl_map_object): Use DT_RUNPATH of the executable
for dlopen searches.
--- libc/elf/dl-load.c.jj 2002-10-10 13:57:28.000000000 +0200
+++ libc/elf/dl-load.c 2002-10-10 13:59:20.000000000 +0200
@@ -1751,6 +1751,14 @@ _dl_map_object (struct link_map *loader,
break;
}
+ /* If dynamically linked, try the DT_RUNPATH of the executable
+ itself. */
+ l = GL(dl_loaded);
+ if (fd == -1 && l && l->l_type != lt_loaded && l != loader
+ && l->l_runpath_dirs.dirs != (void *) -1)
+ fd = open_path (name, namelen, preloaded, &l->l_runpath_dirs,
+ &realname, &fb);
+
if (fd == -1
&& (__builtin_expect (! preloaded, 1)
|| ! INTUSE(__libc_enable_secure)))
Jakub
More information about the Libc-hacker
mailing list