Add stub sys/procfs.h file
[glibc.git] / sysdeps / arm / tlsdesc.c
blobca941b87faf8769d97fc225350ed365fbc6c31d5
1 /* Manage TLS descriptors. ARM version.
2 Copyright (C) 2005-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <link.h>
20 #include <ldsodefs.h>
21 #include <elf/dynamic-link.h>
22 #include <tls.h>
23 #include <dl-tlsdesc.h>
24 #include <dl-unmap-segments.h>
25 #include <tlsdeschtab.h>
27 /* This function is used to lazily resolve TLS_DESC REL relocations
28 Besides the TLS descriptor itself, we get the module's got address
29 as the second parameter. */
31 void
32 attribute_hidden
33 _dl_tlsdesc_lazy_resolver_fixup (struct tlsdesc volatile *td,
34 Elf32_Addr *got)
36 struct link_map *l = (struct link_map *)got[1];
37 lookup_t result;
38 unsigned long value;
40 if (_dl_tlsdesc_resolve_early_return_p
41 (td, (void*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_PLT)]) + l->l_addr)))
42 return;
44 if (td->argument.value & 0x80000000)
46 /* A global symbol, this is the symbol index. */
47 /* The code below was borrowed from _dl_fixup(). */
48 const Elf_Symndx symndx = td->argument.value ^ 0x80000000;
49 const ElfW(Sym) *const symtab
50 = (const void *) D_PTR (l, l_info[DT_SYMTAB]);
51 const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
52 const ElfW(Sym) *sym = &symtab[symndx];
54 /* Look up the target symbol. If the normal lookup rules are not
55 used don't look in the global scope. */
56 if (ELFW(ST_BIND) (sym->st_info) != STB_LOCAL
57 && __builtin_expect (ELFW(ST_VISIBILITY) (sym->st_other), 0) == 0)
59 const struct r_found_version *version = NULL;
61 if (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
63 const ElfW(Half) *vernum =
64 (const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]);
65 ElfW(Half) ndx = vernum[symndx] & 0x7fff;
66 version = &l->l_versions[ndx];
67 if (version->hash == 0)
68 version = NULL;
71 result = _dl_lookup_symbol_x
72 (strtab + sym->st_name, l, &sym,
73 l->l_scope, version, ELF_RTYPE_CLASS_PLT,
74 DL_LOOKUP_ADD_DEPENDENCY, NULL);
75 if (sym)
76 value = sym->st_value;
77 else
79 td->entry = _dl_tlsdesc_undefweak;
80 goto done;
83 else
85 /* We already found the symbol. The module (and therefore its load
86 address) is also known. */
87 result = l;
88 value = sym->st_value;
91 else
93 /* A local symbol, this is the offset within our tls section.
95 value = td->argument.value;
96 result = l;
99 #ifndef SHARED
100 CHECK_STATIC_TLS (l, result);
101 #else
102 if (!TRY_STATIC_TLS (l, result))
104 td->argument.pointer = _dl_make_tlsdesc_dynamic (result, value);
105 td->entry = _dl_tlsdesc_dynamic;
107 else
108 #endif
110 td->argument.value = value + result->l_tls_offset;
111 td->entry = _dl_tlsdesc_return;
114 done:
115 _dl_tlsdesc_wake_up_held_fixups ();
118 /* This function is used to avoid busy waiting for other threads to
119 complete the lazy relocation. Once another thread wins the race to
120 relocate a TLS descriptor, it sets the descriptor up such that this
121 function is called to wait until the resolver releases the
122 lock. */
124 void
125 attribute_hidden
126 _dl_tlsdesc_resolve_hold_fixup (struct tlsdesc volatile *td,
127 void *caller)
129 /* Maybe we're lucky and can return early. */
130 if (caller != td->entry)
131 return;
133 /* Locking here will stop execution until the running resolver runs
134 _dl_tlsdesc_wake_up_held_fixups(), releasing the lock.
136 FIXME: We'd be better off waiting on a condition variable, such
137 that we didn't have to hold the lock throughout the relocation
138 processing. */
139 __rtld_lock_lock_recursive (GL(dl_load_lock));
140 __rtld_lock_unlock_recursive (GL(dl_load_lock));
143 /* Unmap the dynamic object, but also release its TLS descriptor table
144 if there is one. */
146 void
147 internal_function
148 _dl_unmap (struct link_map *map)
150 _dl_unmap_segments (map);
152 #ifdef SHARED
153 /* _dl_unmap is only called for dlopen()ed libraries, for which
154 calling free() is safe, or before we've completed the initial
155 relocation, in which case calling free() is probably pointless,
156 but still safe. */
157 if (map->l_mach.tlsdesc_table)
158 htab_delete (map->l_mach.tlsdesc_table);
159 #endif