2004-12-07 Roland McGrath <roland@redhat.com>
[glibc.git] / elf / tst-tls6.c
blob68d706538f4573d1d83408d7da3613a2d240ae74
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 #ifdef USE_TLS
14 static const char modname[] = "tst-tlsmod2.so";
15 int result = 0;
16 int *foop;
17 int *foop2;
18 int (*fp) (int, int *);
19 void *h;
20 int i;
21 int modid = -1;
23 for (i = 0; i < 10; ++i)
25 h = dlopen (modname, RTLD_LAZY);
26 if (h == NULL)
28 printf ("cannot open '%s': %s\n", modname, dlerror ());
29 exit (1);
32 /* Dirty test code here: we peek into a private data structure.
33 We make sure that the module gets assigned the same ID every
34 time. The value of the first round is used. */
35 if (modid == -1)
36 modid = ((struct link_map *) h)->l_tls_modid;
37 else if (((struct link_map *) h)->l_tls_modid != modid)
39 printf ("round %d: modid now %zd, initially %d\n",
40 i, ((struct link_map *) h)->l_tls_modid, modid);
41 result = 1;
44 foop = dlsym (h, "foo");
45 if (foop == NULL)
47 printf ("cannot get symbol 'foo': %s\n", dlerror ());
48 exit (1);
51 *foop = 42 + i;
53 fp = dlsym (h, "in_dso");
54 if (fp == NULL)
56 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
57 exit (1);
60 result |= fp (42 + i, foop);
62 foop2 = dlsym (h, "foo");
63 if (foop2 == NULL)
65 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
66 exit (1);
69 if (foop != foop2)
71 puts ("address of 'foo' different the second time");
72 result = 1;
74 else if (*foop != 16)
76 puts ("foo != 16");
77 result = 1;
80 dlclose (h);
83 return result;
84 #else
85 return 0;
86 #endif
90 #include "../test-skeleton.c"