htl: Add tcb-offsets.sym for x86_64
[glibc.git] / elf / tst-tls6.c
blobdf81c1f6b40f26f33cc7168cbe9c89e781a48407
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <link.h>
8 static int
9 do_test (void)
11 static const char modname[] = "tst-tlsmod2.so";
12 int result = 0;
13 int *foop;
14 int *foop2;
15 int (*fp) (int, int *);
16 void *h;
17 int i;
18 int modid = -1;
20 for (i = 0; i < 10; ++i)
22 h = dlopen (modname, RTLD_LAZY);
23 if (h == NULL)
25 printf ("cannot open '%s': %s\n", modname, dlerror ());
26 exit (1);
29 /* Dirty test code here: we peek into a private data structure.
30 We make sure that the module gets assigned the same ID every
31 time. The value of the first round is used. */
32 if (modid == -1)
33 modid = ((struct link_map *) h)->l_tls_modid;
34 else if (((struct link_map *) h)->l_tls_modid != modid)
36 printf ("round %d: modid now %zd, initially %d\n",
37 i, ((struct link_map *) h)->l_tls_modid, modid);
38 result = 1;
41 foop = dlsym (h, "foo");
42 if (foop == NULL)
44 printf ("cannot get symbol 'foo': %s\n", dlerror ());
45 exit (1);
48 *foop = 42 + i;
50 fp = dlsym (h, "in_dso");
51 if (fp == NULL)
53 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
54 exit (1);
57 result |= fp (42 + i, foop);
59 foop2 = dlsym (h, "foo");
60 if (foop2 == NULL)
62 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
63 exit (1);
66 if (foop != foop2)
68 puts ("address of 'foo' different the second time");
69 result = 1;
71 else if (*foop != 16)
73 puts ("foo != 16");
74 result = 1;
77 dlclose (h);
80 return result;
84 #include <support/test-driver.c>