aboutsummaryrefslogtreecommitdiff
path: root/tools/regression/tls
diff options
context:
space:
mode:
Diffstat (limited to 'tools/regression/tls')
-rw-r--r--tools/regression/tls/Makefile7
-rw-r--r--tools/regression/tls/Makefile.inc1
-rw-r--r--tools/regression/tls/libxx/Makefile6
-rw-r--r--tools/regression/tls/libxx/xx.c11
-rw-r--r--tools/regression/tls/libyy/Makefile6
-rw-r--r--tools/regression/tls/libyy/yy.c2
-rw-r--r--tools/regression/tls/ttls1/Makefile7
-rw-r--r--tools/regression/tls/ttls1/ttls1.c14
-rw-r--r--tools/regression/tls/ttls2/Makefile6
-rw-r--r--tools/regression/tls/ttls2/ttls2.c41
-rw-r--r--tools/regression/tls/ttls3/Makefile22
-rw-r--r--tools/regression/tls/ttls3/elftls.S112
-rw-r--r--tools/regression/tls/ttls3/tls-test-lib.c108
-rw-r--r--tools/regression/tls/ttls3/tls-test.c57
-rw-r--r--tools/regression/tls/ttls4/Makefile6
-rw-r--r--tools/regression/tls/ttls4/ttls4.c42
16 files changed, 448 insertions, 0 deletions
diff --git a/tools/regression/tls/Makefile b/tools/regression/tls/Makefile
new file mode 100644
index 000000000000..063e3dec7d8d
--- /dev/null
+++ b/tools/regression/tls/Makefile
@@ -0,0 +1,7 @@
+SUBDIR=libxx libyy ttls1 ttls2 ttls4
+
+.if ${MACHINE_ARCH} == "i386"
+SUBDIR+=ttls3
+.endif
+
+.include <bsd.subdir.mk>
diff --git a/tools/regression/tls/Makefile.inc b/tools/regression/tls/Makefile.inc
new file mode 100644
index 000000000000..7f4acd0a43d0
--- /dev/null
+++ b/tools/regression/tls/Makefile.inc
@@ -0,0 +1 @@
+#CFLAGS+= -mno-tls-direct-seg-refs
diff --git a/tools/regression/tls/libxx/Makefile b/tools/regression/tls/libxx/Makefile
new file mode 100644
index 000000000000..18195384ad9c
--- /dev/null
+++ b/tools/regression/tls/libxx/Makefile
@@ -0,0 +1,6 @@
+SHLIB_NAME= libxx.so
+
+SRCS= xx.c
+#CFLAGS+=-mtls-dialect=sun
+
+.include <bsd.lib.mk>
diff --git a/tools/regression/tls/libxx/xx.c b/tools/regression/tls/libxx/xx.c
new file mode 100644
index 000000000000..bc81531e2ce0
--- /dev/null
+++ b/tools/regression/tls/libxx/xx.c
@@ -0,0 +1,11 @@
+
+extern int __thread yy1;
+int __thread xx1 = 1;
+int __thread xx2 = 2;
+int __thread xxa[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+int
+xxyy()
+{
+ return yy1;
+}
diff --git a/tools/regression/tls/libyy/Makefile b/tools/regression/tls/libyy/Makefile
new file mode 100644
index 000000000000..05ecfc735c62
--- /dev/null
+++ b/tools/regression/tls/libyy/Makefile
@@ -0,0 +1,6 @@
+SHLIB_NAME= libyy.so
+
+SRCS= yy.c
+CFLAGS+=-fpic
+
+.include <bsd.lib.mk>
diff --git a/tools/regression/tls/libyy/yy.c b/tools/regression/tls/libyy/yy.c
new file mode 100644
index 000000000000..e7265829b93a
--- /dev/null
+++ b/tools/regression/tls/libyy/yy.c
@@ -0,0 +1,2 @@
+
+int __thread yy1 = 101;
diff --git a/tools/regression/tls/ttls1/Makefile b/tools/regression/tls/ttls1/Makefile
new file mode 100644
index 000000000000..8560de58cc9a
--- /dev/null
+++ b/tools/regression/tls/ttls1/Makefile
@@ -0,0 +1,7 @@
+PROG= ttls1
+LDFLAGS+= -L../libxx -lxx -Wl,--rpath=${.OBJDIR}/../libxx
+LDFLAGS+= -L../libyy -lyy -Wl,--rpath=${.OBJDIR}/../libyy
+MAN=
+DEBUG_FLAGS= -g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/tls/ttls1/ttls1.c b/tools/regression/tls/ttls1/ttls1.c
new file mode 100644
index 000000000000..24e4b1636e7d
--- /dev/null
+++ b/tools/regression/tls/ttls1/ttls1.c
@@ -0,0 +1,14 @@
+
+#include <stdio.h>
+
+extern int __thread xx1;
+extern int __thread xx2;
+extern int __thread xxa[];
+int __thread a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+extern int xxyy();
+
+int main(int argc, char** argv)
+{
+ printf("xx1=%d, xx2=%d, xxa[5]=%d, a[5]=%d, xxyy()=%d\n",
+ xx1, xx2, xxa[5], a[5], xxyy());
+}
diff --git a/tools/regression/tls/ttls2/Makefile b/tools/regression/tls/ttls2/Makefile
new file mode 100644
index 000000000000..782808823efe
--- /dev/null
+++ b/tools/regression/tls/ttls2/Makefile
@@ -0,0 +1,6 @@
+PROG= ttls2
+LIBADD= pthread
+MAN=
+DEBUG_FLAGS= -g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/tls/ttls2/ttls2.c b/tools/regression/tls/ttls2/ttls2.c
new file mode 100644
index 000000000000..6fe316e15128
--- /dev/null
+++ b/tools/regression/tls/ttls2/ttls2.c
@@ -0,0 +1,41 @@
+
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int __thread i;
+
+void *
+foo1(void *arg)
+{
+ printf("thread %p, &i = %p\n", pthread_self(), &i);
+ for (i = 0; i < 10; i++) {
+ printf("thread %p, i = %d\n", pthread_self(), i);
+ sleep(1);
+ }
+ return (NULL);
+}
+
+void *
+foo2(void *arg)
+{
+ printf("thread %p, &i = %p\n", pthread_self(), &i);
+ for (i = 10; i > 0; i--) {
+ printf("thread %p, i = %d\n", pthread_self(), i);
+ sleep(1);
+ }
+ return (NULL);
+}
+
+int
+main(int argc, char** argv)
+{
+ pthread_t t1, t2;
+
+ pthread_create(&t1, 0, foo1, 0);
+ pthread_create(&t2, 0, foo2, 0);
+ pthread_join(t1, 0);
+ pthread_join(t2, 0);
+
+ return (0);
+}
diff --git a/tools/regression/tls/ttls3/Makefile b/tools/regression/tls/ttls3/Makefile
new file mode 100644
index 000000000000..03413ea8e1d6
--- /dev/null
+++ b/tools/regression/tls/ttls3/Makefile
@@ -0,0 +1,22 @@
+all: ttls3
+
+LDFLAGS+=-shared -Bsymbolic --allow-shlib-undefined
+CFLAGS+= -lpthread
+CFLAGS+= -Wl,--rpath=${.OBJDIR}
+
+tls-lib: elftls.S
+ gcc -c -o elftls.o ${.CURDIR}/elftls.S
+ ld $(LDFLAGS) elftls.o -soname libtls.so.1 -o libtls.so.1
+ ln -sf libtls.so.1 libtls.so
+
+tls-test-lib: tls-lib tls-test-lib.c
+ gcc -c -o tls-test.o ${.CURDIR}/tls-test-lib.c
+ ld $(LDFLAGS) tls-test.o libtls.so.1 -rpath=${.OBJDIR} -soname libtls-test.so.1 -o libtls-test.so.1
+
+ttls3: tls-test-lib tls-test.c
+ gcc $(CFLAGS) -rdynamic -o ttls3 ${.CURDIR}/tls-test.c
+
+clean:
+ rm -f *.o libtls.so* libtls-test.so* ttls3
+
+.include <bsd.obj.mk>
diff --git a/tools/regression/tls/ttls3/elftls.S b/tools/regression/tls/ttls3/elftls.S
new file mode 100644
index 000000000000..b13d286c264c
--- /dev/null
+++ b/tools/regression/tls/ttls3/elftls.S
@@ -0,0 +1,112 @@
+/*-
+ * Copyright (C) 2004 NVIDIA Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+.file "elftls.S"
+
+.globl __gl_tls_offsets
+ .type __gl_tls_offsets,@object
+
+.section .tbss,"awT",@nobits
+
+.globl __gl_tls_var0
+ .align 4
+ .type __gl_tls_var0, @object
+ .size __gl_tls_var0, 4
+__gl_tls_var0:
+ .zero 4
+
+.globl __gl_tls_var1
+ .align 4
+ .type __gl_tls_var1, @object
+ .size __gl_tls_var1, 4
+__gl_tls_var1:
+ .zero 4
+
+.globl __gl_tls_var2
+ .align 4
+ .type __gl_tls_var2, @object
+ .size __gl_tls_var2, 4
+__gl_tls_var2:
+ .zero 4
+
+.globl __gl_tls_var3
+ .align 4
+ .type __gl_tls_var3, @object
+ .size __gl_tls_var3, 4
+__gl_tls_var3:
+ .zero 4
+
+.globl __gl_tls_var4
+ .align 4
+ .type __gl_tls_var4, @object
+ .size __gl_tls_var4, 4
+__gl_tls_var4:
+ .zero 4
+
+.globl __gl_tls_var5
+ .align 4
+ .type __gl_tls_var5, @object
+ .size __gl_tls_var5, 4
+__gl_tls_var5:
+ .zero 4
+
+.globl __gl_tls_var6
+ .align 4
+ .type __gl_tls_var6, @object
+ .size __gl_tls_var6, 4
+__gl_tls_var6:
+ .zero 4
+
+.globl __gl_tls_var7
+ .align 4
+ .type __gl_tls_var7, @object
+ .size __gl_tls_var7, 4
+__gl_tls_var7:
+ .zero 4
+
+.text
+ .p2align 4,,15
+.globl __gl_tls_init_offsets
+ .type __gl_tls_init_offsets, @function
+__gl_tls_init_offsets:
+ movl $__gl_tls_offsets, %eax
+ movl $__gl_tls_var0@ntpoff, %ecx
+ movl %ecx, 0(%eax)
+ movl $__gl_tls_var1@ntpoff, %ecx
+ movl %ecx, 4(%eax)
+ movl $__gl_tls_var2@ntpoff, %ecx
+ movl %ecx, 8(%eax)
+ movl $__gl_tls_var3@ntpoff, %ecx
+ movl %ecx, 12(%eax)
+ movl $__gl_tls_var4@ntpoff, %ecx
+ movl %ecx, 16(%eax)
+ movl $__gl_tls_var5@ntpoff, %ecx
+ movl %ecx, 20(%eax)
+ movl $__gl_tls_var6@ntpoff, %ecx
+ movl %ecx, 24(%eax)
+ movl $__gl_tls_var7@ntpoff, %ecx
+ movl %ecx, 28(%eax)
+ ret
diff --git a/tools/regression/tls/ttls3/tls-test-lib.c b/tools/regression/tls/ttls3/tls-test-lib.c
new file mode 100644
index 000000000000..ebdd27c83302
--- /dev/null
+++ b/tools/regression/tls/ttls3/tls-test-lib.c
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (C) 2004 NVIDIA Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#define __G_TLS_OFFSETS_SIZE 8
+unsigned long int __gl_tls_offsets[__G_TLS_OFFSETS_SIZE];
+
+void __gl_tls_init_offsets();
+
+#ifdef __GL_TLS_SINGLE_INSTRUCTION
+#define THREAD_GETMEM(num) \
+({ \
+ void *__value; \
+ __asm__ __volatile__ ( \
+ "movl %%gs:(%1),%0" \
+ : "=r" (__value) \
+ : "r" (__gl_tls_offsets[num]) \
+ ); \
+ __value; \
+})
+
+#define THREAD_SETMEM(num, value) \
+do { \
+ void *__value = (value); \
+ __asm__ __volatile__ ( \
+ "movl %0,%%gs:(%1)" \
+ : \
+ : "r" (__value), \
+ "r" (__gl_tls_offsets[num]) \
+ ); \
+} while (0)
+#else
+#define __GL_TLS_GET(num) \
+({ \
+ void *__dummy, *__value; \
+ __asm__ __volatile__ ( \
+ "movl %%gs:0,%2 \n\t" \
+ "movl (%2,%1),%0 \n\t" \
+ : "=r" (__value) \
+ : "r" (__gl_tls_offsets[num]), \
+ "r" (__dummy) \
+ ); \
+ __value; \
+})
+
+#define __GL_TLS_SET(num, value) \
+do { \
+ void *__dummy, *__value = (value); \
+ __asm__ __volatile__ ( \
+ "movl %%gs:0,%2 \n\t" \
+ "movl %0,(%2,%1) \n\t" \
+ : \
+ : "r" (__value), \
+ "r" (__gl_tls_offsets[num]), \
+ "r" (__dummy) \
+ ); \
+} while (0)
+#endif
+
+void _init(void)
+{
+ __gl_tls_init_offsets();
+
+ __GL_TLS_SET(0, (void *) 0xff000000);
+ __GL_TLS_SET(1, (void *) 0xff000001);
+ __GL_TLS_SET(2, (void *) 0xff000002);
+ __GL_TLS_SET(3, (void *) 0xff000003);
+ __GL_TLS_SET(4, (void *) 0xff000004);
+ __GL_TLS_SET(5, (void *) 0xff000005);
+ __GL_TLS_SET(6, (void *) 0xff000006);
+ __GL_TLS_SET(7, (void *) 0xff000007);
+}
+
+void __gl_tls_test(void)
+{
+ printf("__GL_TLS_GET(0) = %p\n", __GL_TLS_GET(0));
+ printf("__GL_TLS_GET(1) = %p\n", __GL_TLS_GET(1));
+ printf("__GL_TLS_GET(2) = %p\n", __GL_TLS_GET(2));
+ printf("__GL_TLS_GET(3) = %p\n", __GL_TLS_GET(3));
+ printf("__GL_TLS_GET(4) = %p\n", __GL_TLS_GET(4));
+ printf("__GL_TLS_GET(5) = %p\n", __GL_TLS_GET(5));
+ printf("__GL_TLS_GET(6) = %p\n", __GL_TLS_GET(6));
+ printf("__GL_TLS_GET(7) = %p\n", __GL_TLS_GET(7));
+}
diff --git a/tools/regression/tls/ttls3/tls-test.c b/tools/regression/tls/ttls3/tls-test.c
new file mode 100644
index 000000000000..0f2c3fdb79f3
--- /dev/null
+++ b/tools/regression/tls/ttls3/tls-test.c
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (C) 2004 NVIDIA Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <dlfcn.h>
+
+int main(int argc, char **argv)
+{
+ void *handle;
+ void (*__gl_tls_test)(void);
+ const char *error;
+
+ handle = dlopen("libtls-test.so.1", RTLD_NOW);
+ if (!handle) {
+ error = dlerror();
+ printf("dlopen failed (%s)!\n", error);
+ exit(1);
+ }
+
+ dlerror();
+ __gl_tls_test = dlsym(handle, "__gl_tls_test");
+ error = dlerror();
+
+ if (error) {
+ dlclose(handle);
+ printf("dlsym failed (%s)!\n", error);
+ exit(1);
+ }
+
+ __gl_tls_test(); /* print TLS values */
+ dlclose(handle);
+
+ return 0;
+}
diff --git a/tools/regression/tls/ttls4/Makefile b/tools/regression/tls/ttls4/Makefile
new file mode 100644
index 000000000000..b87343ecdd00
--- /dev/null
+++ b/tools/regression/tls/ttls4/Makefile
@@ -0,0 +1,6 @@
+PROG= ttls4
+LIBADD= pthread
+MAN=
+DEBUG_FLAGS= -g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/tls/ttls4/ttls4.c b/tools/regression/tls/ttls4/ttls4.c
new file mode 100644
index 000000000000..60cd91d4542a
--- /dev/null
+++ b/tools/regression/tls/ttls4/ttls4.c
@@ -0,0 +1,42 @@
+/*
+ * This program tests if a new thread's initial tls data
+ * is clean.
+ *
+ * David Xu <davidxu@freebsd.org>
+ */
+
+#include <stdio.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int __thread n;
+
+void
+*f1(void *arg)
+{
+ if (n != 0) {
+ printf("bug, n == %d \n", n);
+ exit(1);
+ }
+ n = 1;
+ return (0);
+}
+
+int
+main(void)
+{
+ pthread_t td;
+ int i;
+
+ for (i = 0; i < 1000; ++i) {
+ pthread_create(&td, NULL, f1, NULL);
+ pthread_join(td, NULL);
+ }
+ sleep(2);
+ for (i = 0; i < 1000; ++i) {
+ pthread_create(&td, NULL, f1, NULL);
+ pthread_join(td, NULL);
+ }
+ return (0);
+}