aarch64: Use range in copyright years.
[glibc.git] / ports / sysdeps / aarch64 / tlsdesc.c
blob606ce797c66ce84d08843a6c3b32db48d9ec2317
1 /* Manage TLS descriptors. AArch64 version.
3 Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 #include <link.h>
22 #include <ldsodefs.h>
23 #include <elf/dynamic-link.h>
24 #include <tls.h>
25 #include <dl-tlsdesc.h>
26 #include <tlsdeschtab.h>
28 /* The following functions take an entry_check_offset argument. It's
29 computed by the caller as an offset between its entry point and the
30 call site, such that by adding the built-in return address that is
31 implicitly passed to the function with this offset, we can easily
32 obtain the caller's entry point to compare with the entry point
33 given in the TLS descriptor. If it's changed, we want to return
34 immediately. */
36 /* This function is used to lazily resolve TLS_DESC RELA relocations.
37 The argument location is used to hold a pointer to the relocation. */
39 void
40 attribute_hidden
41 _dl_tlsdesc_resolve_rela_fixup (struct tlsdesc volatile *td,
42 struct link_map *l)
44 const ElfW(Rela) *reloc = td->arg;
46 if (_dl_tlsdesc_resolve_early_return_p
47 (td, (void*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_PLT)]) + l->l_addr)))
48 return;
50 /* The code below was borrowed from _dl_fixup(),
51 except for checking for STB_LOCAL. */
52 const ElfW(Sym) *const symtab
53 = (const void *) D_PTR (l, l_info[DT_SYMTAB]);
54 const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
55 const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)];
56 lookup_t result;
58 /* Look up the target symbol. If the normal lookup rules are not
59 used don't look in the global scope. */
60 if (ELFW(ST_BIND) (sym->st_info) != STB_LOCAL
61 && __builtin_expect (ELFW(ST_VISIBILITY) (sym->st_other), 0) == 0)
63 const struct r_found_version *version = NULL;
65 if (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
67 const ElfW(Half) *vernum =
68 (const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]);
69 ElfW(Half) ndx = vernum[ELFW(R_SYM) (reloc->r_info)] & 0x7fff;
70 version = &l->l_versions[ndx];
71 if (version->hash == 0)
72 version = NULL;
75 result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym,
76 l->l_scope, version, ELF_RTYPE_CLASS_PLT,
77 DL_LOOKUP_ADD_DEPENDENCY, NULL);
79 else
81 /* We already found the symbol. The module (and therefore its load
82 address) is also known. */
83 result = l;
86 if (!sym)
88 td->arg = (void*) reloc->r_addend;
89 td->entry = _dl_tlsdesc_undefweak;
91 else
93 # ifndef SHARED
94 CHECK_STATIC_TLS (l, result);
95 # else
96 if (!TRY_STATIC_TLS (l, result))
98 td->arg = _dl_make_tlsdesc_dynamic (result, sym->st_value
99 + reloc->r_addend);
100 td->entry = _dl_tlsdesc_dynamic;
102 else
103 # endif
105 td->arg = (void*) (sym->st_value + result->l_tls_offset
106 + reloc->r_addend);
107 td->entry = _dl_tlsdesc_return;
111 _dl_tlsdesc_wake_up_held_fixups ();
114 /* This function is used to avoid busy waiting for other threads to
115 complete the lazy relocation. Once another thread wins the race to
116 relocate a TLS descriptor, it sets the descriptor up such that this
117 function is called to wait until the resolver releases the
118 lock. */
120 void
121 attribute_hidden
122 _dl_tlsdesc_resolve_hold_fixup (struct tlsdesc volatile *td,
123 void *caller)
125 /* Maybe we're lucky and can return early. */
126 if (caller != td->entry)
127 return;
129 /* Locking here will stop execution until the running resolver runs
130 _dl_tlsdesc_wake_up_held_fixups(), releasing the lock.
132 FIXME: We'd be better off waiting on a condition variable, such
133 that we didn't have to hold the lock throughout the relocation
134 processing. */
135 __rtld_lock_lock_recursive (GL(dl_load_lock));
136 __rtld_lock_unlock_recursive (GL(dl_load_lock));
140 /* Unmap the dynamic object, but also release its TLS descriptor table
141 if there is one. */
143 void
144 internal_function
145 _dl_unmap (struct link_map *map)
147 __munmap ((void *) (map)->l_map_start,
148 (map)->l_map_end - (map)->l_map_start);
150 #if SHARED
151 if (map->l_mach.tlsdesc_table)
152 htab_delete (map->l_mach.tlsdesc_table);
153 #endif