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 10extern 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 16int overriddenvar = -1; 17#endif 18 19/* This variable is defined in the shared library. */ 20int shlibvar1 = 3; 21 22/* This variable is defined by another object in the shared library. */ 23extern 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 29int 30shlib_mainvar () 31{ 32 return mainvar; 33} 34#endif 35 36#ifndef XCOFF_TEST 37int 38shlib_overriddenvar () 39{ 40 return overriddenvar; 41} 42#endif 43 44int 45shlib_shlibvar1 () 46{ 47 return shlibvar1; 48} 49 50int 51shlib_shlibvar2 () 52{ 53 return shlibvar2; 54} 55 56/* This function calls a function defined by another object in the 57 shared library. */ 58 59extern int shlib_shlibcalled (); 60 61int 62shlib_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 71extern int shlib_overriddencall2 (); 72 73int 74shlib_shlibcall2 () 75{ 76 return shlib_overriddencall2 (); 77} 78 79int 80shlib_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 89extern int main_called (); 90 91int 92shlib_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 101int 102shlib_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 112int 113shlib_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 122int 123(*shlib_getfunptr1 ()) () 124{ 125 return shlib_shlibvar1; 126} 127 128/* This function returns a pointer to main_called. */ 129 130#ifndef XCOFF_TEST 131int 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 145static int i = 6; 146static const char *str = "Hello, world\n"; 147 148int 149shlib_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 186extern int visibility (); 187#else 188int 189visibility () 190{ 191 return 2; 192} 193#endif 194 195#ifdef HIDDEN_NORMAL_TEST 196asm (".hidden visibility_normal"); 197 198int 199visibility_normal () 200{ 201 return 2; 202} 203#endif 204 205int 206visibility_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 220int 221visibility_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 237void * 238visibility_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 252extern int visibility_var; 253#else 254int visibility_var = 2; 255#endif 256 257#ifdef HIDDEN_NORMAL_TEST 258asm (".hidden visibility_var_normal"); 259 260int visibility_var_normal = 2; 261#endif 262 263int 264visibility_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 281int 282visibility_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 295void * 296visibility_varptr () 297{ 298#ifdef WEAK_TEST 299 if (&visibility_var == NULL) 300 return NULL; 301 else 302#endif 303 return &visibility_var; 304} 305 306int 307visibility_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) 318asm (".hidden visibility"); 319asm (".hidden visibility_var"); 320#else 321#if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST) 322asm (".protected visibility"); 323asm (".protected visibility_var"); 324#endif 325#endif 326 327#ifdef HIDDEN_NORMAL_TEST 328int shlib_visibility_com; 329asm (".hidden shlib_visibility_com"); 330 331int 332shlib_visibility_checkcom () 333{ 334 return shlib_visibility_com == 0; 335} 336 337int 338shlib_visibility_checkweak () 339{ 340 return 1; 341} 342#elif defined (HIDDEN_WEAK_TEST) 343#pragma weak shlib_visibility_undef_var_weak 344extern int shlib_visibility_undef_var_weak; 345asm (".hidden shlib_visibility_undef_var_weak"); 346 347#pragma weak shlib_visibility_undef_func_weak 348extern int shlib_visibility_undef_func_weak (); 349asm (".hidden shlib_visibility_undef_func_weak"); 350 351#pragma weak shlib_visibility_var_weak 352extern int shlib_visibility_var_weak; 353asm (".hidden shlib_visibility_var_weak"); 354 355#pragma weak shlib_visibility_func_weak 356extern int shlib_visibility_func_weak (); 357asm (".hidden shlib_visibility_func_weak"); 358 359int 360shlib_visibility_checkcom () 361{ 362 return 1; 363} 364 365int 366shlib_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 374int 375shlib_visibility_checkcom () 376{ 377 return 1; 378} 379 380int 381shlib_visibility_checkweak () 382{ 383 return 1; 384} 385#endif 386 387#ifdef PROTECTED_TEST 388int shared_data = 100; 389 390int * 391shared_data_p () 392{ 393 return &shared_data; 394} 395 396int 397shared_func () 398{ 399 return 100; 400} 401 402void * 403shared_func_p () 404{ 405 return shared_func; 406} 407#endif 408