* bucomm.c (display_target_list): Make local variable `a' to be of
[binutils.git] / ld / testsuite / ld-elfvsb / sh1.c
blob8d9fcdbdcb33a9c2b42f6b147ac1b741a7f8567a
1 #ifndef NULL
2 #define NULL ((void *) 0)
3 #endif
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. */
9 #ifndef XCOFF_TEST
10 extern int mainvar;
11 #endif
13 /* This variable is defined in the shared library, and overridden by
14 the main program. */
15 #ifndef XCOFF_TEST
16 int overriddenvar = -1;
17 #endif
19 /* This variable is defined in the shared library. */
20 int shlibvar1 = 3;
22 /* This variable is defined by another object in the shared library. */
23 extern int shlibvar2;
25 /* These functions return the values of the above variables as seen in
26 the shared library. */
28 #ifndef XCOFF_TEST
29 int
30 shlib_mainvar ()
32 return mainvar;
34 #endif
36 #ifndef XCOFF_TEST
37 int
38 shlib_overriddenvar ()
40 return overriddenvar;
42 #endif
44 int
45 shlib_shlibvar1 ()
47 return shlibvar1;
50 int
51 shlib_shlibvar2 ()
53 return shlibvar2;
56 /* This function calls a function defined by another object in the
57 shared library. */
59 extern int shlib_shlibcalled ();
61 int
62 shlib_shlibcall ()
64 return shlib_shlibcalled ();
67 #ifndef XCOFF_TEST
68 /* This function calls a function defined in this object in the shared
69 library. The main program will override the called function. */
71 extern int shlib_overriddencall2 ();
73 int
74 shlib_shlibcall2 ()
76 return shlib_overriddencall2 ();
79 int
80 shlib_overriddencall2 ()
82 return 7;
84 #endif
86 /* This function calls a function defined by the main program. */
88 #ifndef XCOFF_TEST
89 extern int main_called ();
91 int
92 shlib_maincall ()
94 return main_called ();
96 #endif
98 /* This function is passed a function pointer to shlib_mainvar. It
99 confirms that the pointer compares equally. */
101 int
102 shlib_checkfunptr1 (p)
103 int (*p) ();
105 return p == shlib_shlibvar1;
108 /* This function is passed a function pointer to main_called. It
109 confirms that the pointer compares equally. */
111 #ifndef XCOFF_TEST
113 shlib_checkfunptr2 (p)
114 int (*p) ();
116 return p == main_called;
118 #endif
120 /* This function returns a pointer to shlib_mainvar. */
123 (*shlib_getfunptr1 ()) ()
125 return shlib_shlibvar1;
128 /* This function returns a pointer to main_called. */
130 #ifndef XCOFF_TEST
132 (*shlib_getfunptr2 ()) ()
134 return main_called;
136 #endif
138 /* This function makes sure that constant data and local functions
139 work. */
141 #ifndef __STDC__
142 #define const
143 #endif
145 static int i = 6;
146 static const char *str = "Hello, world\n";
149 shlib_check ()
151 const char *s1, *s2;
153 if (i != 6)
154 return 0;
156 /* To isolate the test, don't rely on any external functions, such
157 as strcmp. */
158 s1 = "Hello, world\n";
159 s2 = str;
160 while (*s1 != '\0')
161 if (*s1++ != *s2++)
162 return 0;
163 if (*s2 != '\0')
164 return 0;
166 if (shlib_shlibvar1 () != 3)
167 return 0;
169 return 1;
172 #ifdef HIDDEN_WEAK_TEST
173 #define HIDDEN_UNDEF_TEST
174 #define WEAK_TEST
175 #endif
177 #ifdef PROTECTED_WEAK_TEST
178 #define PROTECTED_UNDEF_TEST
179 #define WEAK_TEST
180 #endif
182 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
183 #ifdef WEAK_TEST
184 #pragma weak visibility
185 #endif
186 extern int visibility ();
187 #else
189 visibility ()
191 return 2;
193 #endif
195 #ifdef HIDDEN_NORMAL_TEST
196 asm (".hidden visibility_normal");
199 visibility_normal ()
201 return 2;
203 #endif
206 visibility_checkfunptr ()
208 #ifdef WEAK_TEST
209 return 1;
210 #else
211 #ifdef HIDDEN_NORMAL_TEST
212 int (*v) () = visibility_normal;
213 #else
214 int (*v) () = visibility;
215 #endif
216 return (*v) () == 2;
217 #endif
221 visibility_check ()
223 #ifdef WEAK_TEST
224 if (&visibility)
225 return visibility () == 1;
226 else
227 return 1;
228 #else
229 #ifdef HIDDEN_NORMAL_TEST
230 return visibility_normal () == 2;
231 #else
232 return visibility () == 2;
233 #endif
234 #endif
237 void *
238 visibility_funptr ()
240 #ifdef WEAK_TEST
241 if (&visibility == NULL)
242 return NULL;
243 else
244 #endif
245 return visibility;
248 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
249 #ifdef WEAK_TEST
250 #pragma weak visibility_var
251 #endif
252 extern int visibility_var;
253 #else
254 int visibility_var = 2;
255 #endif
257 #ifdef HIDDEN_NORMAL_TEST
258 asm (".hidden visibility_var_normal");
260 int visibility_var_normal = 2;
261 #endif
264 visibility_checkvarptr ()
266 #ifdef WEAK_TEST
267 if (&visibility_var)
268 return visibility_var == 1;
269 else
270 return 1;
271 #else
272 #ifdef HIDDEN_NORMAL_TEST
273 int *v = &visibility_var_normal;
274 #else
275 int *v = &visibility_var;
276 #endif
277 return *v == 2;
278 #endif
282 visibility_checkvar ()
284 #ifdef WEAK_TEST
285 return 1;
286 #else
287 #ifdef HIDDEN_NORMAL_TEST
288 return visibility_var_normal == 2;
289 #else
290 return visibility_var == 2;
291 #endif
292 #endif
295 void *
296 visibility_varptr ()
298 #ifdef WEAK_TEST
299 if (&visibility_var == NULL)
300 return NULL;
301 else
302 #endif
303 return &visibility_var;
307 visibility_varval ()
309 #ifdef WEAK_TEST
310 if (&visibility_var == NULL)
311 return 0;
312 else
313 #endif
314 return visibility_var;
317 #if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
318 asm (".hidden visibility");
319 asm (".hidden visibility_var");
320 #else
321 #if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
322 asm (".protected visibility");
323 asm (".protected visibility_var");
324 #endif
325 #endif
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 ()
340 return 1;
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 ()
362 return 1;
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;
373 #else
375 shlib_visibility_checkcom ()
377 return 1;
381 shlib_visibility_checkweak ()
383 return 1;
385 #endif
387 #ifdef PROTECTED_TEST
388 int shared_data = 100;
390 int *
391 shared_data_p ()
393 return &shared_data;
397 shared_func ()
399 return 100;
402 void *
403 shared_func_p ()
405 return shared_func;
407 #endif