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 | |
| parent | 712ac5b11c3f250c4354d92ee5a902c67b6d2045 (diff) | |
| download | glibc-aed283dd456e7566cbfef88abe7b235ca77cc23c.tar.xz glibc-aed283dd456e7566cbfef88abe7b235ca77cc23c.zip | |
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.
| -rw-r--r-- | ChangeLog | 60 | ||||
| -rw-r--r-- | elf/Makefile | 10 | ||||
| -rw-r--r-- | elf/Versions | 4 | ||||
| -rw-r--r-- | elf/dl-load.c | 32 | ||||
| -rw-r--r-- | elf/dl-minimal.c | 12 | ||||
| -rw-r--r-- | elf/dl-open.c | 84 | ||||
| -rw-r--r-- | elf/dl-support.c | 12 | ||||
| -rw-r--r-- | elf/dl-sym.c | 22 | ||||
| -rw-r--r-- | elf/rtld.c | 131 | ||||
| -rw-r--r-- | elf/tls-macros.h | 16 | ||||
| -rw-r--r-- | elf/tst-tls1.c | 10 | ||||
| -rw-r--r-- | elf/tst-tls2.c | 10 | ||||
| -rw-r--r-- | elf/tst-tls3.c | 10 | ||||
| -rw-r--r-- | elf/tst-tls4.c | 56 | ||||
| -rw-r--r-- | elf/tst-tls5.c | 72 | ||||
| -rw-r--r-- | elf/tst-tlsmod1.c | 2 | ||||
| -rw-r--r-- | elf/tst-tlsmod2.c | 32 | ||||
| -rw-r--r-- | include/link.h | 4 | ||||
| -rw-r--r-- | include/stdlib.h | 2 | ||||
| -rw-r--r-- | linuxthreads/ChangeLog | 7 | ||||
| -rw-r--r-- | linuxthreads/sysdeps/i386/tls.h | 10 | ||||
| -rw-r--r-- | sysdeps/generic/dl-tls.c | 494 | ||||
| -rw-r--r-- | sysdeps/generic/ldsodefs.h | 37 | ||||
| -rw-r--r-- | sysdeps/i386/dl-tls.h | 6 |
24 files changed, 909 insertions, 226 deletions
@@ -1,7 +1,63 @@ +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. + 2002-02-08 Daniel Jacobowitz <drow@mvista.com> - * sysdeps/mips/machine-gmon.h: Update MCOUNT for current GCC - behavior. + * sysdeps/mips/machine-gmon.h: Update MCOUNT for current GCC behavior. 2002-02-10 Ulrich Drepper <drepper@redhat.com> diff --git a/elf/Makefile b/elf/Makefile index 9c5d4f6210..4ef1614c06 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -119,7 +119,7 @@ tests = loadtest restest1 preloadtest loadfail multiload origtest resolvfail \ $(tests-nodlopen-$(have-z-nodlopen)) neededtest neededtest2 \ neededtest3 neededtest4 unload2 lateglobal initfirst global \ restest2 next dblload dblunload reldep5 reldep6 tst-tls1 tst-tls2 \ - tst-tls3 + tst-tls3 tst-tls4 tst-tls5 test-srcs = tst-pathopt tests-vis-yes = vismain tests-nodelete-yes = nodelete @@ -137,7 +137,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ unload2mod unload2dep ltglobmod1 ltglobmod2 pathoptobj \ dblloadmod1 dblloadmod2 dblloadmod3 reldepmod5 reldepmod6 \ reldep6mod0 reldep6mod1 reldep6mod2 reldep6mod3 reldep6mod4 \ - tst-tlsmod1 + tst-tlsmod1 tst-tlsmod2 modules-vis-yes = vismod1 vismod2 vismod3 modules-nodelete-yes = nodelmod1 nodelmod2 nodelmod3 nodelmod4 modules-nodlopen-yes = nodlopenmod nodlopenmod2 @@ -442,3 +442,9 @@ $(objpfx)reldep6: $(libdl) $(objpfx)reldep6.out: $(objpfx)reldep6mod3.so $(objpfx)reldep6mod4.so $(objpfx)tst-tls3: $(objpfx)tst-tlsmod1.so + +$(objpfx)tst-tls4: $(libdl) +$(objpfx)tst-tls4.out: $(objpfx)tst-tlsmod2.so + +$(objpfx)tst-tls5: $(libdl) +$(objpfx)tst-tls5.out: $(objpfx)tst-tlsmod2.so diff --git a/elf/Versions b/elf/Versions index 8d8a1e8eac..927e26ff46 100644 --- a/elf/Versions +++ b/elf/Versions @@ -27,7 +27,7 @@ libc { ld { GLIBC_2.0 { # Function from libc.so which must be shared with libc. - calloc; free; malloc; realloc; + calloc; free; malloc; realloc; __libc_memalign; _r_debug; } @@ -49,6 +49,6 @@ ld { _dl_map_object; _dl_map_object_deps; _dl_out_of_memory; _dl_relocate_object; _dl_signal_error; _dl_start_profile; _dl_starting_up; _dl_unload_cache; - _rtld_global; + _rtld_global; _dl_tls_symaddr; } } diff --git a/elf/dl-load.c b/elf/dl-load.c index 1fffe72108..48e7cba235 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -941,30 +941,18 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp, #ifdef USE_TLS case PT_TLS: - l->l_tls_blocksize = ph->p_memsz; - l->l_tls_align = ph->p_align; - l->l_tls_initimage_size = ph->p_filesz; - /* Since we don't know the load address yet only store the - offset. We will adjust it later. */ - l->l_tls_initimage = (void *) ph->p_offset; - - /* This is the first element of the initialization image list. - It is created as a circular list so that we can easily - append to it. */ - if (GL(dl_initimage_list) == NULL) - GL(dl_initimage_list) = l->l_tls_nextimage = l->l_tls_previmage - = l; - else + if (ph->p_memsz > 0) { - l->l_tls_nextimage = GL(dl_initimage_list)->l_tls_nextimage; - l->l_tls_nextimage->l_tls_previmage = l; - l->l_tls_previmage = GL(dl_initimage_list); - l->l_tls_previmage->l_tls_nextimage = l; - GL(dl_initimage_list) = l; + l->l_tls_blocksize = ph->p_memsz; + l->l_tls_align = ph->p_align; + l->l_tls_initimage_size = ph->p_filesz; + /* Since we don't know the load address yet only store the + offset. We will adjust it later. */ + l->l_tls_initimage = (void *) ph->p_offset; + + /* Assign the next available module ID. */ + l->l_tls_modid = _dl_next_tls_modid (); } - - /* Assign the next available module ID. */ - l->l_tls_modid = _dl_next_tls_modid (); break; #endif } diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index c65151cb56..275ad86fe0 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -21,8 +21,9 @@ #include <limits.h> #include <string.h> #include <unistd.h> -#include <sys/types.h> #include <sys/mman.h> +#include <sys/param.h> +#include <sys/types.h> #include <ldsodefs.h> #include <stdio-common/_itoa.h> @@ -120,6 +121,15 @@ realloc (void *ptr, size_t n) assert (new == ptr); return new; } + +/* Return alligned memory block. */ +void * weak_function +__libc_memalign (size_t align, size_t n) +{ + void *newp = malloc (n + align - 1); + + return (void *) roundup ((uintptr_t) newp, align); +} /* Avoid signal frobnication in setjmp/longjmp. Keeps things smaller. */ diff --git a/elf/dl-open.c b/elf/dl-open.c index 8f30bc009d..d9ed499054 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); } diff --git a/elf/dl-support.c b/elf/dl-support.c index 914b43f057..876776acba 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -138,20 +138,22 @@ int _dl_correct_cache_id = _DL_CACHE_DEFAULT_ID; __libc_lock_define_initialized_recursive (, _dl_load_lock) #ifdef USE_TLS -/* Beginning of the list of link maps for objects which contain - thread-local storage sections. This will be traversed to - initialize new TLS blocks. */ -struct link_map *_dl_initimage_list; /* Highest dtv index currently needed. */ size_t _dl_tls_max_dtv_idx; /* Flag signalling whether there are gaps in the module ID allocation. */ bool _dl_tls_dtv_gaps; - +/* Information about the dtv slots. */ +struct dtv_slotinfo_list *_dl_tls_dtv_slotinfo_list; +/* Number of modules in the static TLS block. */ +size_t _dl_tls_static_nelem; /* Size of the static TLS block. */ size_t _dl_tls_static_size; /* Alignment requirement of the static TLS block. */ size_t _dl_tls_static_align; + +/* Generation counter for the dtv. */ +size_t _dl_tls_generation; #endif diff --git a/elf/dl-sym.c b/elf/dl-sym.c index b0db159aa6..8cb5d2f411 100644 --- a/elf/dl-sym.c +++ b/elf/dl-sym.c @@ -83,7 +83,16 @@ RTLD_NEXT used in code not dynamically loaded")); } if (ref != NULL) - return DL_SYMBOL_ADDRESS (result, ref); + { +#if defined USE_TLS && defined SHARED + if (ELFW(ST_TYPE) (ref->st_info) == STT_TLS) + /* The found symbol is a thread-local storage variable. + Return the address for to the current thread. */ + return _dl_tls_symaddr (result, ref); +#endif + + return DL_SYMBOL_ADDRESS (result, ref); + } return NULL; } @@ -152,7 +161,16 @@ RTLD_NEXT used in code not dynamically loaded")); } if (ref != NULL) - return DL_SYMBOL_ADDRESS (result, ref); + { +#if defined USE_TLS && defined SHARED + if (ELFW(ST_TYPE) (ref->st_info) == STT_TLS) + /* The found symbol is a thread-local storage variable. + Return the address for to the current thread. */ + return _dl_tls_symaddr (result, ref); +#endif + + return DL_SYMBOL_ADDRESS (result, ref); + } return NULL; } diff --git a/elf/rtld.c b/elf/rtld.c index 6463ed600e..d7653f2394 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -223,7 +223,7 @@ _dl_start_final (void *arg, struct link_map *bootstrap_map_p, ElfW(Ehdr) *ehdr; ElfW(Phdr) *phdr; size_t cnt; - dtv_t initdtv[2]; + dtv_t initdtv[3]; #endif if (HP_TIMING_AVAIL) @@ -291,16 +291,18 @@ _dl_start_final (void *arg, struct link_map *bootstrap_map_p, tlsblock = (void *) (((uintptr_t) tlsblock + max_align - 1) & ~(max_align - 1)); - /* Initialize the dtv. */ + /* Initialize the dtv. [0] is the length, [1] the generation + counter. */ initdtv[0].counter = 1; + initdtv[1].counter = 0; /* Initialize the TLS block. */ # if TLS_TCB_AT_TP - initdtv[1].pointer = tlsblock; + initdtv[2].pointer = tlsblock; # elif TLS_DTV_AT_TP GL(dl_rtld_map).l_tls_offset = roundup (TLS_INIT_TCB_SIZE, GL(dl_rtld_map).l_tls_align); - initdtv[1].pointer = (char *) tlsblock + GL(dl_rtld_map).l_tls_offset); + initdtv[2].pointer = (char *) tlsblock + GL(dl_rtld_map).l_tls_offset); # else # error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined" # endif @@ -723,22 +725,20 @@ of this helper program; chances are you did not intend to run this program.\n\ break; #ifdef USE_TLS case PT_TLS: - /* Note that in the case the dynamic linker we duplicate work - here since we read the PT_TLS entry already in - _dl_start_final. But the result is repeatable so do not - check for this special but unimportant case. */ - GL(dl_loaded)->l_tls_blocksize = ph->p_memsz; - GL(dl_loaded)->l_tls_align = ph->p_align; - GL(dl_loaded)->l_tls_initimage_size = ph->p_filesz; - GL(dl_loaded)->l_tls_initimage = (void *) ph->p_vaddr; - /* This is the first element of the initialization image list. - We create the list as circular since we have to append at - the end. */ - GL(dl_initimage_list) = GL(dl_loaded)->l_tls_nextimage - = GL(dl_loaded)->l_tls_previmage = GL(dl_loaded); - - /* This image gets the ID one. */ - GL(dl_tls_max_dtv_idx) = GL(dl_loaded)->l_tls_modid = 1; + if (ph->p_memsz > 0) + { + /* Note that in the case the dynamic linker we duplicate work + here since we read the PT_TLS entry already in + _dl_start_final. But the result is repeatable so do not + check for this special but unimportant case. */ + GL(dl_loaded)->l_tls_blocksize = ph->p_memsz; + GL(dl_loaded)->l_tls_align = ph->p_align; + GL(dl_loaded)->l_tls_initimage_size = ph->p_filesz; + GL(dl_loaded)->l_tls_initimage = (void *) ph->p_vaddr; + + /* This image gets the ID one. */ + GL(dl_tls_max_dtv_idx) = GL(dl_loaded)->l_tls_modid = 1; + } break; #endif } @@ -1188,43 +1188,66 @@ of this helper program; chances are you did not intend to run this program.\n\ use the static model. First add the dynamic linker to the list if it also uses TLS. */ if (GL(dl_rtld_map).l_tls_blocksize != 0) + /* Assign a module ID. */ + GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid (); + +# ifndef SHARED + /* If dynamic loading of modules with TLS is impossible we do not + have to initialize any of the TLS functionality unless any of the + initial modules uses TLS. */ + if (GL(dl_tls_max_dtv_idx) > 0) +# endif { - /* At to the list. */ - if (GL(dl_initimage_list) == NULL) - GL(dl_initimage_list) = GL(dl_rtld_map).l_tls_nextimage - = GL(dl_rtld_map).l_tls_previmage = &GL(dl_rtld_map); - else - { |
