diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2005-10-03 19:48:25 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2005-10-03 19:48:25 +0000 |
commit | f0ec10f99ceed98f7aca872885d459d0b94f085b (patch) | |
tree | 58b09869d6b5e51c92af23da6035bb0faf4d674c /libexec | |
parent | dc1076a067eafa18a3b9c5f0ca9732efc6e5856b (diff) |
refcount corrections: count common dep libs once and centralize dep lib
refcount increments to _dl_link_sub. adjust _dl_notify_unload_shlib to
match new refcount method. ok drahn@
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/dlfcn.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/library.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/library_mquery.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/library_subr.c | 18 | ||||
-rw-r--r-- | libexec/ld.so/loader.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/resolve.c | 5 |
6 files changed, 23 insertions, 21 deletions
diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c index 1efac15a4f3..1e153e840df 100644 --- a/libexec/ld.so/dlfcn.c +++ b/libexec/ld.so/dlfcn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dlfcn.c,v 1.58 2005/10/01 19:32:22 drahn Exp $ */ +/* $OpenBSD: dlfcn.c,v 1.59 2005/10/03 19:48:24 kurt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -72,7 +72,7 @@ dlopen(const char *libname, int flags) if (object->opencount == 0) _dl_link_dlopen(object); - if (object->refcount > 1) + if (++object->refcount > 1) goto loaded; /* this add_object should not be here, XXX */ diff --git a/libexec/ld.so/library.c b/libexec/ld.so/library.c index 2c77c75f7cb..1e224236d4f 100644 --- a/libexec/ld.so/library.c +++ b/libexec/ld.so/library.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library.c,v 1.46 2005/10/01 19:32:22 drahn Exp $ */ +/* $OpenBSD: library.c,v 1.47 2005/10/03 19:48:24 kurt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -90,12 +90,10 @@ _dl_tryload_shlib(const char *libname, int type, int flags) object = _dl_lookup_object(libname); if (object) { - object->refcount++; object->load_object->obj_flags |= flags & RTLD_GLOBAL; if (object->load_object != object && object->load_object != _dl_objects && object->load_object != _dl_loading_object) { - object->load_object->refcount++; if (_dl_loading_object == NULL) _dl_loading_object = object; _dl_link_sub(object->load_object, _dl_loading_object); @@ -117,13 +115,11 @@ _dl_tryload_shlib(const char *libname, int type, int flags) for (object = _dl_objects; object != NULL; object = object->next) { if (object->dev == sb.st_dev && object->inode == sb.st_ino) { - object->refcount++; object->load_object->obj_flags |= flags & RTLD_GLOBAL; _dl_close(libfile); if (object->load_object != object && object->load_object != _dl_objects && object->load_object != _dl_loading_object) { - object->load_object->refcount++; if (_dl_loading_object == NULL) _dl_loading_object = object; diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index a0b3532825f..2ac6a12ed05 100644 --- a/libexec/ld.so/library_mquery.c +++ b/libexec/ld.so/library_mquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_mquery.c,v 1.27 2005/10/01 19:32:22 drahn Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.28 2005/10/03 19:48:24 kurt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -95,12 +95,10 @@ _dl_tryload_shlib(const char *libname, int type, int flags) object = _dl_lookup_object(libname); if (object) { - object->refcount++; object->load_object->obj_flags |= flags & RTLD_GLOBAL; if (object->load_object != object && object->load_object != _dl_objects && object->load_object != _dl_loading_object) { - object->load_object->refcount++; if (_dl_loading_object == NULL) _dl_loading_object = object; _dl_link_sub(object->load_object, _dl_loading_object); @@ -122,13 +120,11 @@ _dl_tryload_shlib(const char *libname, int type, int flags) for (object = _dl_objects; object != NULL; object = object->next) { if (object->dev == sb.st_dev && object->inode == sb.st_ino) { - object->refcount++; object->load_object->obj_flags |= flags & RTLD_GLOBAL; _dl_close(libfile); if (object->load_object != object && object->load_object != _dl_objects && object->load_object != _dl_loading_object) { - object->load_object->refcount++; if (_dl_loading_object == NULL) _dl_loading_object = object; _dl_link_sub(object->load_object, diff --git a/libexec/ld.so/library_subr.c b/libexec/ld.so/library_subr.c index 2fab10ca73b..44e9a30b178 100644 --- a/libexec/ld.so/library_subr.c +++ b/libexec/ld.so/library_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_subr.c,v 1.14 2005/10/01 19:32:22 drahn Exp $ */ +/* $OpenBSD: library_subr.c,v 1.15 2005/10/03 19:48:24 kurt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -353,10 +353,17 @@ _dl_notify_unload_shlib(elf_object_t *object) { struct dep_node *n; - object->refcount--; - - TAILQ_FOREACH(n, &object->child_list, next_sib) - n->data->refcount--; + /* + * if this is the last ref, then decrement refcount + * on self and all dloaded deps, otherwise just decrement + * self. + */ + if (object->refcount == 1) { + TAILQ_FOREACH(n, &object->dload_list, next_sib) + n->data->refcount--; + } else { + object->refcount--; + } } void @@ -401,6 +408,7 @@ _dl_link_sub(elf_object_t *dep, elf_object_t *p) _dl_exit(8); n->data = dep; TAILQ_INSERT_TAIL(&_dl_loading_object->dload_list, n, next_sib); + dep->refcount++; DL_DEB(("linking dep %s as child of %s\n", dep->load_name, p->load_name)); diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index fa09b606f67..29d8e7eff48 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.91 2005/09/28 18:17:42 kurt Exp $ */ +/* $OpenBSD: loader.c,v 1.92 2005/10/03 19:48:24 kurt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -334,7 +334,7 @@ _dl_boot(const char **argv, char **envp, const long loff, long *dl_data) _dl_exit(9); n->data = exe_obj; TAILQ_INSERT_TAIL(&exe_obj->dload_list, n, next_sib); - + exe_obj->refcount++; if (_dl_preload != NULL) _dl_dopreload(_dl_preload); @@ -430,6 +430,7 @@ _dl_boot(const char **argv, char **envp, const long loff, long *dl_data) _dl_exit(5); n->data = dyn_obj; TAILQ_INSERT_TAIL(&exe_obj->dload_list, n, next_sib); + dyn_obj->refcount++; dyn_obj->status |= STAT_RELOC_DONE; diff --git a/libexec/ld.so/resolve.c b/libexec/ld.so/resolve.c index 8034492209c..afc5ede1cd9 100644 --- a/libexec/ld.so/resolve.c +++ b/libexec/ld.so/resolve.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.c,v 1.37 2005/10/01 19:32:22 drahn Exp $ */ +/* $OpenBSD: resolve.c,v 1.38 2005/10/03 19:48:24 kurt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -153,7 +153,8 @@ _dl_finalize_object(const char *objname, Elf_Dyn *dynp, const long *dl_data, } DL_DEB(("obj %s has %s as head\n", object->load_name, _dl_loading_object->load_name )); - object->refcount = 1; + /* refcount handled in _dl_link_sub, _dl_boot & dlopen */ + object->refcount = 0; TAILQ_INIT(&object->child_list); object->opencount = 0; /* # dlopen() */ /* default dev, inode for dlopen-able objects. */ |