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. */
13 /* This variable is defined in the shared library, and overridden by
17 /* SHARED is defined if we are compiling with -fpic/-fPIC. */
18 int overriddenvar
= -1;
20 /* Without -fpic, newer versions of gcc assume that we are not
21 compiling for a shared library, and thus that overriddenvar is
23 extern int overriddenvar
;
27 /* This variable is defined in the shared library. */
30 /* This variable is defined by another object in the shared library. */
33 /* These functions return the values of the above variables as seen in
34 the shared library. */
46 shlib_overriddenvar ()
64 /* This function calls a function defined by another object in the
67 extern int shlib_shlibcalled ();
72 return shlib_shlibcalled ();
76 /* This function calls a function defined in this object in the shared
77 library. The main program will override the called function. */
79 extern int shlib_overriddencall2 ();
84 return shlib_overriddencall2 ();
89 shlib_overriddencall2 ()
96 /* This function calls a function defined by the main program. */
99 extern int main_called ();
104 return main_called ();
108 /* This function is passed a function pointer to shlib_mainvar. It
109 confirms that the pointer compares equally. */
112 shlib_checkfunptr1 (p
)
115 return p
== shlib_shlibvar1
;
118 /* This function is passed a function pointer to main_called. It
119 confirms that the pointer compares equally. */
123 shlib_checkfunptr2 (p
)
126 return p
== main_called
;
130 /* This function returns a pointer to shlib_mainvar. */
133 (*shlib_getfunptr1 ()) ()
135 return shlib_shlibvar1
;
138 /* This function returns a pointer to main_called. */
142 (*shlib_getfunptr2 ()) ()
148 /* This function makes sure that constant data and local functions
156 static const char *str
= "Hello, world\n";
166 /* To isolate the test, don't rely on any external functions, such
168 s1
= "Hello, world\n";
176 if (shlib_shlibvar1 () != 3)
182 #ifdef HIDDEN_WEAK_TEST
183 #define HIDDEN_UNDEF_TEST
187 #ifdef PROTECTED_WEAK_TEST
188 #define PROTECTED_UNDEF_TEST
192 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
194 #pragma weak visibility
196 extern int visibility ();
205 #ifdef HIDDEN_NORMAL_TEST
206 asm (".hidden visibility_normal");
216 visibility_checkfunptr ()
221 #ifdef HIDDEN_NORMAL_TEST
222 int (*v
) () = visibility_normal
;
224 int (*v
) () = visibility
;
235 return visibility () == 1;
239 #ifdef HIDDEN_NORMAL_TEST
240 return visibility_normal () == 2;
242 return visibility () == 2;
251 if (&visibility
== NULL
)
258 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
260 #pragma weak visibility_var
262 extern int visibility_var
;
264 int visibility_var
= 2;
267 #ifdef HIDDEN_NORMAL_TEST
268 asm (".hidden visibility_var_normal");
270 int visibility_var_normal
= 2;
274 visibility_checkvarptr ()
278 return visibility_var
== 1;
282 #ifdef HIDDEN_NORMAL_TEST
283 int *v
= &visibility_var_normal
;
285 int *v
= &visibility_var
;
292 visibility_checkvar ()
297 #ifdef HIDDEN_NORMAL_TEST
298 return visibility_var_normal
== 2;
300 return visibility_var
== 2;
309 if (&visibility_var
== NULL
)
313 return &visibility_var
;
320 if (&visibility_var
== NULL
)
324 return visibility_var
;
327 #if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
328 asm (".hidden visibility");
329 asm (".hidden visibility_var");
331 #if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
332 asm (".protected visibility");
333 asm (".protected visibility_var");
337 #ifdef HIDDEN_NORMAL_TEST
338 int shlib_visibility_com
;
339 asm (".hidden shlib_visibility_com");
342 shlib_visibility_checkcom ()
344 return shlib_visibility_com
== 0;
348 shlib_visibility_checkweak ()
352 #elif defined (HIDDEN_WEAK_TEST)
353 #pragma weak shlib_visibility_undef_var_weak
354 extern int shlib_visibility_undef_var_weak
;
355 asm (".hidden shlib_visibility_undef_var_weak");
357 #pragma weak shlib_visibility_undef_func_weak
358 extern int shlib_visibility_undef_func_weak ();
359 asm (".hidden shlib_visibility_undef_func_weak");
361 #pragma weak shlib_visibility_var_weak
362 extern int shlib_visibility_var_weak
;
363 asm (".hidden shlib_visibility_var_weak");
365 #pragma weak shlib_visibility_func_weak
366 extern int shlib_visibility_func_weak ();
367 asm (".hidden shlib_visibility_func_weak");
370 shlib_visibility_checkcom ()
376 shlib_visibility_checkweak ()
378 return &shlib_visibility_undef_var_weak
== NULL
379 && &shlib_visibility_undef_func_weak
== NULL
380 && &shlib_visibility_func_weak
== NULL
381 && &shlib_visibility_var_weak
== NULL
;
385 shlib_visibility_checkcom ()
391 shlib_visibility_checkweak ()
397 #ifdef PROTECTED_TEST
399 int shared_data
= 100;
401 extern int shared_data
;