Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ld.elf_so When dlopen()ing with RTLD_GLOBAL, also ma...



details:   https://anonhg.NetBSD.org/src/rev/cfba0729a266
branches:  trunk
changeset: 499088:cfba0729a266
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Fri Nov 10 21:31:30 2000 +0000

description:
When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.

diffstat:

 libexec/ld.elf_so/Makefile |   3 ++-
 libexec/ld.elf_so/load.c   |  26 +++++++++++++++++---------
 libexec/ld.elf_so/rtld.c   |  17 ++++++-----------
 libexec/ld.elf_so/rtld.h   |   8 +++++---
 4 files changed, 30 insertions(+), 24 deletions(-)

diffs (209 lines):

diff -r 2901dd4867ac -r cfba0729a266 libexec/ld.elf_so/Makefile
--- a/libexec/ld.elf_so/Makefile        Fri Nov 10 19:06:17 2000 +0000
+++ b/libexec/ld.elf_so/Makefile        Fri Nov 10 21:31:30 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.33 2000/07/14 22:01:09 matt Exp $
+#      $NetBSD: Makefile,v 1.34 2000/11/10 21:31:30 mycroft Exp $
 
 .include <bsd.own.mk>                  # for OBJECT_FMT definition
 
@@ -31,6 +31,7 @@
 CPPFLAGS+= -D_RTLD_SOURCE
 #CPPFLAGS+= -DRTLD_DEBUG
 #CPPFLAGS+= -DRTLD_DEBUG_RELOC
+#DBG=  -g
 
 LDADD+=        -non_shared -L${DESTDIR}/${LIBDIR} -lc_pic
 DPADD+=        ${LIBC_PIC}
diff -r 2901dd4867ac -r cfba0729a266 libexec/ld.elf_so/load.c
--- a/libexec/ld.elf_so/load.c  Fri Nov 10 19:06:17 2000 +0000
+++ b/libexec/ld.elf_so/load.c  Fri Nov 10 21:31:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: load.c,v 1.11 1999/12/27 15:36:36 christos Exp $        */
+/*     $NetBSD: load.c,v 1.12 2000/11/10 21:31:30 mycroft Exp $         */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -55,7 +55,7 @@
 #include "rtld.h"
 
 static bool _rtld_load_by_name __P((const char *, Obj_Entry *, Needed_Entry **,
-    bool));
+    int, bool));
 
 /*
  * Load a shared object into memory, if it is not already loaded.  The
@@ -66,8 +66,9 @@
  * on failure.
  */
 Obj_Entry *
-_rtld_load_object(filepath, dodebug)
+_rtld_load_object(filepath, mode, dodebug)
        char *filepath;
+       int mode;
        bool dodebug;
 {
        Obj_Entry *obj;
@@ -130,14 +131,18 @@
                free(filepath);
 
        ++obj->refcount;
+       if ((mode & RTLD_GLOBAL) &&
+           _rtld_objlist_find(&_rtld_list_global, obj) == NULL)
+               _rtld_objlist_add(&_rtld_list_global, obj);
        return obj;
 }
 
 static bool
-_rtld_load_by_name(name, obj, needed, dodebug)
+_rtld_load_by_name(name, obj, needed, mode, dodebug)
        const char *name;
        Obj_Entry *obj;
        Needed_Entry **needed;
+       int mode;
        bool dodebug;
 {
        Library_Xform *x = _rtld_xforms;
@@ -202,7 +207,7 @@
                                    x->entry[i].library[j], name);
                                continue;
                        }
-                       o = _rtld_load_object(libpath, true);
+                       o = _rtld_load_object(libpath, mode, true);
                        if (o == NULL)
                                continue;
                        got = true;
@@ -228,7 +233,7 @@
        libpath = _rtld_find_library(name, obj);
        if (libpath == NULL)
                return false;
-       return ((*needed)->obj = _rtld_load_object(libpath, true)) != NULL;
+       return ((*needed)->obj = _rtld_load_object(libpath, mode, true)) != NULL;
 }
 
 
@@ -238,8 +243,9 @@
  * returns -1 on failure.
  */
 int
-_rtld_load_needed_objects(first, dodebug)
+_rtld_load_needed_objects(first, mode, dodebug)
        Obj_Entry *first;
