Add missing files.
[binutils.git] / ld / testsuite / ld-elfvsb / sh1.c
blobb2754249af70e230ed141e03f13085a64168d48d
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 #ifdef SHARED
17 /* SHARED is defined if we are compiling with -fpic/-fPIC. */
18 int overriddenvar = -1;
19 #else
20 /* Without -fpic, newer versions of gcc assume that we are not
21 compiling for a shared library, and thus that overriddenvar is
22 local. */
23 extern int overriddenvar;
24 #endif
25 #endif
27 /* This variable is defined in the shared library. */
28 int shlibvar1 = 3;
30 /* This variable is defined by another object in the shared library. */
31 extern int shlibvar2;
33 /* These functions return the values of the above variables as seen in
34 the shared library. */
36 #ifndef XCOFF_TEST
37 int
38 shlib_mainvar ()
40 return mainvar;
42 #endif
44 #ifndef XCOFF_TEST
45 int
46 shlib_overriddenvar ()
48 return overriddenvar;
50 #endif
52 int
53 shlib_shlibvar1 ()
55 return shlibvar1;
58 int
59 shlib_shlibvar2 ()
61 return shlibvar2;
64 /* This function calls a function defined by another object in the
65 shared library. */
67 extern int shlib_shlibcalled ();
69 int
70 shlib_shlibcall ()
72 return shlib_shlibcalled ();
75 #ifndef XCOFF_TEST
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 ();
81 int
82 shlib_shlibcall2 ()
84 return shlib_overriddencall2 ();
87 #ifdef SHARED
88 int
89 shlib_overriddencall2 ()
91 return 7;
93 #endif
94 #endif
96 /* This function calls a function defined by the main program. */
98 #ifndef XCOFF_TEST
99 extern int main_called ();
102 shlib_maincall ()
104 return main_called ();
106 #endif
108 /* This function is passed a function pointer to shlib_mainvar. It
109 confirms that the pointer compares equally. */
111 int
112 shlib_checkfunptr1 (p)
113 int (*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. */
121 #ifndef XCOFF_TEST
123 shlib_checkfunptr2 (p)
124 int (*p) ();
126 return p == main_called;
128 #endif
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. */
140 #ifndef XCOFF_TEST
142 (*shlib_getfunptr2 ()) ()
144 return main_called;
146 #endif
148 /* This function makes sure that constant data and local functions
149 work. */
151 #ifndef __STDC__
152 #define const
153 #endif
155 static int i = 6;
156 static const char *str = "Hello, world\n";
159 shlib_check ()
161 const char *s1, *s2;
163 if (i != 6)
164 return 0;
166 /* To isolate the test, don't rely on any external functions, such
167 as strcmp. */
168 s1 = "Hello, world\n";
169 s2 = str;
170 while (*s1 != '\0')
171 if (*s1++ != *s2++)
172 return 0;
173 if (*s2 != '\0')
174 return 0;
176 if (shlib_shlibvar1 () != 3)
177 return 0;
179 return 1;
182 #ifdef HIDDEN_WEAK_TEST
183 #define HIDDEN_UNDEF_TEST
184 #define WEAK_TEST
185 #endif
187 #ifdef PROTECTED_WEAK_TEST
188 #define PROTECTED_UNDEF_TEST
189 #define WEAK_TEST
190 #endif
192 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
193 #ifdef WEAK_TEST
194 #pragma weak visibility
195 #endif
196 extern int visibility ();
197 #else
199 visibility ()
201 return 2;
203 #endif
205 #ifdef HIDDEN_NORMAL_TEST
206 asm (".hidden visibility_normal");
209 visibility_normal ()
211 return 2;
213 #endif
216 visibility_checkfunptr ()
218 #ifdef WEAK_TEST
219 return 1;
220 #else
221 #ifdef HIDDEN_NORMAL_TEST
222 int (*v) () = visibility_normal;
223 #else
224 int (*v) () = visibility;
225 #endif
226 return (*v) () == 2;
227 #endif
231 visibility_check ()
233 #ifdef WEAK_TEST
234 if (&visibility)
235 return visibility () == 1;
236 else
237 return 1;
238 #else
239 #ifdef HIDDEN_NORMAL_TEST
240 return visibility_normal () == 2;
241 #else
242 return visibility () == 2;
243 #endif
244 #endif
247 void *
248 visibility_funptr ()
250 #ifdef WEAK_TEST
251 if (&visibility == NULL)
252 return NULL;
253 else
254 #endif
255 return visibility;
258 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
259 #ifdef WEAK_TEST
260 #pragma weak visibility_var
261 #endif
262 extern int visibility_var;
263 #else
264 int visibility_var = 2;
265 #endif
267 #ifdef HIDDEN_NORMAL_TEST
268 asm (".hidden visibility_var_normal");
270 int visibility_var_normal = 2;
271 #endif
274 visibility_checkvarptr ()
276 #ifdef WEAK_TEST
277 if (&visibility_var)
278 return visibility_var == 1;
279 else
280 return 1;
281 #else
282 #ifdef HIDDEN_NORMAL_TEST
283 int *v = &visibility_var_normal;
284 #else
285 int *v = &visibility_var;
286 #endif
287 return *v == 2;
288 #endif
292 visibility_checkvar ()
294 #ifdef WEAK_TEST
295 return 1;
296 #else
297 #ifdef HIDDEN_NORMAL_TEST
298 return visibility_var_normal == 2;
299 #else
300 return visibility_var == 2;
301 #endif
302 #endif
305 void *
306 visibility_varptr ()
308 #ifdef WEAK_TEST
309 if (&visibility_var == NULL)
310 return NULL;
311 else
312 #endif
313 return &visibility_var;
317 visibility_varval ()
319 #ifdef WEAK_TEST
320 if (&visibility_var == NULL)
321 return 0;
322 else
323 #endif
324 return visibility_var;
327 #if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
328 asm (".hidden visibility");
329 asm (".hidden visibility_var");
330 #else
331 #if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
332 asm (".protected visibility");
333 asm (".protected visibility_var");
334 #endif
335 #endif
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 ()
350 return 1;
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 ()
372 return 1;
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;
383 #else
385 shlib_visibility_checkcom ()
387 return 1;
391 shlib_visibility_checkweak ()
393 return 1;
395 #endif
397 #ifdef PROTECTED_TEST
398 #ifdef SHARED
399 int shared_data = 100;
400 #else
401 extern int shared_data;
402 #endif
404 int *
405 shared_data_p ()
407 return &shared_data;
411 shared_func ()
413 return 100;
416 void *
417 shared_func_p ()
419 return shared_func;
421 #endif