Update.
[platform/upstream/glibc.git] / elf / tls-macros.h
1 /* Macros to support TLS testing in times of missing compiler support.  */
2
3 #define COMMON_INT_DEF(x) \
4   asm (".tls_common " #x ",4,4")
5
6 /* XXX This definition will probably be machine specific, too.  */
7 #define VAR_INT_DEF(x) \
8   asm (".section .tdata\n\t"                                                  \
9        ".globl " #x "\n"                                                      \
10        #x ":\t.long 0\n\t"                                                    \
11        ".previous")
12
13
14   /* XXX Each architecture must have its own asm for now.  */
15 #ifdef __i386__
16 # define TLS_LE(x) \
17   ({ int *__l;                                                                \
18      asm ("movl %%gs:0,%0\n\t"                                                \
19           "subl $" #x "@tpoff,%0"                                             \
20           : "=r" (__l));                                                      \
21      __l; })
22
23 #define TLS_IE(x) \
24   ({ int *__l, __b;                                                           \
25      asm ("call 1f\n\t"                                                       \
26           ".subsection 1\n"                                                   \
27           "1:\tmovl (%%esp), %%ebx\n\t"                                       \
28           "ret\n\t"                                                           \
29           ".previous\n\t"                                                     \
30           "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t"                            \
31           "movl %%gs:0,%0\n\t"                                                \
32           "subl " #x "@gottpoff(%%ebx),%0"                                    \
33           : "=r" (__l), "=&b" (__b));                                         \
34      __l; })
35
36 #define TLS_LD(x) \
37   ({ int *__l, __b;                                                           \
38      asm ("call 1f\n\t"                                                       \
39           ".subsection 1\n"                                                   \
40           "1:\tmovl (%%esp), %%ebx\n\t"                                       \
41           "ret\n\t"                                                           \
42           ".previous\n\t"                                                     \
43           "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t"                            \
44           "leal " #x "@tlsldm(%%ebx),%%eax\n\t"                               \
45           "call ___tls_get_addr@plt\n\t"                                      \
46           "leal " #x "@dtpoff(%%eax), %%eax"                                  \
47           : "=a" (__l), "=&b" (__b));                                         \
48      __l; })
49
50 #define TLS_GD(x) \
51   ({ int *__l, __b;                                                           \
52      asm ("call 1f\n\t"                                                       \
53           ".subsection 1\n"                                                   \
54           "1:\tmovl (%%esp), %%ebx\n\t"                                       \
55           "ret\n\t"                                                           \
56           ".previous\n\t"                                                     \
57           "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t"                            \
58           "leal " #x "@tlsgd(%%ebx),%%eax\n\t"                                \
59           "call ___tls_get_addr@plt\n\t"                                      \
60           "nop"                                                               \
61           : "=a" (__l), "=&b" (__b));                                         \
62      __l; })
63
64 #else
65 # error "No support for this architecture so far."
66 #endif