2000-10-31 Philip Blundell <philb@gnu.org>
[binutils.git] / ld / testsuite / ld-elfvsb / main.c
bloba00b70feddb1505d08e5318e5052f101e0414700
1 #ifdef PROTECTED_CHECK
2 #include <features.h>
4 int
5 main (argc, argv)
6 int argc;
7 char *argv[];
9 #if defined (__GLIBC__) && (__GLIBC__ > 2 \
10 || (__GLIBC__ == 2 \
11 && __GLIBC_MINOR__ >= 2))
12 puts ("yes");
13 #else
14 puts ("no");
15 #endif
16 return 0;
18 #else
19 /* This is the main program for the shared library test. */
21 #include <stdio.h>
23 int mainvar = 1;
24 int overriddenvar = 2;
25 extern int shlibvar1;
27 extern int shlib_mainvar ();
28 extern int shlib_overriddenvar ();
29 extern int shlib_shlibvar1 ();
30 extern int shlib_shlibvar2 ();
31 extern int shlib_shlibcall ();
32 extern int shlib_maincall ();
33 extern int shlib_checkfunptr1 ();
34 extern int shlib_checkfunptr2 ();
35 extern int (*shlib_getfunptr1 ()) ();
36 extern int (*shlib_getfunptr2 ()) ();
37 extern int shlib_check ();
38 extern int shlib_shlibcall2 ();
39 extern int visibility_check ();
40 extern int visibility_checkfunptr ();
41 extern void *visibility_funptr ();
42 extern int visibility_checkvar ();
43 extern int visibility_checkvarptr ();
44 extern int visibility_varval ();
45 extern void *visibility_varptr ();
47 #ifdef HIDDEN_WEAK_TEST
48 #define WEAK_TEST
49 #endif
51 #ifdef PROTECTED_WEAK_TEST
52 #define WEAK_TEST
53 #endif
55 #ifdef PROTECTED_UNDEF_TEST
56 #define PROTECTED_TEST
57 #endif
59 #ifndef WEAK_TEST
60 extern int visibility ();
61 extern int visibility_var;
62 #endif
64 #if !defined (HIDDEN_TEST) && defined (PROTECTED_TEST)
65 int
66 visibility ()
68 return 1;
71 static int
72 main_visibility_check ()
74 return visibility_funptr () != visibility;
77 int visibility_var = 1;
79 static int
80 main_visibility_checkvar ()
82 return visibility_varval () != visibility_var
83 && visibility_varptr () != &visibility_var;
85 #else
86 static int
87 main_visibility_check ()
89 #ifdef WEAK_TEST
90 return visibility_funptr () == NULL;
91 #else
92 return visibility_funptr () == visibility;
93 #endif
96 static int
97 main_visibility_checkvar ()
99 #ifdef WEAK_TEST
100 return visibility_varval () == 0
101 && visibility_varptr () == NULL;
102 #else
103 return visibility_varval () == visibility_var
104 && visibility_varptr () == &visibility_var;
105 #endif
107 #endif
109 /* This function is called by the shared library. */
112 main_called ()
114 return 6;
117 /* This function overrides a function in the shared library. */
120 shlib_overriddencall2 ()
122 return 8;
126 main ()
128 int (*p) ();
130 printf ("mainvar == %d\n", mainvar);
131 printf ("overriddenvar == %d\n", overriddenvar);
132 printf ("shlibvar1 == %d\n", shlibvar1);
133 #ifndef XCOFF_TEST
134 printf ("shlib_mainvar () == %d\n", shlib_mainvar ());
135 printf ("shlib_overriddenvar () == %d\n", shlib_overriddenvar ());
136 #endif
137 printf ("shlib_shlibvar1 () == %d\n", shlib_shlibvar1 ());
138 printf ("shlib_shlibvar2 () == %d\n", shlib_shlibvar2 ());
139 printf ("shlib_shlibcall () == %d\n", shlib_shlibcall ());
140 #ifndef XCOFF_TEST
141 printf ("shlib_shlibcall2 () == %d\n", shlib_shlibcall2 ());
142 printf ("shlib_maincall () == %d\n", shlib_maincall ());
143 #endif
144 printf ("main_called () == %d\n", main_called ());
145 printf ("shlib_checkfunptr1 (shlib_shlibvar1) == %d\n",
146 shlib_checkfunptr1 (shlib_shlibvar1));
147 #ifndef XCOFF_TEST
148 printf ("shlib_checkfunptr2 (main_called) == %d\n",
149 shlib_checkfunptr2 (main_called));
150 #endif
151 p = shlib_getfunptr1 ();
152 printf ("shlib_getfunptr1 () ");
153 if (p == shlib_shlibvar1)
154 printf ("==");
155 else
156 printf ("!=");
157 printf (" shlib_shlibvar1\n");
158 #ifndef XCOFF_TEST
159 p = shlib_getfunptr2 ();
160 printf ("shlib_getfunptr2 () ");
161 if (p == main_called)
162 printf ("==");
163 else
164 printf ("!=");
165 printf (" main_called\n");
166 #endif
167 printf ("shlib_check () == %d\n", shlib_check ());
168 printf ("visibility_check () == %d\n", visibility_check ());
169 printf ("visibility_checkfunptr () == %d\n",
170 visibility_checkfunptr ());
171 printf ("main_visibility_check () == %d\n", main_visibility_check ());
172 printf ("visibility_checkvar () == %d\n", visibility_checkvar ());
173 printf ("visibility_checkvarptr () == %d\n",
174 visibility_checkvarptr ());
175 printf ("main_visibility_checkvar () == %d\n",
176 main_visibility_checkvar ());
177 return 0;
179 #endif