1 /* Thread-local storage handling in the ELF dynamic linker.  x86-64 version.
2    Copyright (C) 2017-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
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.
9 
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.
14 
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    <https://www.gnu.org/licenses/>.  */
18 
19 #ifdef SHARED
20 /* Work around GCC PR58066, due to which __tls_get_addr may be called
21    with an unaligned stack.  The compat implementation is in
22    tls_get_addr-compat.S.  */
23 
24 # include <dl-tls.h>
25 
26 /* Define __tls_get_addr within elf/dl-tls.c under a different
27    name.  */
28 extern __typeof__ (__tls_get_addr) ___tls_get_addr;
29 
30 # define __tls_get_addr ___tls_get_addr
31 # include <elf/dl-tls.c>
32 # undef __tls_get_addr
33 
hidden_ver(___tls_get_addr,__tls_get_addr)34 hidden_ver (___tls_get_addr, __tls_get_addr)
35 
36 /* Only handle slow paths for __tls_get_addr.  */
37 attribute_hidden
38 void *
39 __tls_get_addr_slow (GET_ADDR_ARGS)
40 {
41   dtv_t *dtv = THREAD_DTV ();
42 
43   size_t gen = atomic_load_relaxed (&GL(dl_tls_generation));
44   if (__glibc_unlikely (dtv[0].counter != gen))
45     return update_get_addr (GET_ADDR_PARAM);
46 
47   return tls_get_addr_tail (GET_ADDR_PARAM, dtv, NULL);
48 }
49 #else
50 
51 /* No compatibility symbol needed.  */
52 # include <elf/dl-tls.c>
53 
54 #endif
55