NPTL/arc: notify kernel of the TP value
[uClibc.git] / test / tls / tst-tls6.c
blob0ebc50737b3e6b5e1cfc2575cdb5856bc3a7b9cb
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <tls.h>
6 #include <link.h>
7 #ifdef __UCLIBC__
8 #include "dl-elf.h"
9 #include "dl-hash.h"
10 #endif
13 #define TEST_FUNCTION do_test ()
14 static int
15 do_test (void)
17 #ifdef USE_TLS
18 static const char modname[] = "tst-tlsmod2.so";
19 int result = 0;
20 int *foop;
21 int *foop2;
22 int (*fp) (int, int *);
23 void *h;
24 int i;
25 int modid = -1;
27 for (i = 0; i < 10; ++i)
29 h = dlopen (modname, RTLD_LAZY);
30 if (h == NULL)
32 printf ("cannot open '%s': %s\n", modname, dlerror ());
33 exit (1);
36 /* Dirty test code here: we peek into a private data structure.
37 We make sure that the module gets assigned the same ID every
38 time. The value of the first round is used. */
39 #ifdef __UCLIBC__
40 if (modid == -1)
41 modid = ((struct dyn_elf *) h)->dyn->l_tls_modid;
42 else if (((struct dyn_elf *)h)->dyn->l_tls_modid != (size_t) modid)
44 printf ("round %d: modid now %zu, initially %d\n",
46 ((struct dyn_elf *)h)->dyn->l_tls_modid,
47 modid);
48 result = 1;
50 #else
51 if (modid == -1)
52 modid = ((struct link_map *) h)->l_tls_modid;
53 else if (((struct link_map *) h)->l_tls_modid != modid)
55 printf ("round %d: modid now %zd, initially %d\n",
56 i, ((struct link_map *) h)->l_tls_modid, modid);
57 result = 1;
59 #endif
61 foop = dlsym (h, "foo");
62 if (foop == NULL)
64 printf ("cannot get symbol 'foo': %s\n", dlerror ());
65 exit (1);
68 *foop = 42 + i;
70 fp = dlsym (h, "in_dso");
71 if (fp == NULL)
73 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
74 exit (1);
77 result |= fp (42 + i, foop);
79 foop2 = dlsym (h, "foo");
80 if (foop2 == NULL)
82 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
83 exit (1);
86 if (foop != foop2)
88 puts ("address of 'foo' different the second time");
89 result = 1;
91 else if (*foop != 16)
93 puts ("foo != 16");
94 result = 1;
97 dlclose (h);
100 return result;
101 #else
102 return 0;
103 #endif
107 #include "../test-skeleton.c"