| 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 |
#ifndef XCOFF_TEST |
| 10 |
extern int mainvar; |
| 11 |
#endif |
| 12 |
|
| 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 |
| 18 |
|
| 19 |
/* This variable is defined in the shared library. */ |
| 20 |
int shlibvar1 = 3; |
| 21 |
|
| 22 |
/* This variable is defined by another object in the shared library. */ |
| 23 |
extern int shlibvar2; |
| 24 |
|
| 25 |
/* These functions return the values of the above variables as seen in |
| 26 |
the shared library. */ |
| 27 |
|
| 28 |
#ifndef XCOFF_TEST |
| 29 |
int |
| 30 |
shlib_mainvar () |
| 31 |
{ |
| 32 |
return mainvar; |
| 33 |
} |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef XCOFF_TEST |
| 37 |
int |
| 38 |
shlib_overriddenvar () |
| 39 |
{ |
| 40 |
return overriddenvar; |
| 41 |
} |
| 42 |
#endif |
| 43 |
|
| 44 |
int |
| 45 |
shlib_shlibvar1 () |
| 46 |
{ |
| 47 |
return shlibvar1; |
| 48 |
} |
| 49 |
|
| 50 |
int |
| 51 |
shlib_shlibvar2 () |
| 52 |
{ |
| 53 |
return shlibvar2; |
| 54 |
} |
| 55 |
|
| 56 |
/* This function calls a function defined by another object in the |
| 57 |
shared library. */ |
| 58 |
|
| 59 |
extern int shlib_shlibcalled (); |
| 60 |
|
| 61 |
int |
| 62 |
shlib_shlibcall () |
| 63 |
{ |
| 64 |
return shlib_shlibcalled (); |
| 65 |
} |
| 66 |
|
| 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. */ |
| 70 |
|
| 71 |
extern int shlib_overriddencall2 (); |
| 72 |
|
| 73 |
int |
| 74 |
shlib_shlibcall2 () |
| 75 |
{ |
| 76 |
return shlib_overriddencall2 (); |
| 77 |
} |
| 78 |
|
| 79 |
int |
| 80 |
shlib_overriddencall2 () |
| 81 |
{ |
| 82 |
return 7; |
| 83 |
} |
| 84 |
#endif |
| 85 |
|
| 86 |
/* This function calls a function defined by the main program. */ |
| 87 |
|
| 88 |
#ifndef XCOFF_TEST |
| 89 |
extern int main_called (); |
| 90 |
|
| 91 |
int |
| 92 |
shlib_maincall () |
| 93 |
{ |
| 94 |
return main_called (); |
| 95 |
} |
| 96 |
#endif |
| 97 |
|
| 98 |
/* This function is passed a function pointer to shlib_mainvar. It |
| 99 |
confirms that the pointer compares equally. */ |
| 100 |
|
| 101 |
int |
| 102 |
shlib_checkfunptr1 (p) |
| 103 |
int (*p) (); |
| 104 |
{ |
| 105 |
return p == shlib_shlibvar1; |
| 106 |
} |
| 107 |
|
| 108 |
/* This function is passed a function pointer to main_called. It |
| 109 |
confirms that the pointer compares equally. */ |
| 110 |
|
| 111 |
#ifndef XCOFF_TEST |
| 112 |
int |
| 113 |
shlib_checkfunptr2 (p) |
| 114 |
int (*p) (); |
| 115 |
{ |
| 116 |
return p == main_called; |
| 117 |
} |
| 118 |
#endif |
| 119 |
|
| 120 |
/* This function returns a pointer to shlib_mainvar. */ |
| 121 |
|
| 122 |
int |
| 123 |
(*shlib_getfunptr1 ()) () |
| 124 |
{ |
| 125 |
return shlib_shlibvar1; |
| 126 |
} |
| 127 |
|
| 128 |
/* This function returns a pointer to main_called. */ |
| 129 |
|
| 130 |
#ifndef XCOFF_TEST |
| 131 |
int |
| 132 |
(*shlib_getfunptr2 ()) () |
| 133 |
{ |
| 134 |
return main_called; |
| 135 |
} |
| 136 |
#endif |
| 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 |
int shared_data = 100; |
| 389 |
|
| 390 |
int * |
| 391 |
shared_data_p () |
| 392 |
{ |
| 393 |
return &shared_data; |
| 394 |
} |
| 395 |
|
| 396 |
int |
| 397 |
shared_func () |
| 398 |
{ |
| 399 |
return 100; |
| 400 |
} |
| 401 |
|
| 402 |
void * |
| 403 |
shared_func_p () |
| 404 |
{ |
| 405 |
return shared_func; |
| 406 |
} |
| 407 |
#endif |