1 | #include <dlfcn.h> |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | |
5 | |
6 | static int |
7 | do_test (void) |
8 | { |
9 | static const char modname[] = "tst-tlsmod2.so" ; |
10 | int result = 0; |
11 | int *foop; |
12 | int (*fp) (int, int *); |
13 | void *h; |
14 | |
15 | h = dlopen (file: modname, RTLD_LAZY); |
16 | if (h == NULL) |
17 | { |
18 | printf (format: "cannot open '%s': %s\n" , modname, dlerror ()); |
19 | exit (status: 1); |
20 | } |
21 | |
22 | fp = dlsym (handle: h, name: "in_dso" ); |
23 | if (fp == NULL) |
24 | { |
25 | printf (format: "cannot get symbol 'in_dso': %s\n" , dlerror ()); |
26 | exit (status: 1); |
27 | } |
28 | |
29 | size_t modid = -1; |
30 | if (dlinfo (handle: h, request: RTLD_DI_TLS_MODID, arg: &modid)) |
31 | { |
32 | printf (format: "dlinfo RTLD_DI_TLS_MODID failed: %s\n" , dlerror ()); |
33 | result = 1; |
34 | } |
35 | else |
36 | printf (format: "dlinfo says TLS module ID %Zu\n" , modid); |
37 | |
38 | void *block; |
39 | if (dlinfo (handle: h, request: RTLD_DI_TLS_DATA, arg: &block)) |
40 | { |
41 | printf (format: "dlinfo RTLD_DI_TLS_DATA failed: %s\n" , dlerror ()); |
42 | result = 1; |
43 | } |
44 | else if (block != NULL) |
45 | { |
46 | printf (format: "dlinfo RTLD_DI_TLS_DATA says %p but should be unallocated\n" , |
47 | block); |
48 | result = 1; |
49 | } |
50 | |
51 | result |= fp (0, NULL); |
52 | |
53 | foop = dlsym (handle: h, name: "foo" ); |
54 | if (foop == NULL) |
55 | { |
56 | printf (format: "cannot get symbol 'foo' the second time: %s\n" , dlerror ()); |
57 | exit (status: 1); |
58 | } |
59 | if (*foop != 16) |
60 | { |
61 | puts (s: "foo != 16" ); |
62 | result = 1; |
63 | } |
64 | |
65 | /* Now the module's TLS block has been used and should appear. */ |
66 | if (dlinfo (handle: h, request: RTLD_DI_TLS_DATA, arg: &block)) |
67 | { |
68 | printf (format: "dlinfo RTLD_DI_TLS_DATA failed the second time: %s\n" , |
69 | dlerror ()); |
70 | result = 1; |
71 | } |
72 | else if (block != foop) |
73 | { |
74 | printf (format: "dlinfo RTLD_DI_TLS_DATA says %p but should be %p\n" , |
75 | block, foop); |
76 | result = 1; |
77 | } |
78 | |
79 | dlclose (handle: h); |
80 | |
81 | return result; |
82 | } |
83 | |
84 | |
85 | #include <support/test-driver.c> |
86 | |