Automatic date update in version.in
[binutils-gdb.git] / ld / testsuite / ld-vsb / sh1.c
blob193eca2943bbd9034b963421a7917890714da2e1
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 extern int mainvar;
11 /* This variable is defined in the shared library, and overridden by
12 the main program. */
13 #ifndef XCOFF_TEST
14 #ifdef SHARED
15 /* SHARED is defined if we are compiling with -fpic/-fPIC. */
16 int overriddenvar = -1;
17 #else
18 /* Without -fpic, newer versions of gcc assume that we are not
19 compiling for a shared library, and thus that overriddenvar is
20 local. */
21 extern int overriddenvar;
22 #endif
23 #endif
25 /* This variable is defined in the shared library. */
26 int shlibvar1 = 3;
28 /* This variable is defined by another object in the shared library. */
29 extern int shlibvar2;
31 /* These functions return the values of the above variables as seen in
32 the shared library. */
34 int
35 shlib_mainvar ()
37 return mainvar;
40 #ifndef XCOFF_TEST
41 int
42 shlib_overriddenvar ()
44 return overriddenvar;
46 #endif
48 int
49 shlib_shlibvar1 ()
51 return shlibvar1;
54 int
55 shlib_shlibvar2 ()
57 return shlibvar2;
60 /* This function calls a function defined by another object in the
61 shared library. */
63 extern int shlib_shlibcalled ();
65 int
66 shlib_shlibcall ()
68 return shlib_shlibcalled ();
71 #ifndef XCOFF_TEST
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 ();
77 int
78 shlib_shlibcall2 ()
80 return shlib_overriddencall2 ();
83 #ifdef SHARED
84 int
85 shlib_overriddencall2 ()
87 return 7;
89 #endif
90 #endif
92 /* This function calls a function defined by the main program. */
94 extern int main_called ();
96 int
97 shlib_maincall ()
99 return main_called ();
102 /* This function is passed a function pointer to shlib_mainvar. It
103 confirms that the pointer compares equally. */
105 int
106 shlib_checkfunptr1 (p)
107 int (*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)
117 int (*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 ()) ()
135 return main_called;
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 #ifdef SHARED
389 int shared_data = 100;
390 #else
391 extern int shared_data;
392 #endif
394 int *
395 shared_data_p ()
397 return &shared_data;
401 shared_func ()
403 return 100;
406 void *
407 shared_func_p ()
409 return shared_func;
411 #endif