8 #if defined (__GLIBC__) && (__GLIBC__ > 2 \
10 && __GLIBC_MINOR__ >= 2))
18 /* This is the main program for the shared library test. */
23 int overriddenvar
= 2;
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 ();
38 extern int visibility_check ();
39 extern int visibility_checkfunptr ();
40 extern void *visibility_funptr ();
41 extern int visibility_checkvar ();
42 extern int visibility_checkvarptr ();
43 extern int visibility_varval ();
44 extern void *visibility_varptr ();
45 extern int shlib_visibility_checkcom ();
46 extern int shlib_visibility_checkweak ();
48 int shlib_visibility_com
= 1;
50 int shlib_visibility_var_weak
= 1;
53 shlib_visibility_func_weak ()
58 #ifdef HIDDEN_WEAK_TEST
62 #ifdef PROTECTED_WEAK_TEST
66 #ifdef PROTECTED_UNDEF_TEST
67 #define PROTECTED_TEST
71 extern int visibility ();
72 extern int visibility_var
;
75 #if !defined (HIDDEN_TEST) && defined (PROTECTED_TEST)
83 main_visibility_check (void)
85 return ((int (*) (void)) visibility_funptr ()) != visibility
;
88 int visibility_var
= 1;
91 main_visibility_checkvar (void)
93 return visibility_varval () != visibility_var
94 && visibility_varptr () != &visibility_var
;
97 #ifndef PROTECTED_UNDEF_TEST
99 asm (".protected shared_data");
107 asm (".protected shared_func");
109 extern int * shared_data_p ();
110 typedef int (*func
) ();
111 extern func
shared_func_p ();
115 main_visibility_check (void)
118 return visibility_funptr () == NULL
;
120 return ((int (*) (void)) visibility_funptr ()) == visibility
;
125 main_visibility_checkvar (void)
128 return visibility_varval () == 0
129 && visibility_varptr () == NULL
;
131 return visibility_varval () == visibility_var
132 && visibility_varptr () == &visibility_var
;
137 /* This function is called by the shared library. */
145 /* This function overrides a function in the shared library. */
148 shlib_overriddencall2 (void)
153 #ifdef HIDDEN_NORMAL_TEST
155 asm (".hidden visibility_com");
158 main_visibility_checkcom (void)
160 return visibility_com
== 0;
164 main_visibility_checkweak (void)
168 #elif defined (HIDDEN_WEAK_TEST)
170 main_visibility_checkcom (void)
175 #pragma weak visibility_undef_var_weak
176 extern int visibility_undef_var_weak
;
177 asm (".hidden visibility_undef_var_weak");
179 #pragma weak visibility_undef_func_weak
180 extern int visibility_undef_func_weak ();
181 asm (".hidden visibility_undef_func_weak");
183 #pragma weak visibility_var_weak
184 extern int visibility_var_weak
;
185 asm (".hidden visibility_var_weak");
187 #pragma weak visibility_func_weak
188 extern int visibility_func_weak ();
189 asm (".hidden visibility_func_weak");
192 main_visibility_checkweak ()
194 return &visibility_undef_var_weak
== NULL
195 && &visibility_undef_func_weak
== NULL
196 && &visibility_func_weak
== NULL
197 && &visibility_var_weak
== NULL
;
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");
206 main_visibility_checkcom (void)
208 return & visibility_def
!= NULL
&& visibility_def
== 2;
212 main_visibility_checkweak (void)
214 return & visibility_func
!= NULL
&& visibility_func () == 2;
218 main_visibility_checkcom (void)
224 main_visibility_checkweak (void)
236 printf ("mainvar == %d\n", mainvar
);
237 printf ("overriddenvar == %d\n", overriddenvar
);
238 printf ("shlibvar1 == %d\n", shlibvar1
);
240 printf ("shlib_mainvar () == %d\n", shlib_mainvar ());
241 printf ("shlib_overriddenvar () == %d\n", shlib_overriddenvar ());
243 printf ("shlib_shlibvar1 () == %d\n", shlib_shlibvar1 ());
244 printf ("shlib_shlibvar2 () == %d\n", shlib_shlibvar2 ());
245 printf ("shlib_shlibcall () == %d\n", shlib_shlibcall ());
247 printf ("shlib_shlibcall2 () == %d\n", shlib_shlibcall2 ());
248 printf ("shlib_maincall () == %d\n", shlib_maincall ());
250 printf ("main_called () == %d\n", main_called ());
251 printf ("shlib_checkfunptr1 (shlib_shlibvar1) == %d\n",
252 shlib_checkfunptr1 (shlib_shlibvar1
));
254 printf ("shlib_checkfunptr2 (main_called) == %d\n",
255 shlib_checkfunptr2 (main_called
));
257 p
= shlib_getfunptr1 ();
258 printf ("shlib_getfunptr1 () ");
259 if (p
== shlib_shlibvar1
)
263 printf (" shlib_shlibvar1\n");
265 p
= shlib_getfunptr2 ();
266 printf ("shlib_getfunptr2 () ");
267 if (p
== main_called
)
271 printf (" main_called\n");
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 ());
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 ());
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 ());
292 #if !defined (PROTECTED_UNDEF_TEST) && defined (PROTECTED_TEST)
293 if (&shared_data
!= shared_data_p ())
295 p
= shared_func_p ();
296 if (shared_func
!= p
)
298 if (shared_data
!= *shared_data_p ())
300 if (shared_func () != (*p
) () )