]>
Commit | Line | Data |
---|---|---|
08c44e65 L |
1 | #ifdef PROTECTED_CHECK |
2 | #include <features.h> | |
1566ad5d | 3 | #include <stdio.h> |
08c44e65 L |
4 | |
5 | int | |
1566ad5d | 6 | main (void) |
08c44e65 L |
7 | { |
8 | #if defined (__GLIBC__) && (__GLIBC__ > 2 \ | |
9 | || (__GLIBC__ == 2 \ | |
10 | && __GLIBC_MINOR__ >= 2)) | |
11 | puts ("yes"); | |
12 | #else | |
13 | puts ("no"); | |
14 | #endif | |
15 | return 0; | |
16 | } | |
17 | #else | |
6fc49d28 L |
18 | /* This is the main program for the shared library test. */ |
19 | ||
20 | #include <stdio.h> | |
21 | ||
22 | int mainvar = 1; | |
23 | int overriddenvar = 2; | |
24 | extern int shlibvar1; | |
25 | ||
26 | extern int shlib_mainvar (); | |
27 | extern int shlib_overriddenvar (); | |
28 | extern int shlib_shlibvar1 (); | |
29 | extern int shlib_shlibvar2 (); | |
30 | extern int shlib_shlibcall (); | |
31 | extern int shlib_maincall (); | |
32 | extern int shlib_checkfunptr1 (); | |
33 | extern int shlib_checkfunptr2 (); | |
34 | extern int (*shlib_getfunptr1 ()) (); | |
35 | extern int (*shlib_getfunptr2 ()) (); | |
36 | extern int shlib_check (); | |
37 | extern int shlib_shlibcall2 (); | |
6fc49d28 L |
38 | extern int visibility_check (); |
39 | extern int visibility_checkfunptr (); | |
40 | extern void *visibility_funptr (); | |
7cda33a1 L |
41 | extern int visibility_checkvar (); |
42 | extern int visibility_checkvarptr (); | |
43 | extern int visibility_varval (); | |
44 | extern void *visibility_varptr (); | |
1b1fe8fe L |
45 | extern int shlib_visibility_checkcom (); |
46 | extern int shlib_visibility_checkweak (); | |
47 | ||
48 | int shlib_visibility_com = 1; | |
49 | ||
50 | int shlib_visibility_var_weak = 1; | |
51 | ||
52 | int | |
53 | shlib_visibility_func_weak () | |
54 | { | |
55 | return 1; | |
56 | } | |
7cda33a1 L |
57 | |
58 | #ifdef HIDDEN_WEAK_TEST | |
7cda33a1 L |
59 | #define WEAK_TEST |
60 | #endif | |
61 | ||
62 | #ifdef PROTECTED_WEAK_TEST | |
7cda33a1 L |
63 | #define WEAK_TEST |
64 | #endif | |
65 | ||
1345a0c0 L |
66 | #ifdef PROTECTED_UNDEF_TEST |
67 | #define PROTECTED_TEST | |
68 | #endif | |
69 | ||
7cda33a1 L |
70 | #ifndef WEAK_TEST |
71 | extern int visibility (); | |
72 | extern int visibility_var; | |
73 | #endif | |
6fc49d28 L |
74 | |
75 | #if !defined (HIDDEN_TEST) && defined (PROTECTED_TEST) | |
76 | int | |
23a75657 | 77 | visibility (void) |
6fc49d28 L |
78 | { |
79 | return 1; | |
80 | } | |
6fc49d28 | 81 | |
e80778cf | 82 | static int |
23a75657 | 83 | main_visibility_check (void) |
e80778cf | 84 | { |
c0d48c0b | 85 | return ((int (*) (void)) visibility_funptr ()) != visibility; |
e80778cf | 86 | } |
7cda33a1 L |
87 | |
88 | int visibility_var = 1; | |
89 | ||
90 | static int | |
23a75657 | 91 | main_visibility_checkvar (void) |
7cda33a1 L |
92 | { |
93 | return visibility_varval () != visibility_var | |
94 | && visibility_varptr () != &visibility_var; | |
95 | } | |
1b1fe8fe L |
96 | |
97 | #ifndef PROTECTED_UNDEF_TEST | |
98 | int shared_data = 1; | |
99 | asm (".protected shared_data"); | |
100 | ||
101 | int | |
23a75657 | 102 | shared_func (void) |
1b1fe8fe L |
103 | { |
104 | return 1; | |
105 | } | |
106 | ||
107 | asm (".protected shared_func"); | |
108 | ||
109 | extern int * shared_data_p (); | |
110 | typedef int (*func) (); | |
111 | extern func shared_func_p (); | |
112 | #endif | |
e80778cf | 113 | #else |
6fc49d28 | 114 | static int |
23a75657 | 115 | main_visibility_check (void) |
6fc49d28 | 116 | { |
7cda33a1 L |
117 | #ifdef WEAK_TEST |
118 | return visibility_funptr () == NULL; | |
119 | #else | |
c0d48c0b | 120 | return ((int (*) (void)) visibility_funptr ()) == visibility; |
7cda33a1 L |
121 | #endif |
122 | } | |
123 | ||
124 | static int | |
23a75657 | 125 | main_visibility_checkvar (void) |
7cda33a1 L |
126 | { |
127 | #ifdef WEAK_TEST | |
128 | return visibility_varval () == 0 | |
129 | && visibility_varptr () == NULL; | |
130 | #else | |
131 | return visibility_varval () == visibility_var | |
132 | && visibility_varptr () == &visibility_var; | |
133 | #endif | |
6fc49d28 | 134 | } |
e80778cf | 135 | #endif |
6fc49d28 L |
136 | |
137 | /* This function is called by the shared library. */ | |
138 | ||
139 | int | |
23a75657 | 140 | main_called (void) |
6fc49d28 L |
141 | { |
142 | return 6; | |
143 | } | |
144 | ||
145 | /* This function overrides a function in the shared library. */ | |
146 | ||
147 | int | |
23a75657 | 148 | shlib_overriddencall2 (void) |
6fc49d28 L |
149 | { |
150 | return 8; | |
151 | } | |
152 | ||
1b1fe8fe L |
153 | #ifdef HIDDEN_NORMAL_TEST |
154 | int visibility_com; | |
155 | asm (".hidden visibility_com"); | |
156 | ||
157 | int | |
23a75657 | 158 | main_visibility_checkcom (void) |
1b1fe8fe L |
159 | { |
160 | return visibility_com == 0; | |
161 | } | |
162 | ||
163 | int | |
23a75657 | 164 | main_visibility_checkweak (void) |
1b1fe8fe L |
165 | { |
166 | return 1; | |
167 | } | |
ef5aade5 L |
168 | #elif defined (HIDDEN_WEAK_TEST) |
169 | int | |
23a75657 | 170 | main_visibility_checkcom (void) |
ef5aade5 L |
171 | { |
172 | return 1; | |
173 | } | |
174 | ||
175 | #pragma weak visibility_undef_var_weak | |
176 | extern int visibility_undef_var_weak; | |
177 | asm (".hidden visibility_undef_var_weak"); | |
178 | ||
179 | #pragma weak visibility_undef_func_weak | |
180 | extern int visibility_undef_func_weak (); | |
181 | asm (".hidden visibility_undef_func_weak"); | |
182 | ||
183 | #pragma weak visibility_var_weak | |
184 | extern int visibility_var_weak; | |
185 | asm (".hidden visibility_var_weak"); | |
186 | ||
187 | #pragma weak visibility_func_weak | |
188 | extern int visibility_func_weak (); | |
189 | asm (".hidden visibility_func_weak"); | |
190 | ||
191 | int | |
192 | main_visibility_checkweak () | |
193 | { | |
194 | return &visibility_undef_var_weak == NULL | |
195 | && &visibility_undef_func_weak == NULL | |
196 | && &visibility_func_weak == NULL | |
197 | && &visibility_var_weak == NULL; | |
198 | } | |
1b1fe8fe L |
199 | #elif defined (HIDDEN_UNDEF_TEST) |
200 | extern int visibility_def; | |
201 | asm (".hidden visibility_def"); | |
202 | extern int visibility_func (); | |
203 | asm (".hidden visibility_func"); | |
204 | ||
205 | int | |
23a75657 | 206 | main_visibility_checkcom (void) |
1b1fe8fe | 207 | { |
23a75657 | 208 | return & visibility_def != NULL && visibility_def == 2; |
1b1fe8fe L |
209 | } |
210 | ||
211 | int | |
23a75657 | 212 | main_visibility_checkweak (void) |
1b1fe8fe | 213 | { |
23a75657 | 214 | return & visibility_func != NULL && visibility_func () == 2; |
1b1fe8fe L |
215 | } |
216 | #else | |
217 | int | |
23a75657 | 218 | main_visibility_checkcom (void) |
1b1fe8fe L |
219 | { |
220 | return 1; | |
221 | } | |
222 | ||
223 | int | |
23a75657 | 224 | main_visibility_checkweak (void) |
1b1fe8fe L |
225 | { |
226 | return 1; | |
227 | } | |
228 | #endif | |
229 | ||
6fc49d28 | 230 | int |
23a75657 | 231 | main (void) |
6fc49d28 L |
232 | { |
233 | int (*p) (); | |
1b1fe8fe | 234 | int ret = 0; |
6fc49d28 L |
235 | |
236 | printf ("mainvar == %d\n", mainvar); | |
237 | printf ("overriddenvar == %d\n", overriddenvar); | |
238 | printf ("shlibvar1 == %d\n", shlibvar1); | |
239 | #ifndef XCOFF_TEST | |
240 | printf ("shlib_mainvar () == %d\n", shlib_mainvar ()); | |
241 | printf ("shlib_overriddenvar () == %d\n", shlib_overriddenvar ()); | |
242 | #endif | |
243 | printf ("shlib_shlibvar1 () == %d\n", shlib_shlibvar1 ()); | |
244 | printf ("shlib_shlibvar2 () == %d\n", shlib_shlibvar2 ()); | |
245 | printf ("shlib_shlibcall () == %d\n", shlib_shlibcall ()); | |
246 | #ifndef XCOFF_TEST | |
247 | printf ("shlib_shlibcall2 () == %d\n", shlib_shlibcall2 ()); | |
248 | printf ("shlib_maincall () == %d\n", shlib_maincall ()); | |
249 | #endif | |
250 | printf ("main_called () == %d\n", main_called ()); | |
251 | printf ("shlib_checkfunptr1 (shlib_shlibvar1) == %d\n", | |
252 | shlib_checkfunptr1 (shlib_shlibvar1)); | |
253 | #ifndef XCOFF_TEST | |
254 | printf ("shlib_checkfunptr2 (main_called) == %d\n", | |
255 | shlib_checkfunptr2 (main_called)); | |
256 | #endif | |
257 | p = shlib_getfunptr1 (); | |
258 | printf ("shlib_getfunptr1 () "); | |
259 | if (p == shlib_shlibvar1) | |
260 | printf ("=="); | |
261 | else | |
262 | printf ("!="); | |
263 | printf (" shlib_shlibvar1\n"); | |
264 | #ifndef XCOFF_TEST | |
265 | p = shlib_getfunptr2 (); | |
266 | printf ("shlib_getfunptr2 () "); | |
267 | if (p == main_called) | |
268 | printf ("=="); | |
269 | else | |
270 | printf ("!="); | |
271 | printf (" main_called\n"); | |
272 | #endif | |
273 | printf ("shlib_check () == %d\n", shlib_check ()); | |
274 | printf ("visibility_check () == %d\n", visibility_check ()); | |
275 | printf ("visibility_checkfunptr () == %d\n", | |
276 | visibility_checkfunptr ()); | |
277 | printf ("main_visibility_check () == %d\n", main_visibility_check ()); | |
7cda33a1 L |
278 | printf ("visibility_checkvar () == %d\n", visibility_checkvar ()); |
279 | printf ("visibility_checkvarptr () == %d\n", | |
280 | visibility_checkvarptr ()); | |
281 | printf ("main_visibility_checkvar () == %d\n", | |
282 | main_visibility_checkvar ()); | |
1b1fe8fe L |
283 | printf ("main_visibility_checkcom () == %d\n", |
284 | main_visibility_checkcom ()); | |
285 | printf ("shlib_visibility_checkcom () == %d\n", | |
286 | shlib_visibility_checkcom ()); | |
287 | printf ("main_visibility_checkweak () == %d\n", | |
288 | main_visibility_checkweak ()); | |
289 | printf ("shlib_visibility_checkweak () == %d\n", | |
290 | shlib_visibility_checkweak ()); | |
291 | ||
292 | #if !defined (PROTECTED_UNDEF_TEST) && defined (PROTECTED_TEST) | |
293 | if (&shared_data != shared_data_p ()) | |
294 | ret = 1; | |
295 | p = shared_func_p (); | |
296 | if (shared_func != p) | |
297 | ret = 1; | |
298 | if (shared_data != *shared_data_p ()) | |
299 | ret = 1; | |
300 | if (shared_func () != (*p) () ) | |
301 | ret = 1; | |
302 | #endif | |
303 | ||
304 | return ret; | |
6fc49d28 | 305 | } |
08c44e65 | 306 | #endif |