summaryrefslogtreecommitdiff
path: root/test/tls
diff options
context:
space:
mode:
Diffstat (limited to 'test/tls')
-rw-r--r--test/tls/Makefile7
-rw-r--r--test/tls/Makefile.in138
-rw-r--r--test/tls/README8
-rw-r--r--test/tls/tls-macros-arm.h51
-rw-r--r--test/tls/tls-macros-mips.h88
-rw-r--r--test/tls/tls-macros-thumb.h57
-rw-r--r--test/tls/tls-macros.h861
-rw-r--r--test/tls/tst-tls-at-ctor.c21
-rw-r--r--test/tls/tst-tls1-static.c1
-rw-r--r--test/tls/tst-tls1.c92
-rw-r--r--test/tls/tst-tls10.c40
-rw-r--r--test/tls/tst-tls10.h38
-rw-r--r--test/tls/tst-tls11.c27
-rw-r--r--test/tls/tst-tls12.c18
-rw-r--r--test/tls/tst-tls13.c30
-rw-r--r--test/tls/tst-tls14.c66
-rw-r--r--test/tls/tst-tls15.c33
-rw-r--r--test/tls/tst-tls16.c53
-rw-r--r--test/tls/tst-tls17.c29
-rw-r--r--test/tls/tst-tls18.c38
-rw-r--r--test/tls/tst-tls2-static.c1
-rw-r--r--test/tls/tst-tls2.c91
-rw-r--r--test/tls/tst-tls3.c76
-rw-r--r--test/tls/tst-tls4.c56
-rw-r--r--test/tls/tst-tls5.c72
-rw-r--r--test/tls/tst-tls6.c108
-rw-r--r--test/tls/tst-tls7.c79
-rw-r--r--test/tls/tst-tls8.c230
-rw-r--r--test/tls/tst-tls9-static.c1
-rw-r--r--test/tls/tst-tls9.c42
-rw-r--r--test/tls/tst-tlsmod-at-ctor.c25
-rw-r--r--test/tls/tst-tlsmod1.c68
-rw-r--r--test/tls/tst-tlsmod10.c1
-rw-r--r--test/tls/tst-tlsmod11.c6
-rw-r--r--test/tls/tst-tlsmod12.c14
-rw-r--r--test/tls/tst-tlsmod13.c14
-rw-r--r--test/tls/tst-tlsmod13a.c16
-rw-r--r--test/tls/tst-tlsmod14a.c41
-rw-r--r--test/tls/tst-tlsmod14b.c2
-rw-r--r--test/tls/tst-tlsmod15a.c6
-rw-r--r--test/tls/tst-tlsmod15b.c17
-rw-r--r--test/tls/tst-tlsmod16a.c7
-rw-r--r--test/tls/tst-tlsmod16b.c13
-rw-r--r--test/tls/tst-tlsmod17a.c23
-rw-r--r--test/tls/tst-tlsmod17b.c15
-rw-r--r--test/tls/tst-tlsmod18a.c21
-rw-r--r--test/tls/tst-tlsmod2.c38
-rw-r--r--test/tls/tst-tlsmod3.c41
-rw-r--r--test/tls/tst-tlsmod4.c38
-rw-r--r--test/tls/tst-tlsmod5.c7
-rw-r--r--test/tls/tst-tlsmod6.c7
-rw-r--r--test/tls/tst-tlsmod7.c103
-rw-r--r--test/tls/tst-tlsmod8.c72
-rw-r--r--test/tls/tst-tlsmod9.c101
54 files changed, 3148 insertions, 0 deletions
diff --git a/test/tls/Makefile b/test/tls/Makefile
new file mode 100644
index 000000000..a99c5d16f
--- /dev/null
+++ b/test/tls/Makefile
@@ -0,0 +1,7 @@
+# uClibc NPTL tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+top_builddir=../../
+include ../Rules.mak
+-include Makefile.in
+include ../Test.mak
diff --git a/test/tls/Makefile.in b/test/tls/Makefile.in
new file mode 100644
index 000000000..69a8eaf27
--- /dev/null
+++ b/test/tls/Makefile.in
@@ -0,0 +1,138 @@
+# uClibc TLS tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+TESTS := tst-tls1 tst-tls2 tst-tls3 tst-tls4 tst-tls5 tst-tls6 tst-tls7 \
+ tst-tls8 tst-tls9 tst-tls10 tst-tls11 tst-tls12 tst-tls13 \
+ tst-tls14 tst-tls15 tst-tls16 tst-tls17 tst-tls18 tst-tls-at-ctor \
+ tst-tls1-static tst-tls2-static tst-tls9-static
+TESTS_DISABLED := tst-tls1-static tst-tls2-static tst-tls9-static
+
+# All these tests need tls.h, which is not installed with glibc
+GLIBC_TESTS_DISABLED := $(addsuffix _glibc,$(filter-out $(TESTS_DISABLED),$(TESTS)))
+
+
+PTDIR := $(top_builddir)libpthread/nptl
+
+EXTRA_CFLAGS := -DNOT_IN_libc=1 \
+ -std=gnu99 -I. -I$(PTDIR) \
+ -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
+ -I$(PTDIR)/sysdeps/$(TARGET_ARCH) \
+ -I$(PTDIR)/sysdeps/unix/sysv/linux \
+ -I$(PTDIR)/sysdeps/pthread \
+ -I$(PTDIR)/sysdeps/pthread/bits \
+ -I$(PTDIR)/sysdeps/generic \
+ -I$(top_builddir)ldso/include \
+ -I$(top_builddir)ldso/ldso/$(TARGET_ARCH) \
+ -I$(top_builddir)include \
+ -include $(top_builddir)include/libc-symbols.h
+
+tlsmod17a-suffixes := 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
+tlsmod18a-suffixes := 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
+CFLAGS_tst-tlsmod1.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod2.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod3.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod4.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod5.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod6.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod7.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod8.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod9.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod10.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod11.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod12.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod13.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod13a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod14a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod14b.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod15a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod15b.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod16a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod16b.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod17a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod17b.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod18a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod-at-ctor.so := -fPIC -DSHARED -shared
+
+LDFLAGS_tst-tlsmod1.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod2.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod3.so := -shared -static-libgcc -L$(top_builddir)lib \
+ tst-tlsmod2.so
+LDFLAGS_tst-tlsmod4.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod5.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod6.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod7.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod8.so := -shared -static-libgcc -L$(top_builddir)lib \
+ tst-tlsmod7.so
+LDFLAGS_tst-tlsmod9.so := -shared -static-libgcc -L$(top_builddir)lib \
+ tst-tlsmod8.so
+LDFLAGS_tst-tlsmod10.so := -shared -static-libgcc -L$(top_builddir)lib \
+ tst-tlsmod9.so
+LDFLAGS_tst-tlsmod11.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod12.so := -shared -static-libgcc -L$(top_builddir)lib \
+ tst-tlsmod11.so
+LDFLAGS_tst-tlsmod13.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod13a.so := -shared -static-libgcc -L$(top_builddir)lib \
+ tst-tlsmod13.so
+LDFLAGS_tst-tlsmod14a.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod14b.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod15a.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod15b.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod16a.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod16b.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod17a.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod17b.so := -shared -static-libgcc -L$(top_builddir)lib \
+ $(patsubst %,tst-tlsmod17a%.so,$(tlsmod17a-suffixes))
+LDFLAGS_tst-tlsmod18a.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod-at-ctor.so := -shared -static-libgcc -L$(top_builddir)lib
+
+LDFLAGS_tst-tls3 := tst-tlsmod1.so tst-tlsmod4.so
+LDFLAGS_tst-tls4 := -ldl
+LDFLAGS_tst-tls5 := -ldl
+LDFLAGS_tst-tls6 := -ldl
+LDFLAGS_tst-tls7 := -ldl
+LDFLAGS_tst-tls8 := -ldl
+LDFLAGS_tst-tls9 := -ldl
+LDFLAGS_tst-tls10 := -Wl,-rpath-link=. tst-tlsmod8.so
+LDFLAGS_tst-tls11 := -Wl,-rpath-link=. tst-tlsmod10.so
+LDFLAGS_tst-tls12 := -Wl,-rpath-link=. tst-tlsmod12.so
+LDFLAGS_tst-tls13 := -ldl -Wl,-rpath-link=.
+LDFLAGS_tst-tls14 := -ldl -Wl,-rpath-link=. tst-tlsmod14a.so
+LDFLAGS_tst-tls15 := -ldl -Wl,-rpath-link=.
+LDFLAGS_tst-tls16 := -ldl -Wl,-rpath-link=.
+LDFLAGS_tst-tls17 := -ldl -Wl,-rpath-link=.
+LDFLAGS_tst-tls18 := -ldl -Wl,-rpath-link=.
+LDFLAGS_tst-tls-at-ctor := tst-tlsmod-at-ctor.so
+
+tst-tls3: tst-tlsmod1.so tst-tlsmod4.so
+tst-tls4: tst-tlsmod2.so
+tst-tls5: tst-tlsmod2.so
+tst-tls6: tst-tlsmod2.so
+tst-tls7: tst-tlsmod2.so tst-tlsmod3.so
+tst-tls8: tst-tlsmod2.so tst-tlsmod3.so tst-tlsmod4.so
+tst-tls9: tst-tlsmod5.so tst-tlsmod6.so
+tst-tls10: tst-tlsmod7.so tst-tlsmod8.so
+tst-tls11: tst-tlsmod9.so tst-tlsmod10.so
+tst-tls12: tst-tlsmod11.so tst-tlsmod12.so
+tst-tls13: tst-tlsmod13.so tst-tlsmod13a.so
+tst-tls14: tst-tlsmod14a.so tst-tlsmod14b.so
+tst-tls15: tst-tlsmod15b.so
+tst-tls16: tst-tlsmod16a.so tst-tlsmod16b.so
+tst-tls17: tst-tlsmod17b.so
+tst-tlsmod17b.so: $(patsubst %,tst-tlsmod17a%.so,$(tlsmod17a-suffixes))
+tst-tlsmod17a%.so: tst-tlsmod17a.c
+ $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_tst-tlsmod17a.so) $< -o $@ \
+ -DN=$* -Wl,-soname,$@ $(LDFLAGS) $(EXTRA_LIBS) \
+ $(LDFLAGS_tst-tlsmod17a.so)
+tst-tls18: $(patsubst %,tst-tlsmod18a%.so,$(tlsmod18a-suffixes))
+tst-tlsmod18a%.so: tst-tlsmod18a.c
+ $(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_tst-tlsmod18a.so) $< -o $@ \
+ -DN=$* -Wl,-soname,$@ $(LDFLAGS) $(EXTRA_LIBS) \
+ $(LDFLAGS_tst-tlsmod18a.so)
+tst-tls-at-ctor: tst-tlsmod-at-ctor.so
+
+RET_tst-tls13 := 1
+ifeq ($(TARGET_ARCH),mips)
+RET_tst-tls15 := 1
+endif
+
+WRAPPER := env LD_LIBRARY_PATH="$$PWD:.:$(LD_LIBRARY_PATH)"
diff --git a/test/tls/README b/test/tls/README
new file mode 100644
index 000000000..06c9eb743
--- /dev/null
+++ b/test/tls/README
@@ -0,0 +1,8 @@
+These tests were imported from 'glibc/elf' and are responsible for testing
+the TLS functionality of the dynamic loader. The file 'tls-macros-mips.h'
+is a copy of 'glibc/sysdeps/mips/tls-macros.h'. Dependency and link orders
+are critical and should NOT be changed. Even if you think you know what
+you are doing, do not touch the Makefile without posting to the uClibc
+development mailing list.
+
+-Steve <sjhill@uclibc.org>
diff --git a/test/tls/tls-macros-arm.h b/test/tls/tls-macros-arm.h
new file mode 100644
index 000000000..13d0f9752
--- /dev/null
+++ b/test/tls/tls-macros-arm.h
@@ -0,0 +1,51 @@
+#define TLS_LE(x) \
+ ({ int *__result; \
+ void *tp = __builtin_thread_pointer (); \
+ __asm__ ("ldr %0, 1f; " \
+ "add %0, %1, %0; " \
+ "b 2f; " \
+ "1: .word " #x "(tpoff); " \
+ "2: " \
+ : "=&r" (__result) : "r" (tp)); \
+ __result; })
+
+#define TLS_IE(x) \
+ ({ int *__result; \
+ void *tp = __builtin_thread_pointer (); \
+ __asm__ ("ldr %0, 1f; " \
+ "3: ldr %0, [pc, %0];" \
+ "add %0, %1, %0; " \
+ "b 2f; " \
+ "1: .word " #x "(gottpoff) + (. - 3b - 8); " \
+ "2: " \
+ : "=&r" (__result) : "r" (tp)); \
+ __result; })
+
+#define TLS_LD(x) \
+ ({ char *__result; \
+ int __offset; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("ldr %0, 2f; " \
+ "1: add %0, pc, %0; " \
+ "b 3f; " \
+ "2: .word " #x "(tlsldm) + (. - 1b - 8); " \
+ "3: " \
+ : "=r" (__result)); \
+ __result = (char *)__tls_get_addr (__result); \
+ __asm__ ("ldr %0, 1f; " \
+ "b 2f; " \
+ "1: .word " #x "(tlsldo); " \
+ "2: " \
+ : "=r" (__offset)); \
+ (int *) (__result + __offset); })
+
+#define TLS_GD(x) \
+ ({ int *__result; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("ldr %0, 2f; " \
+ "1: add %0, pc, %0; " \
+ "b 3f; " \
+ "2: .word " #x "(tlsgd) + (. - 1b - 8); " \
+ "3: " \
+ : "=r" (__result)); \
+ (int *)__tls_get_addr (__result); })
diff --git a/test/tls/tls-macros-mips.h b/test/tls/tls-macros-mips.h
new file mode 100644
index 000000000..0db383032
--- /dev/null
+++ b/test/tls/tls-macros-mips.h
@@ -0,0 +1,88 @@
+/* Macros to support TLS testing in times of missing compiler support. */
+
+#if _MIPS_SIM != _ABI64
+
+/* These versions are for o32 and n32. */
+
+# define TLS_GD(x) \
+ ({ void *__result; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("addiu %0, $28, %%tlsgd(" #x ")" \
+ : "=r" (__result)); \
+ (int *)__tls_get_addr (__result); })
+#else
+# define TLS_GD(x) \
+ ({ void *__result; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("daddiu %0, $28, %%tlsgd(" #x ")" \
+ : "=r" (__result)); \
+ (int *)__tls_get_addr (__result); })
+#endif
+
+#if _MIPS_SIM != _ABI64
+# define TLS_LD(x) \
+ ({ void *__result; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("addiu %0, $28, %%tlsldm(" #x ")" \
+ : "=r" (__result)); \
+ __result = __tls_get_addr (__result); \
+ __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
+ "addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
+ "addu %0,%0,$3" \
+ : "+r" (__result) : : "$3"); \
+ __result; })
+# define TLS_IE(x) \
+ ({ void *__result; \
+ __asm__ (".set push\n\t.set mips32r2\n\t" \
+ "rdhwr\t%0,$29\n\t.set pop" \
+ : "=v" (__result)); \
+ __asm__ ("lw $3,%%gottprel(" #x ")($28)\n\t" \
+ "addu %0,%0,$3" \
+ : "+r" (__result) : : "$3"); \
+ __result; })
+# define TLS_LE(x) \
+ ({ void *__result; \
+ __asm__ (".set push\n\t.set mips32r2\n\t" \
+ "rdhwr\t%0,$29\n\t.set pop" \
+ : "=v" (__result)); \
+ __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
+ "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
+ "addu %0,%0,$3" \
+ : "+r" (__result) : : "$3"); \
+ __result; })
+
+#else
+
+/* These versions are for n64. */
+
+# define TLS_LD(x) \
+ ({ void *__result; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("daddiu %0, $28, %%tlsldm(" #x ")" \
+ : "=r" (__result)); \
+ __result = __tls_get_addr (__result); \
+ __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
+ "daddiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
+ "daddu %0,%0,$3" \
+ : "+r" (__result) : : "$3"); \
+ __result; })
+# define TLS_IE(x) \
+ ({ void *__result; \
+ __asm__ (".set push\n\t.set mips32r2\n\t" \
+ "rdhwr\t%0,$29\n\t.set pop" \
+ : "=v" (__result)); \
+ __asm__ ("ld $3,%%gottprel(" #x ")($28)\n\t" \
+ "daddu %0,%0,$3" \
+ : "+r" (__result) : : "$3"); \
+ __result; })
+# define TLS_LE(x) \
+ ({ void *__result; \
+ __asm__ (".set push\n\t.set mips32r2\n\t" \
+ "rdhwr\t%0,$29\n\t.set pop" \
+ : "=v" (__result)); \
+ __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
+ "daddiu $3,$3,%%tprel_lo(" #x ")\n\t" \
+ "daddu %0,%0,$3" \
+ : "+r" (__result) : : "$3"); \
+ __result; })
+#endif
diff --git a/test/tls/tls-macros-thumb.h b/test/tls/tls-macros-thumb.h
new file mode 100644
index 000000000..dfa6582a5
--- /dev/null
+++ b/test/tls/tls-macros-thumb.h
@@ -0,0 +1,57 @@
+#define TLS_LE(x) \
+ ({ int *__result; \
+ void *tp = __builtin_thread_pointer (); \
+ __asm__ ("ldr %0, 1f; " \
+ "add %0, %1, %0; " \
+ "b 2f; " \
+ ".align 2; " \
+ "1: .word " #x "(tpoff); " \
+ "2: " \
+ : "=&r" (__result) : "r" (tp)); \
+ __result; })
+
+#define TLS_IE(x) \
+ ({ int *__result; \
+ int tmp; \
+ void *tp = __builtin_thread_pointer (); \
+ __asm__ ("ldr %0, 1f; " \
+ "adr %1, 1f; " \
+ "ldr %0, [%1, %0]; " \
+ "add %0, %2, %0; " \
+ "b 2f; " \
+ ".align 2; " \
+ "1: .word " #x "(gottpoff); " \
+ "2: " \
+ : "=&r" (__result), "=&r"(tmp) : "r" (tp)); \
+ __result; })
+
+#define TLS_LD(x) \
+ ({ char *__result; \
+ int __offset; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("ldr %0, 2f; " \
+ ".align 2; " \
+ "1: add %0, pc, %0; " \
+ "b 3f; " \
+ "2: .word " #x "(tlsldm) + (. - 1b - 4); " \
+ "3: " \
+ : "=r" (__result)); \
+ __result = (char *)__tls_get_addr (__result); \
+ __asm__ ("ldr %0, 1f; " \
+ "b 2f; " \
+ "1: .word " #x "(tlsldo); " \
+ "2: " \
+ : "=r" (__offset)); \
+ (int *) (__result + __offset); })
+
+#define TLS_GD(x) \
+ ({ int *__result; \
+ extern void *__tls_get_addr (void *); \
+ __asm__ ("ldr %0, 2f; " \
+ ".align 2; " \
+ "1: add %0, pc, %0; " \
+ "b 3f; " \
+ "2: .word " #x "(tlsgd) + (. - 1b - 4); " \
+ "3: " \
+ : "=r" (__result)); \
+ (int *)__tls_get_addr (__result); })
diff --git a/test/tls/tls-macros.h b/test/tls/tls-macros.h
new file mode 100644
index 000000000..cd31100cf
--- /dev/null
+++ b/test/tls/tls-macros.h
@@ -0,0 +1,861 @@
+/* Macros to support TLS testing in times of missing compiler support. */
+
+#define COMMON_INT_DEF(x) \
+ __asm__ (".tls_common " #x ",4,4")
+/* XXX Until we get compiler support we don't need declarations. */
+#define COMMON_INT_DECL(x)
+
+/* XXX This definition will probably be machine specific, too. */
+#define VAR_INT_DEF(x) \
+ __asm__ (".section .tdata\n\t" \
+ ".globl " #x "\n" \
+ ".balign 4\n" \
+ #x ":\t.long 0\n\t" \
+ ".size " #x ",4\n\t" \
+ ".previous")
+/* XXX Until we get compiler support we don't need declarations. */
+#define VAR_INT_DECL(x)
+
+#ifdef __mips__
+#include <tls-macros-mips.h>
+#endif
+
+#ifdef __arm__
+#ifdef __thumb__
+#include <tls-macros-thumb.h>
+#else
+#include <tls-macros-arm.h>
+#endif
+#endif
+
+ /* XXX Each architecture must have its own asm for now. */
+#ifdef __i386__
+# define TLS_LE(x) \
+ ({ int *__l; \
+ __asm__ ("movl %%gs:0,%0\n\t" \
+ "subl $" #x "@tpoff,%0" \
+ : "=r" (__l)); \
+ __l; })
+
+# ifdef PIC
+# define TLS_IE(x) \
+ ({ int *__l; \
+ __asm__ ("movl %%gs:0,%0\n\t" \
+ "subl " #x "@gottpoff(%%ebx),%0" \
+ : "=r" (__l)); \
+ __l; })
+# else
+# define TLS_IE(x) \
+ ({ int *__l; \
+ __asm__ ("call 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tmovl (%%esp), %%ebx\n\t" \
+ "ret\n\t" \
+ ".previous\n\t" \
+ "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
+ "movl %%gs:0,%0\n\t" \
+ "subl " #x "@gottpoff(%%ebx),%0" \
+ : "=r" (__l)); \
+ __l; })
+# endif
+
+# ifdef PIC
+# define TLS_LD(x) \
+ ({ int *__l, __c, __d; \
+ __asm__ ("leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
+ "call ___tls_get_addr@plt\n\t" \
+ "leal " #x "@dtpoff(%%eax), %%eax" \
+ : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
+ __l; })
+# else
+# define TLS_LD(x) \
+ ({ int *__l, __b, __c, __d; \
+ __asm__ ("call 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tmovl (%%esp), %%ebx\n\t" \
+ "ret\n\t" \
+ ".previous\n\t" \
+ "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
+ "leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
+ "call ___tls_get_addr@plt\n\t" \
+ "leal " #x "@dtpoff(%%eax), %%eax" \
+ : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
+ __l; })
+# endif
+
+# ifdef PIC
+# define TLS_GD(x) \
+ ({ int *__l, __c, __d; \
+ __asm__ ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
+ "call ___tls_get_addr@plt\n\t" \
+ "nop" \
+ : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
+ __l; })
+# else
+# define TLS_GD(x) \
+ ({ int *__l, __c, __d; \
+ __asm__ ("call 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tmovl (%%esp), %%ebx\n\t" \
+ "ret\n\t" \
+ ".previous\n\t" \
+ "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
+ "leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
+ "call ___tls_get_addr@plt\n\t" \
+ "nop" \
+ : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
+ __l; })
+# endif
+
+#elif defined __x86_64__
+
+# define TLS_LE(x) \
+ ({ int *__l; \
+ __asm__ ("movq %%fs:0,%0\n\t" \
+ "leaq " #x "@tpoff(%0), %0" \
+ : "=r" (__l)); \
+ __l; })
+
+# define TLS_IE(x) \
+ ({ int *__l; \
+ __asm__ ("movq %%fs:0,%0\n\t" \
+ "addq " #x "@gottpoff(%%rip),%0" \
+ : "=r" (__l)); \
+ __l; })
+
+# define TLS_LD(x) \
+ ({ int *__l, __c, __d; \
+ __asm__ ("leaq " #x "@tlsld(%%rip),%%rdi\n\t" \
+ "call __tls_get_addr@plt\n\t" \
+ "leaq " #x "@dtpoff(%%rax), %%rax" \
+ : "=a" (__l), "=&c" (__c), "=&d" (__d) \
+ : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
+ __l; })
+
+# define TLS_GD(x) \
+ ({ int *__l, __c, __d; \
+ __asm__ (".byte 0x66\n\t" \
+ "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
+ ".word 0x6666\n\t" \
+ "rex64\n\t" \
+ "call __tls_get_addr@plt" \
+ : "=a" (__l), "=&c" (__c), "=&d" (__d) \
+ : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
+ __l; })
+
+#elif defined __sh__
+
+# define TLS_LE(x) \
+ ({ int *__l; void *__tp; \
+ __asm__ ("stc gbr,%1\n\t" \
+ "mov.l 1f,%0\n\t" \
+ "bra 2f\n\t" \
+ " add %1,%0\n\t" \
+ ".align 2\n\t" \
+ "1: .long " #x "@tpoff\n\t" \
+ "2:" \
+ : "=r" (__l), "=r" (__tp)); \
+ __l; })
+
+# ifdef PIC
+# define TLS_IE(x) \
+ ({ int *__l; void *__tp; \
+ register void *__gp __asm__("r12"); \
+ __asm__ ("mov.l 1f,r0\n\t" \
+ "stc gbr,%1\n\t" \
+ "mov.l @(r0,r12),%0\n\t" \
+ "bra 2f\n\t" \
+ " add %1,%0\n\t" \
+ ".align 2\n\t" \
+ "1: .long " #x "@gottpoff\n\t" \
+ "2:" \
+ : "=r" (__l), "=r" (__tp) : "r" (__gp) : "r0"); \
+ __l; })
+# else
+# define TLS_IE(x) \
+ ({ int *__l; void *__tp; \
+ __asm__ ("mov.l r12,@-r15\n\t" \
+ "mova 0f,r0\n\t" \
+ "mov.l 0f,r12\n\t" \
+ "add r0,r12\n\t" \
+ "mov.l 1f,r0\n\t" \
+ "stc gbr,%1\n\t" \
+ "mov.l @(r0,r12),%0\n\t" \
+ "bra 2f\n\t" \
+ " add %1,%0\n\t" \
+ ".align 2\n\t" \
+ "1: .long " #x "@gottpoff\n\t" \
+ "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
+ "2: mov.l @r15+,r12" \
+ : "=r" (__l), "=r" (__tp) : : "r0"); \
+ __l; })
+#endif
+
+# ifdef PIC
+# define TLS_LD(x) \
+ ({ int *__l; \
+ register void *__gp __asm__("r12"); \
+ __asm__ ("mov.l 1f,r4\n\t" \
+ "mova 2f,r0\n\t" \
+ "mov.l 2f,r1\n\t" \
+ "add r0,r1\n\t" \
+ "jsr @r1\n\t" \
+ " add r12,r4\n\t" \
+ "bra 4f\n\t" \
+ " nop\n\t" \
+ ".align 2\n\t" \
+ "1: .long " #x "@tlsldm\n\t" \
+ "2: .long __tls_get_addr@plt\n\t" \
+ "4: mov.l 3f,%0\n\t" \
+ "bra 5f\n\t" \
+ " add r0,%0\n\t" \
+ ".align 2\n\t" \
+ "3: .long " #x "@dtpoff\n\t" \
+ "5:" \
+ : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
+ "r6", "r7", "pr", "t"); \
+ __l; })
+# else
+# define TLS_LD(x) \
+ ({ int *__l; \
+ __asm__ ("mov.l r12,@-r15\n\t" \
+ "mova 0f,r0\n\t" \
+ "mov.l 0f,r12\n\t" \
+ "add