aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-tls.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-01-17 20:20:00 +0000
committerUlrich Drepper <drepper@redhat.com>2008-01-17 20:20:00 +0000
commit4c533566c2bb94162bcc1f66c5cf9db609e20803 (patch)
treeeb3d31e6a55056dc285e43b4700dccded4b88771 /elf/dl-tls.c
parenta0f6c236e068b4fa2d1116cdf7d31b2c2722ab6c (diff)
downloadglibc-4c533566c2bb94162bcc1f66c5cf9db609e20803.zip
glibc-4c533566c2bb94162bcc1f66c5cf9db609e20803.tar.gz
glibc-4c533566c2bb94162bcc1f66c5cf9db609e20803.tar.bz2
* include/link.h (FORCED_DYNAMIC_TLS_OFFSET): Define.
* elf/dl-close.c (_dl_close): Check for it. * elf/dl-reloc.c (CHECK_STATIC_TLS): Likewise. (_dl_allocate_static_tls): Likewise. * elf/dl-tls.c (_dl_allocate_tls_init): Likewise. (__tls_get_addr): Protect from race conditions in setting l_tls_offset to it. * elf/tst-tls16.c: New file. * elf/tst-tlsmod16a.c: New file. * elf/tst-tlsmod16b.c: New file. * elf/Makefile: Add rules to build and run tst-tls16.
Diffstat (limited to 'elf/dl-tls.c')
-rw-r--r--elf/dl-tls.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index d5865ab..3059481 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -413,7 +413,8 @@ _dl_allocate_tls_init (void *result)
not be the generation counter. */
maxgen = MAX (maxgen, listp->slotinfo[cnt].gen);
- if (map->l_tls_offset == NO_TLS_OFFSET)
+ if (map->l_tls_offset == NO_TLS_OFFSET
+ || map->l_tls_offset == FORCED_DYNAMIC_TLS_OFFSET)
{
/* For dynamically loaded modules we simply store
the value indicating deferred allocation. */
@@ -702,6 +703,7 @@ __tls_get_addr (GET_ADDR_ARGS)
if (__builtin_expect (dtv[0].counter != GL(dl_tls_generation), 0))
the_map = _dl_update_slotinfo (GET_ADDR_MODULE);
+ retry:
p = dtv[GET_ADDR_MODULE].pointer.val;
if (__builtin_expect (p == TLS_DTV_UNALLOCATED, 0))
@@ -722,6 +724,28 @@ __tls_get_addr (GET_ADDR_ARGS)
the_map = listp->slotinfo[idx].map;
}
+ /* Make sure that, if a dlopen running in parallel forces the
+ variable into static storage, we'll wait until the address in
+ the static TLS block is set up, and use that. If we're
+ undecided yet, make sure we make the decision holding the
+ lock as well. */
+ if (__builtin_expect (the_map->l_tls_offset
+ != FORCED_DYNAMIC_TLS_OFFSET, 0))
+ {
+ __rtld_lock_lock_recursive (GL(dl_load_lock));
+ if (__builtin_expect (the_map->l_tls_offset == NO_TLS_OFFSET, 1))
+ {
+ the_map->l_tls_offset = FORCED_DYNAMIC_TLS_OFFSET;
+ __rtld_lock_unlock_recursive (GL(dl_load_lock));
+ }
+ else
+ {
+ __rtld_lock_unlock_recursive (GL(dl_load_lock));
+ if (__builtin_expect (the_map->l_tls_offset
+ != FORCED_DYNAMIC_TLS_OFFSET, 1))
+ goto retry;
+ }
+ }
p = dtv[GET_ADDR_MODULE].pointer.val = allocate_and_init (the_map);
dtv[GET_ADDR_MODULE].pointer.is_static = false;
}