2 #define NULL ((void *) 0)
5 /* This is part of the shared library ld test. This file becomes part
6 of a shared library. */
8 /* This variable is supplied by the main program. */
11 /* This variable is defined in the shared library, and overridden by
15 /* SHARED is defined if we are compiling with -fpic/-fPIC. */
16 int overriddenvar
= -1;
18 /* Without -fpic, newer versions of gcc assume that we are not
19 compiling for a shared library, and thus that overriddenvar is
21 extern int overriddenvar
;
25 /* This variable is defined in the shared library. */
28 /* This variable is defined by another object in the shared library. */
31 /* These functions return the values of the above variables as seen in
32 the shared library. */
42 shlib_overriddenvar ()
60 /* This function calls a function defined by another object in the
63 extern int shlib_shlibcalled ();
68 return shlib_shlibcalled ();
72 /* This function calls a function defined in this object in the shared
73 library. The main program will override the called function. */
75 extern int shlib_overriddencall2 ();
80 return shlib_overriddencall2 ();
85 shlib_overriddencall2 ()
92 /* This function calls a function defined by the main program. */
94 extern int main_called ();
99 return main_called ();
102 /* This function is passed a function pointer to shlib_mainvar. It
103 confirms that the pointer compares equally. */
106 shlib_checkfunptr1 (p
)
109 return p
== shlib_shlibvar1
;
112 /* This function is passed a function pointer to main_called. It
113 confirms that the pointer compares equally. */
116 shlib_checkfunptr2 (p
)
119 return p
== main_called
;
122 /* This function returns a pointer to shlib_mainvar. */
125 (*shlib_getfunptr1 ()) ()
127 return shlib_shlibvar1
;
130 /* This function returns a pointer to main_called. */
133 (*shlib_getfunptr2 ()) ()
138 /* This function makes sure that constant data and local functions
146 static const char *str
= "Hello, world\n";
156 /* To isolate the test, don't rely on any external functions, such
158 s1
= "Hello, world\n";
166 if (shlib_shlibvar1 () != 3)
172 #ifdef HIDDEN_WEAK_TEST
173 #define HIDDEN_UNDEF_TEST
177 #ifdef PROTECTED_WEAK_TEST
178 #define PROTECTED_UNDEF_TEST
182 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
184 #pragma weak visibility
186 extern int visibility ();
195 #ifdef HIDDEN_NORMAL_TEST
196 __asm__ (".hidden visibility_normal");
206 visibility_checkfunptr ()
211 #ifdef HIDDEN_NORMAL_TEST
212 int (*v
) () = visibility_normal
;
214 int (*v
) () = visibility
;
225 return visibility () == 1;
229 #ifdef HIDDEN_NORMAL_TEST
230 return visibility_normal () == 2;
232 return visibility () == 2;
241 if (&visibility
== NULL
)
248 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
250 #pragma weak visibility_var
252 extern int visibility_var
;
254 int visibility_var
= 2;
257 #ifdef HIDDEN_NORMAL_TEST
258 __asm__ (".hidden visibility_var_normal");
260 int visibility_var_normal
= 2;
264 visibility_checkvarptr ()
268 return visibility_var
== 1;
272 #ifdef HIDDEN_NORMAL_TEST
273 int *v
= &visibility_var_normal
;
275 int *v
= &visibility_var
;
282 visibility_checkvar ()
287 #ifdef HIDDEN_NORMAL_TEST
288 return visibility_var_normal
== 2;
290 return visibility_var
== 2;
299 if (&visibility_var
== NULL
)
303 return &visibility_var
;
310 if (&visibility_var
== NULL
)
314 return visibility_var
;
317 #if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
318 __asm__ (".hidden visibility");
319 __asm__ (".hidden visibility_var");
321 #if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
322 __asm__ (".protected visibility");
323 __asm__ (".protected visibility_var");
327 #ifdef HIDDEN_NORMAL_TEST
328 int shlib_visibility_com
;
329 __asm__ (".hidden shlib_visibility_com");
332 shlib_visibility_checkcom ()
334 return shlib_visibility_com
== 0;
338 shlib_visibility_checkweak ()
342 #elif defined (HIDDEN_WEAK_TEST)
343 #pragma weak shlib_visibility_undef_var_weak
344 extern int shlib_visibility_undef_var_weak
;
345 __asm__ (".hidden shlib_visibility_undef_var_weak");
347 #pragma weak shlib_visibility_undef_func_weak
348 extern int shlib_visibility_undef_func_weak ();
349 __asm__ (".hidden shlib_visibility_undef_func_weak");
351 #pragma weak shlib_visibility_var_weak
352 extern int shlib_visibility_var_weak
;
353 __asm__ (".hidden shlib_visibility_var_weak");
355 #pragma weak shlib_visibility_func_weak
356 extern int shlib_visibility_func_weak ();
357 __asm__ (".hidden shlib_visibility_func_weak");
360 shlib_visibility_checkcom ()
366 shlib_visibility_checkweak ()
368 return &shlib_visibility_undef_var_weak
== NULL
369 && &shlib_visibility_undef_func_weak
== NULL
370 && &shlib_visibility_func_weak
== NULL
371 && &shlib_visibility_var_weak
== NULL
;
375 shlib_visibility_checkcom ()
381 shlib_visibility_checkweak ()
387 #ifdef PROTECTED_TEST
389 int shared_data
= 100;
391 extern int shared_data
;