summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordfr <dfr@FreeBSD.org>2004-08-03 09:04:01 +0000
committerdfr <dfr@FreeBSD.org>2004-08-03 09:04:01 +0000
commitc5d9c3618efa06abd292cabeea45abf2d8f73b14 (patch)
tree799306d40d41245260af360416589ca5c07e375f /tools
parentaedc433cf36288de98437f3d9a41b9380f81a498 (diff)
downloadFreeBSD-src-c5d9c3618efa06abd292cabeea45abf2d8f73b14.zip
FreeBSD-src-c5d9c3618efa06abd292cabeea45abf2d8f73b14.tar.gz
Add regression tests for TLS.
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/tls/Makefile9
-rw-r--r--tools/regression/tls/Makefile.inc1
-rw-r--r--tools/regression/tls/libxx/Makefile10
-rw-r--r--tools/regression/tls/libxx/xx.c12
-rw-r--r--tools/regression/tls/libyy/Makefile10
-rw-r--r--tools/regression/tls/libyy/yy.c3
-rw-r--r--tools/regression/tls/ttls1/Makefile12
-rw-r--r--tools/regression/tls/ttls1/ttls1.c15
-rw-r--r--tools/regression/tls/ttls2/Makefile14
-rw-r--r--tools/regression/tls/ttls2/ttls2.c36
-rw-r--r--tools/regression/tls/ttls3/Makefile24
-rw-r--r--tools/regression/tls/ttls3/elftls.S114
-rw-r--r--tools/regression/tls/ttls3/tls-test-lib.c110
-rw-r--r--tools/regression/tls/ttls3/tls-test.c59
14 files changed, 429 insertions, 0 deletions
diff --git a/tools/regression/tls/Makefile b/tools/regression/tls/Makefile
new file mode 100644
index 0000000..aea3025
--- /dev/null
+++ b/tools/regression/tls/Makefile
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+SUBDIR=libxx libyy ttls1 ttls2
+
+.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 0000000..7f4acd0
--- /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 0000000..b3fe79e
--- /dev/null
+++ b/tools/regression/tls/libxx/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+LIB= xx
+SHLIB_MAJOR= 1
+
+SRCS= xx.c
+#CFLAGS+=-mtls-dialect=sun
+NOMAN= t
+
+.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 0000000..6d1e73f
--- /dev/null
+++ b/tools/regression/tls/libxx/xx.c
@@ -0,0 +1,12 @@
+/* $FreeBSD$ */
+
+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 0000000..c425977
--- /dev/null
+++ b/tools/regression/tls/libyy/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+LIB= yy
+SHLIB_MAJOR= 1
+
+SRCS= yy.c
+CFLAGS+=-fpic
+NOMAN= t
+
+.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 0000000..c00cb87
--- /dev/null
+++ b/tools/regression/tls/libyy/yy.c
@@ -0,0 +1,3 @@
+/* $FreeBSD$ */
+
+int __thread yy1 = 101;
diff --git a/tools/regression/tls/ttls1/Makefile b/tools/regression/tls/ttls1/Makefile
new file mode 100644
index 0000000..ef451b7
--- /dev/null
+++ b/tools/regression/tls/ttls1/Makefile
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+PROG= ttls1
+LDADD+= -L../libxx -lxx -Wl,--rpath=${.CURDIR}/../libxx
+LDADD+= -L../libyy -lyy -Wl,--rpath=${.CURDIR}/../libyy
+LDADD+= -L${.CURDIR}/../../../../lib/libc -lc
+LDADD+= -Wl,--rpath=${.CURDIR}/../../../../lib/libc
+LDADD+= -Wl,--dynamic-linker=${.CURDIR}/../../../../libexec/rtld-elf/ld-elf.so.1
+NOMAN= t
+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 0000000..2967ebc
--- /dev/null
+++ b/tools/regression/tls/ttls1/ttls1.c
@@ -0,0 +1,15 @@
+/* $FreeBSD$
+
+#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 0000000..584bf42
--- /dev/null
+++ b/tools/regression/tls/ttls2/Makefile
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+PROG= ttls2
+LDADD+= -lpthread
+LDADD+= -Wl,--rpath=${.CURDIR}/../../../../lib/libpthread
+#LDADD+= -lthr
+#LDADD+= -Wl,--rpath=${.CURDIR}/../../../../lib/libthr
+LDADD+= -L${.CURDIR}/../../../../lib/libc -lc
+LDADD+= -Wl,--rpath=${.CURDIR}/../../../../lib/libc
+LDADD+= -Wl,--dynamic-linker=${.CURDIR}/../../../../libexec/rtld-elf/ld-elf.so.1
+NOMAN= t
+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 0000000..f528e3d
--- /dev/null
+++ b/tools/regression/tls/ttls2/ttls2.c
@@ -0,0 +1,36 @@
+/* $FreeBSD$ */
+
+#include <stdio.h>
+#include <pthread.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);
+ }
+}
+
+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);
+ }
+}
+
+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);
+}
diff --git a/tools/regression/tls/ttls3/Makefile b/tools/regression/tls/ttls3/Makefile
new file mode 100644
index 0000000..fece4cb
--- /dev/null
+++ b/tools/regression/tls/ttls3/Makefile
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+all: ttls3
+
+LDFLAGS=-shared -Bsymbolic --allow-shlib-undefined
+CFLAGS+= -L${.CURDIR}/../../../../lib/libc -lc -lthr
+CFLAGS+= -Wl,--rpath=${.CURDIR}/../../../../lib/libc
+CFLAGS+= -Wl,--rpath=${.OBJDIR}
+CFLAGS+= -Wl,--dynamic-linker=${.CURDIR}/../../../../libexec/rtld-elf/ld-elf.so.1
+
+tls-lib: elftls.S
+ gcc -c -o elftls.o 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 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 tls-test.c
+
+clean:
+ rm -f *.o libtls.so* libtls-test.so* ttls3
diff --git a/tools/regression/tls/ttls3/elftls.S b/tools/regression/tls/ttls3/elftls.S
new file mode 100644
index 0000000..0fad08d
--- /dev/null
+++ b/tools/regression/tls/ttls3/elftls.S
@@ -0,0 +1,114 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+.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 0000000..bc88ad1
--- /dev/null
+++ b/tools/regression/tls/ttls3/tls-test-lib.c
@@ -0,0 +1,110 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#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 0000000..539b6ce
--- /dev/null
+++ b/tools/regression/tls/ttls3/tls-test.c
@@ -0,0 +1,59 @@
+/*-
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#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;
+}
OpenPOWER on IntegriCloud