]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/tls/tst-tls16.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / tls / tst-tls16.c
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 static int
6 do_test (void)
7 {
8   void *h = dlopen ("tst-tlsmod16a.so", RTLD_LAZY | RTLD_GLOBAL);
9   if (h == NULL)
10     {
11       puts ("unexpectedly failed to open tst-tlsmod16a.so");
12       exit (1);
13     }
14
15   void *p = dlsym (h, "tlsvar");
16
17   /* This dlopen should indeed fail, because tlsvar was assigned to
18      dynamic TLS, and the new module requests it to be in static TLS.
19      However, there's a possibility that dlopen succeeds if the
20      variable is, for whatever reason, assigned to static TLS, or if
21      the module fails to require static TLS, or even if TLS is not
22      supported.  */
23   h = dlopen ("tst-tlsmod16b.so", RTLD_NOW | RTLD_GLOBAL);
24   if (h == NULL)
25     {
26       return 0;
27     }
28
29   puts ("unexpectedly succeeded to open tst-tlsmod16b.so");
30
31
32   void *(*fp) (void) = (void *(*) (void)) dlsym (h, "in_dso");
33   if (fp == NULL)
34     {
35       puts ("cannot find in_dso");
36       exit (1);
37     }
38
39   /* If the dlopen passes, at least make sure the address returned by
40      dlsym is the same as that returned by the initial-exec access.
41      If the variable was assigned to dynamic TLS during dlsym, this
42      portion will fail.  */
43   if (fp () != p)
44     {
45       puts ("returned values do not match");
46       exit (1);
47     }
48
49   return 0;
50 }
51
52 #define TEST_FUNCTION do_test ()
53 #include "../test-skeleton.c"