1 /* Macros to support TLS testing in times of missing compiler support. */
3 #define COMMON_INT_DEF(x) \
4 asm (".tls_common " #x ",4,4")
5 /* XXX Until we get compiler support we don't need declarations. */
6 #define COMMON_INT_DECL(x)
8 /* XXX This definition will probably be machine specific, too. */
9 #define VAR_INT_DEF(x) \
10 asm (".section .tdata\n\t" \
14 ".size " #x ",4\n\t" \
16 /* XXX Until we get compiler support we don't need declarations. */
17 #define VAR_INT_DECL(x)
19 #include_next <tls-macros.h>
21 /* XXX Each architecture must have its own asm for now. */
25 asm ("movl %%gs:0,%0\n\t" \
26 "subl $" #x "@tpoff,%0" \
33 asm ("movl %%gs:0,%0\n\t" \
34 "subl " #x "@gottpoff(%%ebx),%0" \
42 "1:\tmovl (%%esp), %%ebx\n\t" \
45 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
46 "movl %%gs:0,%0\n\t" \
47 "subl " #x "@gottpoff(%%ebx),%0" \
48 : "=r" (__l), "=&b" (__b)); \
54 ({ int *__l, __c, __d; \
55 asm ("leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
56 "call ___tls_get_addr@plt\n\t" \
57 "leal " #x "@dtpoff(%%eax), %%eax" \
58 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
62 ({ int *__l, __b, __c, __d; \
65 "1:\tmovl (%%esp), %%ebx\n\t" \
68 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
69 "leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
70 "call ___tls_get_addr@plt\n\t" \
71 "leal " #x "@dtpoff(%%eax), %%eax" \
72 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
78 ({ int *__l, __c, __d; \
79 asm ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
80 "call ___tls_get_addr@plt\n\t" \
82 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
86 ({ int *__l, __b, __c, __d; \
89 "1:\tmovl (%%esp), %%ebx\n\t" \
92 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
93 "leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
94 "call ___tls_get_addr@plt\n\t" \
96 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
100 #elif defined __x86_64__
104 asm ("movq %%fs:0,%0\n\t" \
105 "leaq " #x "@tpoff(%0), %0" \
111 asm ("movq %%fs:0,%0\n\t" \
112 "addq " #x "@gottpoff(%%rip),%0" \
117 ({ int *__l, __c, __d; \
118 asm ("leaq " #x "@tlsld(%%rip),%%rdi\n\t" \
119 "call __tls_get_addr@plt\n\t" \
120 "leaq " #x "@dtpoff(%%rax), %%rax" \
121 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
122 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
126 ({ int *__l, __c, __d; \
127 asm (".byte 0x66\n\t" \
128 "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
131 "call __tls_get_addr@plt" \
132 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
133 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
139 ({ int *__l; void *__tp; \
140 asm ("stc gbr,%1\n\t" \
145 "1: .long " #x "@tpoff\n\t" \
147 : "=r" (__l), "=r" (__tp)); \
152 ({ int *__l; void *__tp; \
153 register void *__gp __asm__("r12"); \
154 asm ("mov.l 1f,r0\n\t" \
156 "mov.l @(r0,r12),%0\n\t" \
160 "1: .long " #x "@gottpoff\n\t" \
162 : "=r" (__l), "=r" (__tp) : "r" (__gp) : "r0"); \
166 ({ int *__l; void *__tp; \
167 asm ("mov.l r12,@-r15\n\t" \
173 "mov.l @(r0,r12),%0\n\t" \
177 "1: .long " #x "@gottpoff\n\t" \
178 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
179 "2: mov.l @r15+,r12" \
180 : "=r" (__l), "=r" (__tp) : : "r0"); \
187 register void *__gp __asm__("r12"); \
188 asm ("mov.l 1f,r4\n\t" \
197 "1: .long " #x "@tlsldm\n\t" \
198 "2: .long __tls_get_addr@plt\n\t" \
199 "4: mov.l 3f,%0\n\t" \
203 "3: .long " #x "@dtpoff\n\t" \
205 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
206 "r6", "r7", "pr", "t"); \
211 asm ("mov.l r12,@-r15\n\t" \
224 "1: .long " #x "@tlsldm\n\t" \
225 "2: .long __tls_get_addr@plt\n\t" \
226 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
227 "4: mov.l 3f,%0\n\t" \
231 "3: .long " #x "@dtpoff\n\t" \
232 "5: mov.l @r15+,r12" \
233 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
241 register void *__gp __asm__("r12"); \
242 asm ("mov.l 1f,r4\n\t" \
251 "1: .long " #x "@tlsgd\n\t" \
252 "2: .long __tls_get_addr@plt\n\t" \
254 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
255 "r6", "r7", "pr", "t"); \
260 asm ("mov.l r12,@-r15\n\t" \
273 "1: .long " #x "@tlsgd\n\t" \
274 "2: .long __tls_get_addr@plt\n\t" \
275 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
276 "3: mov.l @r15+,r12" \
277 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
282 #elif defined __alpha__
284 register void *__gp __asm__("$29");
288 asm ("call_pal 158\n\tlda $0," #x "($0)\t\t!tprel" : "=v"(__l)); \
292 ({ char *__tp; unsigned long __o; \
293 asm ("call_pal 158\n\tldq %1," #x "($gp)\t\t!gottprel" \
294 : "=v"(__tp), "=r"(__o) : "r"(__gp)); \
295 (int *)(__tp + __o); })
298 ({ extern void *__tls_get_addr(void *); int *__l; void *__i; \
299 asm ("lda %0," #x "($gp)\t\t!tlsldm" : "=r" (__i) : "r"(__gp)); \
300 __i = __tls_get_addr(__i); \
301 asm ("lda %0, " #x "(%1)\t\t!dtprel" : "=r"(__l) : "r"(__i)); \
305 ({ extern void *__tls_get_addr(void *); void *__i; \
306 asm ("lda %0," #x "($gp)\t\t!tlsgd" : "=r" (__i) : "r"(__gp)); \
307 (int *) __tls_get_addr(__i); })
310 #elif defined __ia64__
314 asm ("mov r2=r13\n\t" \
316 "addl %0=@tprel(" #x "),r2\n\t" \
317 : "=r" (__l) : : "r2" ); __l; })
321 register long __gp asm ("gp"); \
323 "addl r16=@ltoff(@tprel(" #x ")),gp\n\t" \
325 "ld8 r17=[r16]\n\t" \
327 "add %0=r13,r17\n\t" \
329 : "=r" (__l) : "r" (__gp) : "r16", "r17" ); __l; })
331 # define __TLS_CALL_CLOBBERS \
332 "r2", "r3", "r8", "r9", "r10", "r11", "r14", "r15", "r16", "r17", \
333 "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", \
334 "r27", "r28", "r29", "r30", "r31", \
335 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
336 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
338 "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7"
342 register long __gp asm ("gp"); \
345 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
346 "addl out1=@dtprel(" #x "),r0\n\t" \
348 "ld8 out0=[r16]\n\t" \
349 "br.call.sptk.many b0=__tls_get_addr" \
354 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
359 register long __gp asm ("gp"); \
362 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
363 "addl r17=@ltoff(@dtprel(" #x ")),gp\n\t" \
365 "ld8 out0=[r16]\n\t" \
366 "ld8 out1=[r17]\n\t" \
367 "br.call.sptk.many b0=__tls_get_addr" \
372 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
375 #elif defined __sparc__ && !defined __arch64__
379 asm ("sethi %%tle_hix22(" #x "), %0" : "=r" (__l)); \
380 asm ("xor %1, %%tle_lox10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
381 asm ("add %%g7, %1, %0" : "=r" (__l) : "r" (__l)); \
385 # define TLS_LOAD_PIC \
386 ({ register long pc __asm__ ("%o7"); \
388 asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
390 "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
391 "add %1, %0, %1\n\t" \
392 : "=r" (pc), "=r" (got)); \
395 # define TLS_LOAD_PIC \
397 asm (".hidden _GLOBAL_OFFSET_TABLE_\n\t" \
398 "sethi %%hi(_GLOBAL_OFFSET_TABLE_), %0\n\t" \
399 "or %0, %%lo(_GLOBAL_OFFSET_TABLE_), %0" \
406 asm ("sethi %%tie_hi22(" #x "), %0" : "=r" (__l)); \
407 asm ("add %1, %%tie_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
408 asm ("ld [%1 + %2], %0, %%tie_ld(" #x ")" \
409 : "=r" (__l) : "r" (TLS_LOAD_PIC), "r" (__l)); \
410 asm ("add %%g7, %1, %0, %%tie_add(" #x ")" : "=r" (__l) : "r" (__l)); \
414 ({ int *__l; register void *__o0 asm ("%o0"); \
416 asm ("sethi %%tldm_hi22(" #x "), %0" : "=r" (__l)); \
417 asm ("add %1, %%tldm_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
418 asm ("add %1, %2, %0, %%tldm_add(" #x ")" \
419 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
420 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
422 : "=r" (__o0) : "0" (__o0) \
423 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
425 asm ("sethi %%tldo_hix22(" #x "), %0" : "=r" (__o)); \
426 asm ("xor %1, %%tldo_lox10(" #x "), %0" : "=r" (__o) : "r" (__o)); \
427 asm ("add %1, %2, %0, %%tldo_add(" #x ")" : "=r" (__l) \
428 : "r" (__o0), "r" (__o)); \
432 ({ int *__l; register void *__o0 asm ("%o0"); \
433 asm ("sethi %%tgd_hi22(" #x "), %0" : "=r" (__l)); \
434 asm ("add %1, %%tgd_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
435 asm ("add %1, %2, %0, %%tgd_add(" #x ")" \
436 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
437 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
439 : "=r" (__o0) : "0" (__o0) \
440 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
444 #elif defined __s390x__
447 ({ unsigned long __offset; \
448 asm ("bras %0,1f\n" \
449 "0:\t.quad " #x "@ntpoff\n" \
451 : "=a" (__offset) : : "cc" ); \
452 (int *) (__builtin_thread_pointer() + __offset); })
456 ({ unsigned long __offset; \
457 asm ("bras %0,1f\n" \
458 "0:\t.quad " #x "@gotntpoff\n" \
459 "1:\tlg %0,0(%0)\n\t" \
460 "lg %0,0(%0,%%r12):tls_load:" #x \
461 : "=&a" (__offset) : : "cc" ); \
462 (int *) (__builtin_thread_pointer() + __offset); })
465 ({ unsigned long __offset; \
466 asm ("bras %0,1f\n" \
467 "0:\t.quad " #x "@indntpoff\n" \
468 "1:\t lg %0,0(%0)\n\t" \
469 "lg %0,0(%0):tls_load:" #x \
470 : "=&a" (__offset) : : "cc" ); \
471 (int *) (__builtin_thread_pointer() + __offset); })
476 ({ unsigned long __offset, __save12; \
477 asm ("bras %0,1f\n" \
478 "0:\t.quad " #x "@tlsldm\n\t" \
479 ".quad " #x "@dtpoff\n" \
480 "1:\tlgr %1,%%r12\n\t" \
481 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
482 "lg %%r2,0(%0)\n\t" \
483 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
487 : "=&a" (__offset), "=&a" (__save12) \
488 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
489 (int *) (__builtin_thread_pointer() + __offset); })
492 ({ unsigned long __offset; \
493 asm ("bras %0,1f\n" \
494 "0:\t.quad " #x "@tlsldm\n\t" \
495 ".quad " #x "@dtpoff\n" \
496 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
497 "lg %%r2,0(%0)\n\t" \
498 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
502 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
503 (int *) (__builtin_thread_pointer() + __offset); })
508 ({ unsigned long __offset, __save12; \
509 asm ("bras %0,1f\n" \
510 "0:\t.quad " #x "@tlsgd\n" \
511 "1:\tlgr %1,%%r12\n\t" \
512 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
513 "lg %%r2,0(%0)\n\t" \
514 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
517 : "=&a" (__offset), "=&a" (__save12) \
518 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
519 (int *) (__builtin_thread_pointer() + __offset); })
522 ({ unsigned long __offset; \
523 asm ("bras %0,1f\n" \
524 "0:\t.quad " #x "@tlsgd\n" \
525 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
526 "lg %%r2,0(%0)\n\t" \
527 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
530 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
531 (int *) (__builtin_thread_pointer() + __offset); })
534 #elif defined __s390__
537 ({ unsigned long __offset; \
538 asm ("bras %0,1f\n" \
539 "0:\t.long " #x "@ntpoff\n" \
541 : "=a" (__offset) : : "cc" ); \
542 (int *) (__builtin_thread_pointer() + __offset); })
546 ({ unsigned long __offset; \
547 asm ("bras %0,1f\n" \
548 "0:\t.long " #x "@gotntpoff\n" \
549 "1:\tl %0,0(%0)\n\t" \
550 "l %0,0(%0,%%r12):tls_load:" #x \
551 : "=&a" (__offset) : : "cc" ); \
552 (int *) (__builtin_thread_pointer() + __offset); })
555 ({ unsigned long __offset; \
556 asm ("bras %0,1f\n" \
557 "0:\t.long " #x "@indntpoff\n" \
558 "1:\t l %0,0(%0)\n\t" \
559 "l %0,0(%0):tls_load:" #x \
560 : "=&a" (__offset) : : "cc" ); \
561 (int *) (__builtin_thread_pointer() + __offset); })
566 ({ unsigned long __offset, __save12; \
567 asm ("bras %0,1f\n" \
568 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
569 ".long __tls_get_offset@plt-0b\n\t" \
570 ".long " #x "@tlsldm\n\t" \
571 ".long " #x "@dtpoff\n" \
572 "1:\tlr %1,%%r12\n\t" \
573 "l %%r12,0(%0)\n\t" \
574 "la %%r12,0(%%r12,%0)\n\t" \
577 "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
581 : "=&a" (__offset), "=&a" (__save12) \
582 : : "cc", "0", "1", "2", "3", "4", "5" ); \
583 (int *) (__builtin_thread_pointer() + __offset); })
586 ({ unsigned long __offset; \
587 asm ("bras %0,1f\n" \
588 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
589 ".long __tls_get_offset@plt\n\t" \
590 ".long " #x "@tlsldm\n\t" \
591 ".long " #x "@dtpoff\n" \
592 "1:\tl %%r12,0(%0)\n\t" \
595 "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
598 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
599 (int *) (__builtin_thread_pointer() + __offset); })
604 ({ unsigned long __offset, __save12; \
605 asm ("bras %0,1f\n" \
606 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
607 ".long __tls_get_offset@plt-0b\n\t" \
608 ".long " #x "@tlsgd\n" \
609 "1:\tlr %1,%%r12\n\t" \
610 "l %%r12,0(%0)\n\t" \
611 "la %%r12,0(%%r12,%0)\n\t" \
614 "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
617 : "=&a" (__offset), "=&a" (__save12) \
618 : : "cc", "0", "1", "2", "3", "4", "5" ); \
619 (int *) (__builtin_thread_pointer() + __offset); })
622 ({ unsigned long __offset; \
623 asm ("bras %0,1f\n" \
624 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
625 ".long __tls_get_offset@plt\n\t" \
626 ".long " #x "@tlsgd\n" \
627 "1:\tl %%r12,0(%0)\n\t" \
630 "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
632 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
633 (int *) (__builtin_thread_pointer() + __offset); })
636 #elif defined __powerpc__ && !defined __powerpc64__
638 # define __TLS_CALL_CLOBBERS \
639 "0", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", \
640 "lr", "ctr", "cr0", "cr1", "cr5", "cr6", "cr7"
642 /* PowerPC32 Local Exec TLS access. */
645 asm ("addi %0,2," #x "@tprel" \
646 : "=r" (__result)); \
649 /* PowerPC32 Initial Exec TLS access. */
652 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
654 "lwz %0," #x "@got@tprel(%0)\n\t" \
655 "add %0,%0," #x "@tls" \
656 : "=b" (__result) : \
660 /* PowerPC32 Local Dynamic TLS access. */
663 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
665 "addi 3,3," #x "@got@tlsld\n\t" \
666 "bl __tls_get_addr@plt\n\t" \
667 "addi %0,3," #x "@dtprel" \
668 : "=r" (__result) : \
669 : __TLS_CALL_CLOBBERS); \
672 /* PowerPC32 General Dynamic TLS access. */
674 ({ register int *__result __asm__ ("r3"); \
675 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
677 "addi 3,3," #x "@got@tlsgd\n\t" \
678 "bl __tls_get_addr@plt" \
680 : __TLS_CALL_CLOBBERS); \
683 #elif defined __powerpc__ && defined __powerpc64__
685 /* PowerPC64 Local Exec TLS access. */
689 " addis %0,13," #x "@tprel@ha\n" \
690 " addi %0,%0," #x "@tprel@l\n" \
691 : "=b" (__result) ); \
694 /* PowerPC64 Initial Exec TLS access. */
698 " ld %0," #x "@got@tprel(2)\n" \
699 " add %0,%0," #x "@tls\n" \
700 : "=b" (__result) ); \
703 /* PowerPC64 Local Dynamic TLS access. */
707 " addi 3,2," #x "@got@tlsld\n" \
708 " bl .__tls_get_addr\n" \
710 " addis %0,3," #x "@dtprel@ha\n" \
711 " addi %0,%0," #x "@dtprel@l\n" \
712 : "=b" (__result) : \
713 : "0", "3", "4", "5", "6", "7", \
714 "8", "9", "10", "11", "12", \
716 "cr0", "cr1", "cr5", "cr6", "cr7"); \
719 /* PowerPC64 General Dynamic TLS access. */
723 " addi 3,2," #x "@got@tlsgd\n" \
724 " bl .__tls_get_addr\n" \
727 : "=b" (__result) : \
728 : "0", "3", "4", "5", "6", "7", \
729 "8", "9", "10", "11", "12", \
731 "cr0", "cr1", "cr5", "cr6", "cr7"); \
735 #elif !defined TLS_LE || !defined TLS_IE \
736 || !defined TLS_LD || !defined TLS_GD(x)
737 # error "No support for this architecture so far."