1#include <dlfcn.h>
2#include <stdlib.h>
3#include <stdio.h>
4
5static int
6do_test (void)
7{
8 void *h = dlopen (file: "tst-tlsmod16a.so", RTLD_LAZY | RTLD_GLOBAL);
9 if (h == NULL)
10 {
11 puts (s: "unexpectedly failed to open tst-tlsmod16a.so");
12 exit (status: 1);
13 }
14
15 void *p = dlsym (handle: h, name: "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 (file: "tst-tlsmod16b.so", RTLD_NOW | RTLD_GLOBAL);
24 if (h == NULL)
25 {
26 return 0;
27 }
28
29 puts (s: "unexpectedly succeeded to open tst-tlsmod16b.so");
30
31
32 void *(*fp) (void) = (void *(*) (void)) dlsym (handle: h, name: "in_dso");
33 if (fp == NULL)
34 {
35 puts (s: "cannot find in_dso");
36 exit (status: 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 (s: "returned values do not match");
46 exit (status: 1);
47 }
48
49 return 0;
50}
51
52#include <support/test-driver.c>
53

source code of glibc/elf/tst-tls16.c