summaryrefslogtreecommitdiff
path: root/elf/dl-close.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-03-30 16:30:49 +0000
committerUlrich Drepper <drepper@redhat.com>2000-03-30 16:30:49 +0000
commitdacc8ffa420575038f04c543c31065fea81d5732 (patch)
treee48ee55d563a39779776f3c7e02d76bc05a4cbb4 /elf/dl-close.c
parent38e986ecd8aba6953cfa4e7f104c671100f00999 (diff)
downloadglibc-dacc8ffa420575038f04c543c31065fea81d5732.tar.gz
Update.
2000-03-30 Ulrich Drepper <drepper@redhat.com> Implement dynamic determination of constructor/destructor order in the dynamic linker. * elf/Versions [ld.so] (GLIBC_2.0): Remove _dl_init_next. (GLIBC_2.2): Add _dl_init. * elf/dl-close.c: Also call all destructors in FINI_ARRAY. r_duplist is not anymore allocated separately. l_initfini is and therefore free it if necessary. * elf/dl-deps.c: If a searchlist has to be allocated, put all in one malloc block. Otherwise allocate l_initfini list only. Put dependencies for the object in l_initfini list. Sort dependencies for the object to be loaded topologically. * elf/dl-fini.c: Before running the destructors sort the topologically. * elf/dl-init.c (_dl_init): Renamed from _dl_init_next. Rewrite to call constructors instead of iterating over the pointers. Get list of objects for which to run constructors from l_initfini element. Accept argc, argv, and env as parameters and pass them to the constructors. * elf/ld-load.c (_dl_map_object_from_fd): Initialize l_ldnum member with size of dynamic section. * elf/dl-open.c (dl_open_worker): Only call _dl_init instead of _dl_init_next and calling constructors ourself. * elf/dl-preinit.c (_dl_preinit): Renamed from _dl_preinit_next. Take argc, argv, and env as parameters and pass them to the constructors. Rewrite to call all constructors and not iterate over the pointers. * elf/dynamic-link.h: Don't relocate DT_FINI_ARRAY entry. Don't precompute l_initcount and l_preinitcount. * elf/link.h (struct link_map): Add l_ldnum member. Make l_phdr_allocated part of the bitfield. Remove l_runcount, l_initcount, and l_preinitcount. Add l_initfini. * sysdeps/generic/ldsodefs.h: Replace _dl_init_next prototype with one for _dl_init. * sysdeps/i386/dl-machine (RTLD_START): Rewrite to match new init function interface. * sysdeps/unix/sysv/linux/init-first.h: Removed. * sysdeps/unix/sysv/linux/Dist: Delete file here as well. * sysdeps/unix/sysv/linux/init-first.c [PIC]: Don't use SYSDEP_CALL_INIT. Make _init a strong alias of init. The calling conventions now match. * sysdeps/generic/libc-start.c: Calling __libc_init_first has no effect for shared objects. Don't emit message and call only for static library.
Diffstat (limited to 'elf/dl-close.c')
-rw-r--r--elf/dl-close.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/elf/dl-close.c b/elf/dl-close.c
index 0636d2e16b..7740787a40 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -1,5 +1,5 @@
/* Close a shared object opened by `_dl_open'.
- Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -27,6 +27,10 @@
#include <sys/mman.h>
+/* Type of the constructor functions. */
+typedef void (*fini_t) (void);
+
+
/* During the program run we must not modify the global data of
loaded shared object simultanously in two threads. Therefore we
protect `dlopen' and `dlclose' in dlclose.c. */
@@ -64,9 +68,9 @@ _dl_close (void *_map)
/* Call all termination functions at once. */
for (i = 0; i < nsearchlist; ++i)
{
- struct link_map *imap = list[i];
+ struct link_map *imap = map->l_initfini[i];
if (imap->l_opencount == 1 && imap->l_type == lt_loaded
- && imap->l_info[DT_FINI]
+ && (imap->l_info[DT_FINI] || imap->l_info[DT_FINI_ARRAY])
/* Skip any half-cooked objects that were never initialized. */
&& imap->l_init_called)
{
@@ -74,9 +78,25 @@ _dl_close (void *_map)
if (_dl_debug_impcalls)
_dl_debug_message (1, "\ncalling fini: ", imap->l_name,
"\n\n", NULL);
+
/* Call its termination function. */
- (*(void (*) (void)) ((void *) imap->l_addr
- + imap->l_info[DT_FINI]->d_un.d_ptr)) ();
+ if (imap->l_info[DT_FINI_ARRAY] != NULL)
+ {
+ ElfW(Addr) *array =
+ (ElfW(Addr) *) (imap->l_addr
+ + imap->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+ unsigned int sz = (imap->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
+ / sizeof (ElfW(Addr)));
+ unsigned int cnt;
+
+ for (cnt = 0; cnt < sz; ++cnt)
+ ((fini_t) (imap->l_addr + array[cnt])) ();
+ }
+
+ /* Next try the old-style destructor. */
+ if (imap->l_info[DT_FINI] != NULL)
+ (*(void (*) (void)) ((void *) imap->l_addr
+ + imap->l_info[DT_FINI]->d_un.d_ptr)) ();
}
}
@@ -157,14 +177,13 @@ _dl_close (void *_map)
while (lnp != NULL);
/* Remove the searchlists. */
- if (imap->l_searchlist.r_duplist != imap->l_searchlist.r_list)
+ if (imap != map)
{
- /* If a r_list exists there always also is a r_duplist. */
- assert (imap->l_searchlist.r_list != NULL);
- free (imap->l_searchlist.r_duplist);
+ if (imap->l_searchlist.r_list != NULL)
+ free (imap->l_searchlist.r_list);
+ else if (imap->l_initfini != NULL)
+ free (imap->l_initfini);
}
- if (imap != map && imap->l_searchlist.r_list != NULL)
- free (imap->l_searchlist.r_list);
if (imap->l_phdr_allocated)
free ((void *) imap->l_phdr);