Updated to fedora-glibc-20080524T2218
[glibc.git] / elf / tst-tls6.c
blob021622d9c7cee6d2d080268694b1372960fb1fe3
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <link.h>
6 #include <tls.h>
9 #define TEST_FUNCTION do_test ()
10 static int
11 do_test (void)
13 static const char modname[] = "tst-tlsmod2.so";
14 int result = 0;
15 int *foop;
16 int *foop2;
17 int (*fp) (int, int *);
18 void *h;
19 int i;
20 int modid = -1;
22 for (i = 0; i < 10; ++i)
24 h = dlopen (modname, RTLD_LAZY);
25 if (h == NULL)
27 printf ("cannot open '%s': %s\n", modname, dlerror ());
28 exit (1);
31 /* Dirty test code here: we peek into a private data structure.
32 We make sure that the module gets assigned the same ID every
33 time. The value of the first round is used. */
34 if (modid == -1)
35 modid = ((struct link_map *) h)->l_tls_modid;
36 else if (((struct link_map *) h)->l_tls_modid != modid)
38 printf ("round %d: modid now %zd, initially %d\n",
39 i, ((struct link_map *) h)->l_tls_modid, modid);
40 result = 1;
43 foop = dlsym (h, "foo");
44 if (foop == NULL)
46 printf ("cannot get symbol 'foo': %s\n", dlerror ());
47 exit (1);
50 *foop = 42 + i;
52 fp = dlsym (h, "in_dso");
53 if (fp == NULL)
55 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
56 exit (1);
59 result |= fp (42 + i, foop);
61 foop2 = dlsym (h, "foo");
62 if (foop2 == NULL)
64 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
65 exit (1);
68 if (foop != foop2)
70 puts ("address of 'foo' different the second time");
71 result = 1;
73 else if (*foop != 16)
75 puts ("foo != 16");
76 result = 1;
79 dlclose (h);
82 return result;
86 #include "../test-skeleton.c"