add __tls_get_new regression test
authorSzabolcs Nagy <nsz@port70.net>
Wed, 25 Nov 2015 23:03:59 +0000 (23:03 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Wed, 25 Nov 2015 23:03:59 +0000 (23:03 +0000)
src/regression/tls_get_new-dtv.c [new file with mode: 0644]
src/regression/tls_get_new-dtv_dso.c [new file with mode: 0644]

diff --git a/src/regression/tls_get_new-dtv.c b/src/regression/tls_get_new-dtv.c
new file mode 100644 (file)
index 0000000..a183fff
--- /dev/null
@@ -0,0 +1,38 @@
+// __tls_get_new did not allocate new dtv for threads properly
+#include <pthread.h>
+#include <dlfcn.h>
+#include "test.h"
+
+#define N 10
+
+#define T(c) ((c) || (t_error(#c " failed\n"),0))
+
+static pthread_barrier_t b;
+static void *mod;
+
+static void *start(void *a)
+{
+       void *(*f)(void);
+
+       pthread_barrier_wait(&b);
+       T(f = dlsym(mod, "f"));
+       f();
+       return 0;
+}
+
+int main()
+{
+       pthread_t td[N];
+       int i;
+
+       pthread_barrier_init(&b, 0, N+1);
+       for (i=0; i<N; i++)
+               T(!pthread_create(td+i, 0, start, 0));
+
+       T(mod = dlopen("tls_get_new-dtv_dso.so", RTLD_NOW));
+       pthread_barrier_wait(&b);
+
+       for (i=0; i<N; i++)
+               T(!pthread_join(td[i], 0));
+       return t_status;
+}
diff --git a/src/regression/tls_get_new-dtv_dso.c b/src/regression/tls_get_new-dtv_dso.c
new file mode 100644 (file)
index 0000000..eb4be9b
--- /dev/null
@@ -0,0 +1,13 @@
+__thread char v[123];
+__thread int x = 42;
+__thread long double y;
+
+void *f()
+{
+       int i;
+       for (i=0; i<sizeof v; i++)
+               v[i] = i%16;
+       return v;
+}
+void *g() {return &x;}
+void *h() {return &y;}