2000-10-31 Philip Blundell <philb@gnu.org>
[binutils.git] / ld / testsuite / ld-elfvsb / sh1.c
blob2299f83bdc36715fcc8a3fb6e8b777f03a794d2e
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 extern int visibility ();
184 #else
186 visibility ()
188 return 2;
190 #endif
192 #ifdef HIDDEN_NORMAL_TEST
193 asm (".hidden visibility_normal");
196 visibility_normal ()
198 return 2;
200 #endif
203 visibility_checkfunptr ()
205 #ifdef WEAK_TEST
206 return 1;
207 #else
208 #ifdef HIDDEN_NORMAL_TEST
209 int (*v) () = visibility_normal;
210 #else
211 int (*v) () = visibility;
212 #endif
213 return (*v) () == 2;
214 #endif
218 visibility_check ()
220 #ifdef WEAK_TEST
221 if (&visibility)
222 return visibility () == 1;
223 else
224 return 1;
225 #else
226 #ifdef HIDDEN_NORMAL_TEST
227 return visibility_normal () == 2;
228 #else
229 return visibility () == 2;
230 #endif
231 #endif
234 void *
235 visibility_funptr ()
237 #ifdef WEAK_TEST
238 if (&visibility == NULL)
239 return NULL;
240 else
241 #endif
242 return visibility;
245 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
246 extern int visibility_var;
247 #else
248 int visibility_var = 2;
249 #endif
251 #ifdef HIDDEN_NORMAL_TEST
252 asm (".hidden visibility_var_normal");
254 int visibility_var_normal = 2;
255 #endif
258 visibility_checkvarptr ()
260 #ifdef WEAK_TEST
261 if (&visibility_var)
262 return visibility_var == 1;
263 else
264 return 1;
265 #else
266 #ifdef HIDDEN_NORMAL_TEST
267 int *v = &visibility_var_normal;
268 #else
269 int *v = &visibility_var;
270 #endif
271 return *v == 2;
272 #endif
276 visibility_checkvar ()
278 #ifdef WEAK_TEST
279 return 1;
280 #else
281 #ifdef HIDDEN_NORMAL_TEST
282 return visibility_var_normal == 2;
283 #else
284 return visibility_var == 2;
285 #endif
286 #endif
289 void *
290 visibility_varptr ()
292 #ifdef WEAK_TEST
293 if (&visibility_var == NULL)
294 return NULL;
295 else
296 #endif
297 return &visibility_var;
301 visibility_varval ()
303 #ifdef WEAK_TEST
304 if (&visibility_var == NULL)
305 return 0;
306 else
307 #endif
308 return visibility_var;
311 #if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
312 asm (".hidden visibility");
313 asm (".hidden visibility_var");
314 #else
315 #if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
316 asm (".protected visibility");
317 asm (".protected visibility_var");
318 #endif
319 #endif
321 #ifdef WEAK_TEST
322 asm (".weak visibility");
323 asm (".weak visibility_var");
324 #endif