diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-02-13 08:03:56 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-02-13 08:03:56 +0000 |
commit | aed283dd456e7566cbfef88abe7b235ca77cc23c (patch) | |
tree | 39e854a8a182adce9cc8876c27a0a1d8b07d878e /elf/dl-open.c | |
parent | 712ac5b11c3f250c4354d92ee5a902c67b6d2045 (diff) | |
download | glibc-aed283dd456e7566cbfef88abe7b235ca77cc23c.zip glibc-aed283dd456e7566cbfef88abe7b235ca77cc23c.tar.gz glibc-aed283dd456e7566cbfef88abe7b235ca77cc23c.tar.bz2 |
Update.
2002-02-12 Ulrich Drepper <drepper@redhat.com>
* sysdeps/generic/dl-tls.c (TLS_DTV_UNALLOCATED): Renamed from
TLS_DTV_UNALLOCATE.
(oom): New function.
(_dl_next_tls_modid): Rewrite to handle dl_tls_dtv_slotinfo_list.
(_dl_determine_tlsoffset): Likewise.
(_dl_allocate_tls): Likewise.
(__TLS_GET_ADDR): Define if not already defined.
(_dl_tls_symaddr): New function.
(allocate_and_init): New function.
(__tls_get_addr): Actually implement handling of generation counter
and deferred allocation.
* sysdeps/generic/ldsodefs.h (_rtld_global): Remove _dl_initimage_list,
add _dl_tls_dtv_slotinfo_list, _dl_tls_static_nelem, and
_dl_tls_generation.
Define TLS_SLOTINFO_SURPLUS and DTV_SURPLUS.
Declare _dl_tls_symaddr.
* sysdeps/i386/dl-tls.h: Disable __tls_get_addr handling unless
SHARED.
* include/link.h (struct link_map): Remove l_tls_nextimage and
l_tls_previmage.
* elf/dl-sym.c (_dl_sym): After successful lookup call _dl_tls_symaddr
instead of DL_SYMBOL_ADDRESS for STT_TLS symbols.
(_dl_vsym): Likewise.
* elf/rtld.c (_dl_start_final): Adjust initdtv initialization for new
layout.
(dl_main): Allow PT_TLS be present for empty segment. Remove
nextimage list handling. Instead add all modules using TLS to
dl_tls_dtv_slotinfo_list.
* elf/dl-open.c (dl_open_worker): After successfully loading all
objects add those with TLS to the dl_tls_dtv_slotinfo_list list.
* elf/dl-load.c (_dl_map_object_from_fd): If PT_TLS entry is for an
empty segment don't do anything. Remove handling of initimage list.
* elf/Versions [ld] (GLIBC_2.0): Add __libc_memalign.
(GLIBC_PRIVATE): Add _dl_tls_symaddr.
* elf/dl-minimal.c: Define __libc_memalign.
* elf/dl-support.c: Remove _dl_initimage_list. Add
_dl_tls_dtv_slotinfo_list, _dl_tls_static_nelem, and
_dl_tls_generation.
* include/stdlib.h: Declare __libc_memalign.
* elf/Makefile: Add rules to build and run tst-tls4 and tst-tls5.
* elf/tst-tls4.c: New file.
* elf/tst-tls5.c: New file.
* elf/tst-tlsmod2.c: New file.
* elf/tls-macros.h: asms using ___tls_get_addr destroy %ecx and %edx.
* elf/tst-tlsmod1.c: Don't define variables unles USE_TLS.
* elf/tst-tls1.c: Use test-skeleton.c.
* elf/tst-tls2.c: Likewise.
* elf/tst-tls3.c: Likewise.
* elf/dl-conflict.c (RESOLVE_MAP): Return NULL not 0.
* sysdeps/mips/machine-gmon.h: Update MCOUNT for current GCC behavior.
Diffstat (limited to 'elf/dl-open.c')
-rw-r--r-- | elf/dl-open.c | 84 |
1 files changed, 80 insertions, 4 deletions
diff --git a/elf/dl-open.c b/elf/dl-open.c index 8f30bc0..d9ed499 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -31,6 +31,7 @@ #include <bp-sym.h> #include <dl-dst.h> +#include <dl-tls.h> extern ElfW(Addr) _dl_sysdep_start (void **start_argptr, @@ -353,6 +354,73 @@ dl_open_worker (void *a) imap->l_scope[cnt++] = &new->l_searchlist; imap->l_scope[cnt] = NULL; } +#if USE_TLS + else if (new->l_searchlist.r_list[i]->l_opencount == 1 + /* Only if the module defines thread local data. */ + && __builtin_expect (new->l_searchlist.r_list[i]->l_tls_blocksize + > 0, 0)) + { + /* Now that we know the object is loaded successfully add + modules containing TLS data to the dtv info table. We + might have to increase its size. */ + struct dtv_slotinfo_list *listp; + struct dtv_slotinfo_list *prevp; + size_t idx = new->l_searchlist.r_list[i]->l_tls_modid; + + assert (new->l_searchlist.r_list[i]->l_type == lt_loaded); + + /* Find the place in the stv slotinfo list. */ + listp = GL(dl_tls_dtv_slotinfo_list); + prevp = NULL; /* Needed to shut up gcc. */ + do + { + /* Does it fit in the array of this list element? */ + if (idx <= listp->len) + break; + prevp = listp; + } + while ((listp = listp->next) != NULL); + + if (listp == NULL) + { + /* When we come here it means we have to add a new element + to the slotinfo list. And the new module must be in + the first slot. */ + assert (idx == 0); + + listp = prevp->next = (struct dtv_slotinfo_list *) + malloc (sizeof (struct dtv_slotinfo_list) + + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); + if (listp == NULL) + { + /* We ran out of memory. We will simply fail this + call but don't undo anything we did so far. The + application will crash or be terminated anyway very + soon. */ + + /* We have to do this since some entries in the dtv + slotinfo array might already point to this + generation. */ + ++GL(dl_tls_generation); + + _dl_signal_error (ENOMEM, "dlopen", NULL, + N_("cannot create TLS data structures")); + } + + listp->len = TLS_SLOTINFO_SURPLUS; + listp->next = NULL; + memset (listp->slotinfo, '\0', + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); + } + + /* Add the information into the slotinfo data structure. */ + listp->slotinfo[idx].map = new->l_searchlist.r_list[i]; + listp->slotinfo[idx].gen = GL(dl_tls_generation) + 1; + } + + /* Bump the generation number. */ + ++GL(dl_tls_generation); +#endif /* Run the initializer functions of new objects. */ _dl_init (new, __libc_argc, __libc_argv, __environ); @@ -424,10 +492,18 @@ _dl_open (const char *file, int mode, const void *caller) { unsigned int i; - /* Increment open counters for all objects since this has - not happened yet. */ - for (i = 0; i < args.map->l_searchlist.r_nlist; ++i) - ++args.map->l_searchlist.r_list[i]->l_opencount; + /* Increment open counters for all objects since this + sometimes has not happened yet. */ + if (args.map->l_searchlist.r_list[0]->l_opencount == 0) + for (i = 0; i < args.map->l_searchlist.r_nlist; ++i) + ++args.map->l_searchlist.r_list[i]->l_opencount; + + /* Maybe some of the modules which were loaded uses TLS. + Since it will be removed in the folowing _dl_close call + we have to mark the dtv array as having gaps to fill + the holes. This is a pessimistic assumption which won't + hurt if not true. */ + GL(dl_tls_dtv_gaps) = true; _dl_close (args.map); } |