Date: Wed, 10 Nov 2010 08:46:29 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r215084 - stable/8/libexec/rtld-elf Message-ID: <201011100846.oAA8kTsC096832@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Wed Nov 10 08:46:29 2010 New Revision: 215084 URL: http://svn.freebsd.org/changeset/base/215084 Log: MFC r214728: If dlopen() is called for the dso that has been already loaded as a dependency, then the dso never has its DAG initialized. Empty DAG makes ref_dag() call in dlopen() a nop, and the dso refcount is off by one. Initialize the DAG on the first dlopen() call, using a boolean flag to prevent double initialization. MFC r214776: Fix style. MFC r214777: Change init_dag() to not increment DAG refcount. Unconditionally call both init_dag() and ref_dag() in dlopen() for the case when the object was already loaded. Modified: stable/8/libexec/rtld-elf/rtld.c stable/8/libexec/rtld-elf/rtld.h Directory Properties: stable/8/libexec/rtld-elf/ (props changed) Modified: stable/8/libexec/rtld-elf/rtld.c ============================================================================== --- stable/8/libexec/rtld-elf/rtld.c Wed Nov 10 08:21:25 2010 (r215083) +++ stable/8/libexec/rtld-elf/rtld.c Wed Nov 10 08:46:29 2010 (r215084) @@ -1278,8 +1278,11 @@ init_dag(Obj_Entry *root) { DoneList donelist; + if (root->dag_inited) + return; donelist_init(&donelist); init_dag1(root, root, &donelist); + root->dag_inited = true; } static void @@ -1290,7 +1293,6 @@ init_dag1(Obj_Entry *root, Obj_Entry *ob if (donelist_check(dlp, obj)) return; - obj->refcount++; objlist_push_tail(&obj->dldags, root); objlist_push_tail(&root->dagmembers, obj); for (needed = obj->needed; needed != NULL; needed = needed->next) @@ -2035,6 +2037,7 @@ dlopen(const char *name, int mode) assert(*old_obj_tail == obj); result = load_needed_objects(obj, RTLD_LO_DLOPEN); init_dag(obj); + ref_dag(obj); if (result != -1) result = rtld_verify_versions(&obj->dagmembers); if (result != -1 && ld_tracing) @@ -2052,7 +2055,13 @@ dlopen(const char *name, int mode) } } else { - /* Bump the reference counts for objects on this DAG. */ + /* + * Bump the reference counts for objects on this DAG. If + * this is the first dlopen() call for the object that was + * already loaded as a dependency, initialize the dag + * starting at it. + */ + init_dag(obj); ref_dag(obj); if (ld_tracing) @@ -3059,6 +3068,7 @@ ref_dag(Obj_Entry *root) { Objlist_Entry *elm; + assert(root->dag_inited); STAILQ_FOREACH(elm, &root->dagmembers, link) elm->obj->refcount++; } @@ -3068,6 +3078,7 @@ unref_dag(Obj_Entry *root) { Objlist_Entry *elm; + assert(root->dag_inited); STAILQ_FOREACH(elm, &root->dagmembers, link) elm->obj->refcount--; } Modified: stable/8/libexec/rtld-elf/rtld.h ============================================================================== --- stable/8/libexec/rtld-elf/rtld.h Wed Nov 10 08:21:25 2010 (r215083) +++ stable/8/libexec/rtld-elf/rtld.h Wed Nov 10 08:46:29 2010 (r215084) @@ -222,6 +222,7 @@ typedef struct Struct_Obj_Entry { bool ref_nodel : 1; /* Refcount increased to prevent dlclose */ bool init_scanned: 1; /* Object is already on init list. */ bool on_fini_list: 1; /* Object is already on fini list. */ + bool dag_inited : 1; /* Object has its DAG initialized. */ struct link_map linkmap; /* For GDB and dlinfo() */ Objlist dldags; /* Object belongs to these dlopened DAGs (%) */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011100846.oAA8kTsC096832>