* elf32-spu.c (build_stub): Fix malloc under-allocation.
[binutils.git] / ld / testsuite / ld-elfvsb / main.c
blobb498d43459ea21c45917a8de0b0ffedb8ce6006f
1 #ifdef PROTECTED_CHECK
2 #include <features.h>
3 #include <stdio.h>
5 int
6 main (void)
8 #if defined (__GLIBC__) && (__GLIBC__ > 2 \
9 || (__GLIBC__ == 2 \
10 && __GLIBC_MINOR__ >= 2))
11 puts ("yes");
12 #else
13 puts ("no");
14 #endif
15 return 0;
17 #else
18 /* This is the main program for the shared library test. */
20 #include <stdio.h>
22 int mainvar = 1;
23 int overriddenvar = 2;
24 extern int shlibvar1;
26 extern int shlib_mainvar ();
27 extern int shlib_overriddenvar ();
28 extern int shlib_shlibvar1 ();
29 extern int shlib_shlibvar2 ();
30 extern int shlib_shlibcall ();
31 extern int shlib_maincall ();
32 extern int shlib_checkfunptr1 ();
33 extern int shlib_checkfunptr2 ();
34 extern int (*shlib_getfunptr1 ()) ();
35 extern int (*shlib_getfunptr2 ()) ();
36 extern int shlib_check ();
37 extern int shlib_shlibcall2 ();
38 extern int visibility_check ();
39 extern int visibility_checkfunptr ();
40 extern void *visibility_funptr ();
41 extern int visibility_checkvar ();
42 extern int visibility_checkvarptr ();
43 extern int visibility_varval ();
44 extern void *visibility_varptr ();
45 extern int shlib_visibility_checkcom ();
46 extern int shlib_visibility_checkweak ();
48 int shlib_visibility_com = 1;
50 int shlib_visibility_var_weak = 1;
52 int
53 shlib_visibility_func_weak ()
55 return 1;
58 #ifdef HIDDEN_WEAK_TEST
59 #define WEAK_TEST
60 #endif
62 #ifdef PROTECTED_WEAK_TEST
63 #define WEAK_TEST
64 #endif
66 #ifdef PROTECTED_UNDEF_TEST
67 #define PROTECTED_TEST
68 #endif
70 #ifndef WEAK_TEST
71 extern int visibility ();
72 extern int visibility_var;
73 #endif
75 #if !defined (HIDDEN_TEST) && defined (PROTECTED_TEST)
76 int
77 visibility (void)
79 return 1;
82 static int
83 main_visibility_check (void)
85 return ((int (*) (void)) visibility_funptr ()) != visibility;
88 int visibility_var = 1;
90 static int
91 main_visibility_checkvar (void)
93 return visibility_varval () != visibility_var
94 && visibility_varptr () != &visibility_var;
97 #ifndef PROTECTED_UNDEF_TEST
98 int shared_data = 1;
99 asm (".protected shared_data");
102 shared_func (void)
104 return 1;
107 asm (".protected shared_func");
109 extern int * shared_data_p ();
110 typedef int (*func) ();
111 extern func shared_func_p ();
112 #endif
113 #else
114 static int
115 main_visibility_check (void)
117 #ifdef WEAK_TEST
118 return visibility_funptr () == NULL;
119 #else
120 return ((int (*) (void)) visibility_funptr ()) == visibility;
121 #endif
124 static int
125 main_visibility_checkvar (void)
127 #ifdef WEAK_TEST
128 return visibility_varval () == 0
129 && visibility_varptr () == NULL;
130 #else
131 return visibility_varval () == visibility_var
132 && visibility_varptr () == &visibility_var;
133 #endif
135 #endif
137 /* This function is called by the shared library. */
140 main_called (void)
142 return 6;
145 /* This function overrides a function in the shared library. */
148 shlib_overriddencall2 (void)
150 return 8;
153 #ifdef HIDDEN_NORMAL_TEST
154 int visibility_com;
155 asm (".hidden visibility_com");
158 main_visibility_checkcom (void)
160 return visibility_com == 0;
164 main_visibility_checkweak (void)
166 return 1;
168 #elif defined (HIDDEN_WEAK_TEST)
170 main_visibility_checkcom (void)
172 return 1;
175 #pragma weak visibility_undef_var_weak
176 extern int visibility_undef_var_weak;
177 asm (".hidden visibility_undef_var_weak");
179 #pragma weak visibility_undef_func_weak
180 extern int visibility_undef_func_weak ();
181 asm (".hidden visibility_undef_func_weak");
183 #pragma weak visibility_var_weak
184 extern int visibility_var_weak;
185 asm (".hidden visibility_var_weak");
187 #pragma weak visibility_func_weak
188 extern int visibility_func_weak ();
189 asm (".hidden visibility_func_weak");
192 main_visibility_checkweak ()
194 return &visibility_undef_var_weak == NULL
195 && &visibility_undef_func_weak == NULL
196 && &visibility_func_weak == NULL
197 && &visibility_var_weak == NULL;
199 #elif defined (HIDDEN_UNDEF_TEST)
200 extern int visibility_def;
201 asm (".hidden visibility_def");
202 extern int visibility_func ();
203 asm (".hidden visibility_func");
206 main_visibility_checkcom (void)
208 return & visibility_def != NULL && visibility_def == 2;
212 main_visibility_checkweak (void)
214 return & visibility_func != NULL && visibility_func () == 2;
216 #else
218 main_visibility_checkcom (void)
220 return 1;
224 main_visibility_checkweak (void)
226 return 1;
228 #endif
231 main (void)
233 int (*p) ();
234 int ret = 0;
236 printf ("mainvar == %d\n", mainvar);
237 printf ("overriddenvar == %d\n", overriddenvar);
238 printf ("shlibvar1 == %d\n", shlibvar1);
239 #ifndef XCOFF_TEST
240 printf ("shlib_mainvar () == %d\n", shlib_mainvar ());
241 printf ("shlib_overriddenvar () == %d\n", shlib_overriddenvar ());
242 #endif
243 printf ("shlib_shlibvar1 () == %d\n", shlib_shlibvar1 ());
244 printf ("shlib_shlibvar2 () == %d\n", shlib_shlibvar2 ());
245 printf ("shlib_shlibcall () == %d\n", shlib_shlibcall ());
246 #ifndef XCOFF_TEST
247 printf ("shlib_shlibcall2 () == %d\n", shlib_shlibcall2 ());
248 printf ("shlib_maincall () == %d\n", shlib_maincall ());
249 #endif
250 printf ("main_called () == %d\n", main_called ());
251 printf ("shlib_checkfunptr1 (shlib_shlibvar1) == %d\n",
252 shlib_checkfunptr1 (shlib_shlibvar1));
253 #ifndef XCOFF_TEST
254 printf ("shlib_checkfunptr2 (main_called) == %d\n",
255 shlib_checkfunptr2 (main_called));
256 #endif
257 p = shlib_getfunptr1 ();
258 printf ("shlib_getfunptr1 () ");
259 if (p == shlib_shlibvar1)
260 printf ("==");
261 else
262 printf ("!=");
263 printf (" shlib_shlibvar1\n");
264 #ifndef XCOFF_TEST
265 p = shlib_getfunptr2 ();
266 printf ("shlib_getfunptr2 () ");
267 if (p == main_called)
268 printf ("==");
269 else
270 printf ("!=");
271 printf (" main_called\n");
272 #endif
273 printf ("shlib_check () == %d\n", shlib_check ());
274 printf ("visibility_check () == %d\n", visibility_check ());
275 printf ("visibility_checkfunptr () == %d\n",
276 visibility_checkfunptr ());
277 printf ("main_visibility_check () == %d\n", main_visibility_check ());
278 printf ("visibility_checkvar () == %d\n", visibility_checkvar ());
279 printf ("visibility_checkvarptr () == %d\n",
280 visibility_checkvarptr ());
281 printf ("main_visibility_checkvar () == %d\n",
282 main_visibility_checkvar ());
283 printf ("main_visibility_checkcom () == %d\n",
284 main_visibility_checkcom ());
285 printf ("shlib_visibility_checkcom () == %d\n",
286 shlib_visibility_checkcom ());
287 printf ("main_visibility_checkweak () == %d\n",
288 main_visibility_checkweak ());
289 printf ("shlib_visibility_checkweak () == %d\n",
290 shlib_visibility_checkweak ());
292 #if !defined (PROTECTED_UNDEF_TEST) && defined (PROTECTED_TEST)
293 if (&shared_data != shared_data_p ())
294 ret = 1;
295 p = shared_func_p ();
296 if (shared_func != p)
297 ret = 1;
298 if (shared_data != *shared_data_p ())
299 ret = 1;
300 if (shared_func () != (*p) () )
301 ret = 1;
302 #endif
304 return ret;
306 #endif