1 #ifndef NULL
2 #define NULL ((void *) 0)
3 #endif
4
5 /* This is part of the shared library ld test. This file becomes part
6 of a shared library. */
7
8 /* This variable is supplied by the main program. */
9 extern int mainvar;
10
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
24
25 /* This variable is defined in the shared library. */
26 int shlibvar1 = 3;
27
28 /* This variable is defined by another object in the shared library. */
29 extern int shlibvar2;
30
31 /* These functions return the values of the above variables as seen in
32 the shared library. */
33
34 int
35 shlib_mainvar ()
36 {
37 return mainvar;
38 }
39
40 #ifndef XCOFF_TEST
41 int
42 shlib_overriddenvar ()
43 {
44 return overriddenvar;
45 }
46 #endif
47
48 int
49 shlib_shlibvar1 ()
50 {
51 return shlibvar1;
52 }
53
54 int
55 shlib_shlibvar2 ()
56 {
57 return shlibvar2;
58 }
59
60 /* This function calls a function defined by another object in the
61 shared library. */
62
63 extern int shlib_shlibcalled ();
64
65 int
66 shlib_shlibcall ()
67 {
68 return shlib_shlibcalled ();
69 }
70
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. */
74
75 extern int shlib_overriddencall2 ();
76
77 int
78 shlib_shlibcall2 ()
79 {
80 return shlib_overriddencall2 ();
81 }
82
83 #ifdef SHARED
84 int
85 shlib_overriddencall2 ()
86 {
87 return 7;
88 }
89 #endif
90 #endif
91
92 /* This function calls a function defined by the main program. */
93
94 extern int main_called ();
95
96 int
97 shlib_maincall ()
98 {
99 return main_called ();
100 }
101
102 /* This function is passed a function pointer to shlib_mainvar. It
103 confirms that the pointer compares equally. */
104
105 int
106 shlib_checkfunptr1 (p)
107 int (*p) ();
108 {
109 return p == shlib_shlibvar1;
110 }
111
112 /* This function is passed a function pointer to main_called. It
113 confirms that the pointer compares equally. */
114
115 int
116 shlib_checkfunptr2 (p)
117 int (*p) ();
118 {
119 return p == main_called;
120 }
121
122 /* This function returns a pointer to shlib_mainvar. */
123
124 int
125 (*shlib_getfunptr1 ()) ()
126 {
127 return shlib_shlibvar1;
128 }
129
130 /* This function returns a pointer to main_called. */
131
132 int
133 (*shlib_getfunptr2 ()) ()
134 {
135 return main_called;
136 }
137
138 /* This function makes sure that constant data and local functions
139 work. */
140
141 #ifndef __STDC__
142 #define const
143 #endif
144
145 static int i = 6;
146 static const char *str = "Hello, world\n";
147
148 int
149 shlib_check ()
150 {
151 const char *s1, *s2;
152
153 if (i != 6)
154 return 0;
155
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;
165
166 if (shlib_shlibvar1 () != 3)
167 return 0;
168
169 return 1;
170 }
171
172 #ifdef HIDDEN_WEAK_TEST
173 #define HIDDEN_UNDEF_TEST
174 #define WEAK_TEST
175 #endif
176
177 #ifdef PROTECTED_WEAK_TEST
178 #define PROTECTED_UNDEF_TEST
179 #define WEAK_TEST
180 #endif
181
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
188 int
189 visibility ()
190 {
191 return 2;
192 }
193 #endif
194
195 #ifdef HIDDEN_NORMAL_TEST
196 __asm__ (".hidden visibility_normal");
197
198 int
199 visibility_normal ()
200 {
201 return 2;
202 }
203 #endif
204
205 int
206 visibility_checkfunptr ()
207 {
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
218 }
219
220 int
221 visibility_check ()
222 {
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
235 }
236
237 void *
238 visibility_funptr ()
239 {
240 #ifdef WEAK_TEST
241 if (&visibility == NULL)
242 return NULL;
243 else
244 #endif
245 return visibility;
246 }
247
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
256
257 #ifdef HIDDEN_NORMAL_TEST
258 __asm__ (".hidden visibility_var_normal");
259
260 int visibility_var_normal = 2;
261 #endif
262
263 int
264 visibility_checkvarptr ()
265 {
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
279 }
280
281 int
282 visibility_checkvar ()
283 {
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
293 }
294
295 void *
296 visibility_varptr ()
297 {
298 #ifdef WEAK_TEST
299 if (&visibility_var == NULL)
300 return NULL;
301 else
302 #endif
303 return &visibility_var;
304 }
305
306 int
307 visibility_varval ()
308 {
309 #ifdef WEAK_TEST
310 if (&visibility_var == NULL)
311 return 0;
312 else
313 #endif
314 return visibility_var;
315 }
316
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
326
327 #ifdef HIDDEN_NORMAL_TEST
328 int shlib_visibility_com;
329 __asm__ (".hidden shlib_visibility_com");
330
331 int
332 shlib_visibility_checkcom ()
333 {
334 return shlib_visibility_com == 0;
335 }
336
337 int
338 shlib_visibility_checkweak ()
339 {
340 return 1;
341 }
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");
346
347 #pragma weak shlib_visibility_undef_func_weak
348 extern int shlib_visibility_undef_func_weak ();
349 __asm__ (".hidden shlib_visibility_undef_func_weak");
350
351 #pragma weak shlib_visibility_var_weak
352 extern int shlib_visibility_var_weak;
353 __asm__ (".hidden shlib_visibility_var_weak");
354
355 #pragma weak shlib_visibility_func_weak
356 extern int shlib_visibility_func_weak ();
357 __asm__ (".hidden shlib_visibility_func_weak");
358
359 int
360 shlib_visibility_checkcom ()
361 {
362 return 1;
363 }
364
365 int
366 shlib_visibility_checkweak ()
367 {
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;
372 }
373 #else
374 int
375 shlib_visibility_checkcom ()
376 {
377 return 1;
378 }
379
380 int
381 shlib_visibility_checkweak ()
382 {
383 return 1;
384 }
385 #endif
386
387 #ifdef PROTECTED_TEST
388 #ifdef SHARED
389 int shared_data = 100;
390 #else
391 extern int shared_data;
392 #endif
393
394 int *
395 shared_data_p ()
396 {
397 return &shared_data;
398 }
399
400 int
401 shared_func ()
402 {
403 return 100;
404 }
405
406 void *
407 shared_func_p ()
408 {
409 return shared_func;
410 }
411 #endif