summaryrefslogtreecommitdiff
path: root/elf/dl-close.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-01-06 22:40:27 +0000
committerUlrich Drepper <drepper@redhat.com>2005-01-06 22:40:27 +0000
commit9dcafc559763e339d4a79580c333127033e39c11 (patch)
tree342441fed429693bc69d95addc588e10a7d021c4 /elf/dl-close.c
parentf14038f2e295e7994e2317127cdea1cb26db6be1 (diff)
downloadglibc-9dcafc559763e339d4a79580c333127033e39c11.tar.gz
* csu/elf-init.c (__libc_csu_fini): Don't do anything here.
* sysdeps/generic/libc-start.c: Don't register program destructor here. * dlfcn/Makefile: Add rules to build dlfcn.c. (LDFLAGS-dl.so): Removed. * dlfcn/dlclose.c: _dl_close is now in ld.so, use function pointer table. * dlfcn/dlmopen.c: Likewise for _dl_open. * dlfcn/dlopen.c: Likewise. * dlfcn/dlopenold.c: Likewise. * elf/dl-libc.c: Likewise for _dl_open and _dl_close. * elf/Makefile (routines): Remove dl-open and dl-close. (dl-routines): Add dl-open, dl-close, and dl-trampoline. Add rules to build and run tst-audit1. * elf/tst-audit1.c: New file. * elf/tst-auditmod1.c: New file. * elf/Versions [libc]: Remove _dl_open and _dl_close. * elf/dl-close.c: Change for use inside ld.so instead of libc.so. * elf/dl-open.c: Likewise. * elf/dl-debug.c (_dl_debug_initialize): Allow reinitialization, signaled by nonzero parameter. * elf/dl-init.c: Fix use of r_state. * elf/dl-load.c: Likewise. * elf/dl-close.c: Add auditing checkpoints. * elf/dl-open.c: Likewise. * elf/dl-fini.c: Likewise. * elf/dl-load.c: Likewise. * elf/dl-sym.c: Likewise. * sysdeps/generic/libc-start.c: Likewise. * elf/dl-object.c: Allocate memory for auditing information. * elf/dl-reloc.c: Remove RESOLV. We now always need the map. Correctly initialize slotinfo. * elf/dynamic-link.h: Adjust after removal of RESOLV. * sysdeps/hppa/dl-lookupcfg.h: Likewise. * sysdeps/ia64/dl-lookupcfg.h: Likewise. * sysdeps/powerpc/powerpc64/dl-lookupcfg.h: Removed. * elf/dl-runtime.c (_dl_fixup): Little cleanup. (_dl_profile_fixup): New parameters to point to register struct and variable for frame size. Add auditing checkpoints. (_dl_call_pltexit): New function. Don't define trampoline code here. * elf/rtld.c: Recognize LD_AUDIT. Load modules on startup. Remove all the functions from _rtld_global_ro which only _dl_open and _dl_close needed. Add auditing checkpoints. * elf/link.h: Define symbols for auditing interfaces. * include/link.h: Likewise. * include/dlfcn.h: Define __RTLD_AUDIT. Remove prototypes for _dl_open and _dl_close. Adjust access to argc and argv in libdl. * dlfcn/dlfcn.c: New file. * sysdeps/generic/dl-lookupcfg.h: Remove all content now that RESOLVE is gone. * sysdeps/generic/ldsodefs.h: Add definitions for auditing interfaces. * sysdeps/generic/unsecvars.h: Add LD_AUDIT. * sysdeps/i386/dl-machine.h: Remove trampoline code here. Adjust for removal of RESOLVE. * sysdeps/x86_64/dl-machine.h: Likewise. * sysdeps/generic/dl-trampoline.c: New file. * sysdeps/i386/dl-trampoline.c: New file. * sysdeps/x86_64/dl-trampoline.c: New file. * sysdeps/generic/dl-tls.c: Cleanups. Fixup for dtv_t change. Fix updating of DTV. * sysdeps/generic/libc-tls.c: Likewise. * sysdeps/arm/bits/link.h: Renamed to ... * sysdeps/arm/buts/linkmap.h: ...this. * sysdeps/generic/bits/link.h: Renamed to... * sysdeps/generic/bits/linkmap.h: ...this. * sysdeps/hppa/bits/link.h: Renamed to... * sysdeps/hppa/bits/linkmap.h: ...this. * sysdeps/hppa/i386/link.h: Renamed to... * sysdeps/hppa/i386/linkmap.h: ...this. * sysdeps/hppa/ia64/link.h: Renamed to... * sysdeps/hppa/ia64/linkmap.h: ...this. * sysdeps/hppa/s390/link.h: Renamed to... * sysdeps/hppa/s390/linkmap.h: ...this. * sysdeps/hppa/sh/link.h: Renamed to... * sysdeps/hppa/sh/linkmap.h: ...this. * sysdeps/hppa/x86_64/link.h: Renamed to... * sysdeps/hppa/x86_64/linkmap.h: ...this. 2005-01-06 Ulrich Drepper <drepper@redhat.com> * allocatestack.c (init_one_static_tls): Adjust initialization of DTV entry for static tls deallocation fix. * sysdeps/alpha/tls.h (dtv_t): Change pointer type to be struct which also contains information whether the memory pointed to is static TLS or not. * sysdeps/i386/tls.h: Likewise. * sysdeps/ia64/tls.h: Likewise. * sysdeps/powerpc/tls.h: Likewise. * sysdeps/s390/tls.h: Likewise. * sysdeps/sh/tls.h: Likewise. * sysdeps/sparc/tls.h: Likewise. * sysdeps/x86_64/tls.h: Likewise.
Diffstat (limited to 'elf/dl-close.c')
-rw-r--r--elf/dl-close.c110
1 files changed, 85 insertions, 25 deletions
diff --git a/elf/dl-close.c b/elf/dl-close.c
index c823b17642..cf926ae566 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <bits/libc-lock.h>
#include <ldsodefs.h>
#include <sys/types.h>
@@ -99,7 +100,6 @@ remove_slotinfo (size_t idx, struct dtv_slotinfo_list *listp, size_t disp,
void
-internal_function
_dl_close (void *_map)
{
struct reldep_list
@@ -112,6 +112,7 @@ _dl_close (void *_map)
} *reldeps = NULL;
struct link_map **list;
struct link_map *map = _map;
+ Lmid_t ns = map->l_ns;
unsigned int i;
unsigned int *new_opencount;
#ifdef USE_TLS
@@ -139,8 +140,8 @@ _dl_close (void *_map)
{
/* There are still references to this object. Do nothing more. */
if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0))
- GLRO(dl_debug_printf) ("\nclosing file=%s; opencount == %u\n",
- map->l_name, map->l_opencount);
+ _dl_debug_printf ("\nclosing file=%s; opencount == %u\n",
+ map->l_name, map->l_opencount);
/* Decrement the object's reference counter, not the dependencies'. */
--map->l_opencount;
@@ -268,13 +269,17 @@ _dl_close (void *_map)
for (i = 0; list[i] != NULL; ++i)
{
struct link_map *imap = list[i];
+
+ /* All elements must be in the same namespace. */
+ assert (imap->l_ns == ns);
+
if (new_opencount[i] == 0 && imap->l_type == lt_loaded
&& (imap->l_flags_1 & DF_1_NODELETE) == 0)
{
/* When debugging print a message first. */
if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
- GLRO(dl_debug_printf) ("\ncalling fini: %s [%lu]\n\n",
- imap->l_name, imap->l_ns);
+ _dl_debug_printf ("\ncalling fini: %s [%lu]\n\n",
+ imap->l_name, ns);
/* Call its termination function. Do not do it for
half-cooked objects. */
@@ -299,6 +304,22 @@ _dl_close (void *_map)
+ imap->l_info[DT_FINI]->d_un.d_ptr))) ();
}
+#ifdef SHARED
+ /* Auditing checkpoint: we have a new object. */
+ if (__builtin_expect (GLRO(dl_naudit) > 0, 0))
+ {
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->objclose != NULL)
+ /* Return value is ignored. */
+ (void) afct->objclose (&imap->l_audit[cnt].cookie);
+
+ afct = afct->next;
+ }
+ }
+#endif
+
/* This object must not be used anymore. We must remove the
reference from the scope. */
unsigned int j;
@@ -365,9 +386,30 @@ _dl_close (void *_map)
assert (imap->l_type == lt_loaded || imap->l_opencount > 0);
}
+#ifdef SHARED
+ /* Auditing checkpoint: we will start deleting objects. */
+ if (__builtin_expect (GLRO(dl_naudit) > 0, 0))
+ {
+ struct link_map *head = GL(dl_ns)[ns]._ns_loaded;
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ /* Do not call the functions for any auditing object. */
+ if (head->l_auditing == 0)
+ {
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->activity != NULL)
+ afct->activity (&head->l_audit[cnt].cookie, LA_ACT_DELETE);
+
+ afct = afct->next;
+ }
+ }
+ }
+#endif
+
/* Notify the debugger we are about to remove some loaded objects. */
- _r_debug.r_state = RT_DELETE;
- GLRO(dl_debug_state) ();
+ struct r_debug *r = _dl_debug_initialize (0);
+ r->r_state = RT_DELETE;
+ _dl_debug_state ();
#ifdef USE_TLS
size_t tls_free_start;
@@ -389,21 +431,19 @@ _dl_close (void *_map)
if (__builtin_expect (imap->l_global, 0))
{
/* This object is in the global scope list. Remove it. */
- unsigned int cnt
- = GL(dl_ns)[imap->l_ns]._ns_main_searchlist->r_nlist;
+ unsigned int cnt = GL(dl_ns)[ns]._ns_main_searchlist->r_nlist;
do
--cnt;
- while (GL(dl_ns)[imap->l_ns]._ns_main_searchlist->r_list[cnt]
- != imap);
+ while (GL(dl_ns)[ns]._ns_main_searchlist->r_list[cnt] != imap);
/* The object was already correctly registered. */
while (++cnt
- < GL(dl_ns)[imap->l_ns]._ns_main_searchlist->r_nlist)
- GL(dl_ns)[imap->l_ns]._ns_main_searchlist->r_list[cnt - 1]
- = GL(dl_ns)[imap->l_ns]._ns_main_searchlist->r_list[cnt];
+ < GL(dl_ns)[ns]._ns_main_searchlist->r_nlist)
+ GL(dl_ns)[ns]._ns_main_searchlist->r_list[cnt - 1]
+ = GL(dl_ns)[ns]._ns_main_searchlist->r_list[cnt];
- --GL(dl_ns)[imap->l_ns]._ns_main_searchlist->r_nlist;
+ --GL(dl_ns)[ns]._ns_main_searchlist->r_nlist;
}
#ifdef USE_TLS
@@ -412,9 +452,10 @@ _dl_close (void *_map)
{
any_tls = true;
- if (! remove_slotinfo (imap->l_tls_modid,
- GL(dl_tls_dtv_slotinfo_list), 0,
- imap->l_init_called))
+ if (GL(dl_tls_dtv_slotinfo_list) != NULL
+ && ! remove_slotinfo (imap->l_tls_modid,
+ GL(dl_tls_dtv_slotinfo_list), 0,
+ imap->l_init_called))
/* All dynamically loaded modules with TLS are unloaded. */
GL(dl_tls_max_dtv_idx) = GL(dl_tls_static_nelem);
@@ -499,12 +540,12 @@ _dl_close (void *_map)
else
{
#ifdef SHARED
- assert (imap->l_ns != LM_ID_BASE);
+ assert (ns != LM_ID_BASE);
#endif
- GL(dl_ns)[imap->l_ns]._ns_loaded = imap->l_next;
+ GL(dl_ns)[ns]._ns_loaded = imap->l_next;
}
- --GL(dl_ns)[imap->l_ns]._ns_nloaded;
+ --GL(dl_ns)[ns]._ns_nloaded;
if (imap->l_next != NULL)
imap->l_next->l_prev = imap->l_prev;
@@ -579,16 +620,36 @@ _dl_close (void *_map)
if (any_tls)
{
if (__builtin_expect (++GL(dl_tls_generation) == 0, 0))
- __libc_fatal (_("TLS generation counter wrapped! Please report as described in <http://www.gnu.org/software/libc/bugs.html>."));
+ _dl_fatal_printf ("TLS generation counter wrapped! Please report as described in <http://www.gnu.org/software/libc/bugs.html>.\n");
if (tls_free_end == GL(dl_tls_static_used))
GL(dl_tls_static_used) = tls_free_start;
}
#endif
+#ifdef SHARED
+ /* Auditing checkpoint: we have deleted all objects. */
+ if (__builtin_expect (GLRO(dl_naudit) > 0, 0))
+ {
+ struct link_map *head = GL(dl_ns)[ns]._ns_loaded;
+ /* Do not call the functions for any auditing object. */
+ if (head->l_auditing == 0)
+ {
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->activity != NULL)
+ afct->activity (&head->l_audit[cnt].cookie, LA_ACT_CONSISTENT);
+
+ afct = afct->next;
+ }
+ }
+ }
+#endif
+
/* Notify the debugger those objects are finalized and gone. */
- _r_debug.r_state = RT_CONSISTENT;
- GLRO(dl_debug_state) ();
+ r->r_state = RT_CONSISTENT;
+ _dl_debug_state ();
/* Now we can perhaps also remove the modules for which we had
dependencies because of symbol lookup. */
@@ -612,7 +673,6 @@ _dl_close (void *_map)
/* Release the lock. */
__rtld_lock_unlock_recursive (GL(dl_load_lock));
}
-libc_hidden_def (_dl_close)
#ifdef USE_TLS