public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Honor executables DT_RUNPATH for dlopen
@ 2002-10-10 23:42 Jakub Jelinek
  2002-11-05 20:04 ` Roland McGrath
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2002-10-10 23:42 UTC (permalink / raw)
  To: Roland McGrath, Ulrich Drepper; +Cc: Glibc hackers

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Honor executables DT_RUNPATH for dlopen
  2002-10-10 23:42 [PATCH] Honor executables DT_RUNPATH for dlopen Jakub Jelinek
@ 2002-11-05 20:04 ` Roland McGrath
  0 siblings, 0 replies; 2+ messages in thread
From: Roland McGrath @ 2002-11-05 20:04 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers

That change is not correct.  The ELF spec says that DT_RUNPATH applies to
"only the immediate dependencies of the executable or shared object
containing the DT_RUNPATH entry."  I'm not aware of anything that specifies
dlopen in enough detail that it couldn't do whatever it likes.  But it
seems consistent with the spec for dlopen not to be affected by any
DT_RUNPATH (except for dependencies being affected by a DT_RUNPATH within a
dlopen'd dependent object).  The application or library can use whatever
prefix it put in its DT_RUNPATH on the strings it passes to dlopen directly.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-11-06  4:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-10 23:42 [PATCH] Honor executables DT_RUNPATH for dlopen Jakub Jelinek
2002-11-05 20:04 ` Roland McGrath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).