]>
Commit | Line | Data |
---|---|---|
ebda6173 UD |
1 | #include <dlfcn.h> |
2 | #include <stdio.h> | |
3 | #include <stdlib.h> | |
4 | ||
5 | #include <link.h> | |
6 | #include <tls.h> | |
7 | ||
8 | ||
9 | #define TEST_FUNCTION do_test () | |
10 | static int | |
11 | do_test (void) | |
12 | { | |
a7e91561 UD |
13 | static const char modname1[] = "$ORIGIN/tst-tlsmod3.so"; |
14 | static const char modname2[] = "$ORIGIN/tst-tlsmod4.so"; | |
ebda6173 UD |
15 | int result = 0; |
16 | int (*fp1) (void); | |
17 | int (*fp2) (int, int *); | |
18 | void *h1; | |
19 | void *h2; | |
20 | int i; | |
541765b6 UD |
21 | size_t modid1 = (size_t) -1; |
22 | size_t modid2 = (size_t) -1; | |
ebda6173 UD |
23 | int *bazp; |
24 | ||
25 | for (i = 0; i < 10; ++i) | |
26 | { | |
27 | h1 = dlopen (modname1, RTLD_LAZY); | |
28 | if (h1 == NULL) | |
29 | { | |
30 | printf ("cannot open '%s': %s\n", modname1, dlerror ()); | |
31 | exit (1); | |
32 | } | |
33 | ||
34 | /* Dirty test code here: we peek into a private data structure. | |
35 | We make sure that the module gets assigned the same ID every | |
36 | time. The value of the first round is used. */ | |
541765b6 | 37 | if (modid1 == (size_t) -1) |
ebda6173 UD |
38 | modid1 = ((struct link_map *) h1)->l_tls_modid; |
39 | else if (((struct link_map *) h1)->l_tls_modid != modid1) | |
40 | { | |
d347a4ab | 41 | printf ("round %d: modid now %zd, initially %zd\n", |
ebda6173 UD |
42 | i, ((struct link_map *) h1)->l_tls_modid, modid1); |
43 | result = 1; | |
44 | } | |
45 | ||
46 | fp1 = dlsym (h1, "in_dso2"); | |
47 | if (fp1 == NULL) | |
48 | { | |
49 | printf ("cannot get symbol 'in_dso2' in %s\n", modname1); | |
50 | exit (1); | |
51 | } | |
52 | ||
53 | result |= fp1 (); | |
54 | ||
55 | ||
56 | ||
57 | h2 = dlopen (modname2, RTLD_LAZY); | |
58 | if (h2 == NULL) | |
59 | { | |
60 | printf ("cannot open '%s': %s\n", modname2, dlerror ()); | |
61 | exit (1); | |
62 | } | |
63 | ||
64 | /* Dirty test code here: we peek into a private data structure. | |
65 | We make sure that the module gets assigned the same ID every | |
66 | time. The value of the first round is used. */ | |
541765b6 | 67 | if (modid2 == (size_t) -1) |
ebda6173 UD |
68 | modid2 = ((struct link_map *) h1)->l_tls_modid; |
69 | else if (((struct link_map *) h1)->l_tls_modid != modid2) | |
70 | { | |
d347a4ab | 71 | printf ("round %d: modid now %zd, initially %zd\n", |
ebda6173 UD |
72 | i, ((struct link_map *) h1)->l_tls_modid, modid2); |
73 | result = 1; | |
74 | } | |
75 | ||
76 | bazp = dlsym (h2, "baz"); | |
77 | if (bazp == NULL) | |
78 | { | |
79 | printf ("cannot get symbol 'baz' in %s\n", modname2); | |
80 | exit (1); | |
81 | } | |
82 | ||
83 | *bazp = 42 + i; | |
84 | ||
85 | fp2 = dlsym (h2, "in_dso"); | |
86 | if (fp2 == NULL) | |
87 | { | |
88 | printf ("cannot get symbol 'in_dso' in %s\n", modname2); | |
89 | exit (1); | |
90 | } | |
91 | ||
92 | result |= fp2 (42 + i, bazp); | |
93 | ||
94 | dlclose (h1); | |
95 | dlclose (h2); | |
96 | ||
97 | ||
98 | h1 = dlopen (modname1, RTLD_LAZY); | |
99 | if (h1 == NULL) | |
100 | { | |
101 | printf ("cannot open '%s': %s\n", modname1, dlerror ()); | |
102 | exit (1); | |
103 | } | |
104 | ||
105 | /* Dirty test code here: we peek into a private data structure. | |
106 | We make sure that the module gets assigned the same ID every | |
107 | time. The value of the first round is used. */ | |
108 | if (((struct link_map *) h1)->l_tls_modid != modid1) | |
109 | { | |
d347a4ab | 110 | printf ("round %d: modid now %zd, initially %zd\n", |
ebda6173 UD |
111 | i, ((struct link_map *) h1)->l_tls_modid, modid1); |
112 | result = 1; | |
113 | } | |
114 | ||
115 | fp1 = dlsym (h1, "in_dso2"); | |
116 | if (fp1 == NULL) | |
117 | { | |
118 | printf ("cannot get symbol 'in_dso2' in %s\n", modname1); | |
119 | exit (1); | |
120 | } | |
121 | ||
122 | result |= fp1 (); | |
123 | ||
124 | ||
125 | ||
126 | h2 = dlopen (modname2, RTLD_LAZY); | |
127 | if (h2 == NULL) | |
128 | { | |
129 | printf ("cannot open '%s': %s\n", modname2, dlerror ()); | |
130 | exit (1); | |
131 | } | |
132 | ||
133 | /* Dirty test code here: we peek into a private data structure. | |
134 | We make sure that the module gets assigned the same ID every | |
135 | time. The value of the first round is used. */ | |
136 | if (((struct link_map *) h1)->l_tls_modid != modid2) | |
137 | { | |
d347a4ab | 138 | printf ("round %d: modid now %zd, initially %zd\n", |
ebda6173 UD |
139 | i, ((struct link_map *) h1)->l_tls_modid, modid2); |
140 | result = 1; | |
141 | } | |
142 | ||
143 | bazp = dlsym (h2, "baz"); | |
144 | if (bazp == NULL) | |
145 | { | |
146 | printf ("cannot get symbol 'baz' in %s\n", modname2); | |
147 | exit (1); | |
148 | } | |
149 | ||
150 | *bazp = 62 + i; | |
151 | ||
152 | fp2 = dlsym (h2, "in_dso"); | |
153 | if (fp2 == NULL) | |
154 | { | |
155 | printf ("cannot get symbol 'in_dso' in %s\n", modname2); | |
156 | exit (1); | |
157 | } | |
158 | ||
159 | result |= fp2 (62 + i, bazp); | |
160 | ||
161 | /* This time the dlclose calls are in reverse order. */ | |
162 | dlclose (h2); | |
163 | dlclose (h1); | |
164 | } | |
165 | ||
166 | return result; | |
ebda6173 UD |
167 | } |
168 | ||
169 | ||
170 | #include "../test-skeleton.c" |