+       int mode;
        bool dodebug;
 {
        Obj_Entry *obj;
@@ -251,7 +257,8 @@
                for (needed = obj->needed; needed != NULL;
                    needed = needed->next) {
                        const char *name = obj->strtab + needed->name;
-                       if (!_rtld_load_by_name(name, obj, &needed, dodebug))
+                       if (!_rtld_load_by_name(name, obj, &needed, mode,
+                           dodebug))
                                status = -1;    /* FIXME - cleanup */
 #ifdef RTLD_LOADER
                        if (status == -1)
@@ -276,7 +283,8 @@
        if (preload_path != NULL) {
                cp = buf = xstrdup(preload_path);
                while ((path = strsep(&cp, " ")) != NULL && status == 0) {
-                       if (_rtld_load_object(xstrdup(path), dodebug) == NULL)
+                       if (_rtld_load_object(xstrdup(path), RTLD_GLOBAL,
+                           dodebug) == NULL)
                                status = -1;
                        else if (dodebug)
                                dbg((" preloaded \"%s\"", path));
diff -r 2901dd4867ac -r cfba0729a266 libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Fri Nov 10 19:06:17 2000 +0000
+++ b/libexec/ld.elf_so/rtld.c  Fri Nov 10 21:31:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.c,v 1.41 2000/08/28 04:15:54 scottb Exp $  */
+/*     $NetBSD: rtld.c,v 1.42 2000/11/10 21:31:30 mycroft Exp $         */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -122,8 +122,6 @@
 static Obj_Entry *_rtld_dlcheck __P((void *));
 static void _rtld_init_dag __P((Obj_Entry *));
 static void _rtld_init_dag1 __P((Obj_Entry *, Obj_Entry *));
-static void _rtld_objlist_add __P((Objlist *, Obj_Entry *));
-static Objlist_Entry *_rtld_objlist_find __P((Objlist *, const Obj_Entry *));
 static void _rtld_objlist_remove __P((Objlist *, Obj_Entry *));
 static void _rtld_unload_object __P((Obj_Entry *, bool));
 static void _rtld_unref_dag __P((Obj_Entry *));
@@ -478,7 +476,7 @@
                _rtld_die();
 
        dbg(("loading needed objects"));
-       if (_rtld_load_needed_objects(_rtld_objmain, true) == -1)
+       if (_rtld_load_needed_objects(_rtld_objmain, RTLD_GLOBAL, true) == -1)
                _rtld_die();
 
        for (obj = _rtld_objlist;  obj != NULL;  obj = obj->next)
@@ -689,18 +687,15 @@
        } else {
                char *path = _rtld_find_library(name, _rtld_objmain);
                if (path != NULL)
-                       obj = _rtld_load_object(path, true);
+                       obj = _rtld_load_object(path, mode, true);
        }
 
        if (obj != NULL) {
                ++obj->dl_refcount;
-               if ((mode & RTLD_GLOBAL) &&
-                   _rtld_objlist_find(&_rtld_list_global, obj) == NULL)
-                       _rtld_objlist_add(&_rtld_list_global, obj);
                if (*old_obj_tail != NULL) {    /* We loaded something new. */
                        assert(*old_obj_tail == obj);
 
-                       if (_rtld_load_needed_objects(obj, true) == -1 ||
+                       if (_rtld_load_needed_objects(obj, mode, true) == -1 ||
                            (_rtld_init_dag(obj),
                            _rtld_relocate_objects(obj,
                            ((mode & 3) == RTLD_NOW), true)) == -1) {
@@ -953,7 +948,7 @@
        return NULL;
 }
 
-static void
+void
 _rtld_objlist_add(list, obj)
        Objlist *list;
        Obj_Entry *obj;
@@ -965,7 +960,7 @@
        SIMPLEQ_INSERT_TAIL(list, elm, link);
 }
 
-static Objlist_Entry *
+Objlist_Entry *
 _rtld_objlist_find(Objlist *list, const Obj_Entry *obj)
 {
        Objlist_Entry *elm;
diff -r 2901dd4867ac -r cfba0729a266 libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h  Fri Nov 10 19:06:17 2000 +0000
+++ b/libexec/ld.elf_so/rtld.h  Fri Nov 10 21:31:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.h,v 1.28 2000/10/10 19:54:38 is Exp $      */
+/*     $NetBSD: rtld.h,v 1.29 2000/11/10 21:31:30 mycroft Exp $         */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -248,14 +248,16 @@
 void _rtld_debug_state __P((void));
 void _rtld_linkmap_add __P((Obj_Entry *));
 void _rtld_linkmap_delete __P((Obj_Entry *));
+void _rtld_objlist_add __P((Objlist *, Obj_Entry *));
+Objlist_Entry *_rtld_objlist_find __P((Objlist *, const Obj_Entry *));
 
 /* headers.c */
 void _rtld_digest_dynamic __P((Obj_Entry *));
 Obj_Entry *_rtld_digest_phdr __P((const Elf_Phdr *, int, caddr_t));
 
 /* load.c */
-Obj_Entry *_rtld_load_object __P((char *, bool));
-int _rtld_load_needed_objects __P((Obj_Entry *, bool));
+Obj_Entry *_rtld_load_object __P((char *, int, bool));
+int _rtld_load_needed_objects __P((Obj_Entry *, int, bool));
 int _rtld_preload __P((const char *, bool));
 
 /* path.c */



Home | Main Index | Thread Index | Old Index