Back to index

cell-binutils  2.17cvs20070401
sh1.c
Go to the documentation of this file.
00001 #ifndef NULL
00002 #define NULL ((void *) 0)
00003 #endif
00004 
00005 /* This is part of the shared library ld test.  This file becomes part
00006    of a shared library.  */
00007 
00008 /* This variable is supplied by the main program.  */
00009 #ifndef XCOFF_TEST
00010 extern int mainvar;
00011 #endif
00012 
00013 /* This variable is defined in the shared library, and overridden by
00014    the main program.  */
00015 #ifndef XCOFF_TEST
00016 #ifdef SHARED
00017 /* SHARED is defined if we are compiling with -fpic/-fPIC.  */
00018 int overriddenvar = -1;
00019 #else
00020 /* Without -fpic, newer versions of gcc assume that we are not
00021    compiling for a shared library, and thus that overriddenvar is
00022    local.  */
00023 extern int overriddenvar;
00024 #endif
00025 #endif
00026 
00027 /* This variable is defined in the shared library.  */
00028 int shlibvar1 = 3;
00029 
00030 /* This variable is defined by another object in the shared library.  */
00031 extern int shlibvar2;
00032 
00033 /* These functions return the values of the above variables as seen in
00034    the shared library.  */
00035 
00036 #ifndef XCOFF_TEST
00037 int
00038 shlib_mainvar ()
00039 {
00040   return mainvar;
00041 }
00042 #endif
00043 
00044 #ifndef XCOFF_TEST
00045 int
00046 shlib_overriddenvar ()
00047 {
00048   return overriddenvar;
00049 }
00050 #endif
00051 
00052 int
00053 shlib_shlibvar1 ()
00054 {
00055   return shlibvar1;
00056 }
00057 
00058 int
00059 shlib_shlibvar2 ()
00060 {
00061   return shlibvar2;
00062 }
00063 
00064 /* This function calls a function defined by another object in the
00065    shared library.  */
00066 
00067 extern int shlib_shlibcalled ();
00068 
00069 int
00070 shlib_shlibcall ()
00071 {
00072   return shlib_shlibcalled ();
00073 }
00074 
00075 #ifndef XCOFF_TEST
00076 /* This function calls a function defined in this object in the shared
00077    library.  The main program will override the called function.  */
00078 
00079 extern int shlib_overriddencall2 ();
00080 
00081 int
00082 shlib_shlibcall2 ()
00083 {
00084   return shlib_overriddencall2 ();
00085 }
00086 
00087 #ifdef SHARED
00088 int
00089 shlib_overriddencall2 ()
00090 {
00091   return 7;
00092 }
00093 #endif
00094 #endif
00095 
00096 /* This function calls a function defined by the main program.  */
00097 
00098 #ifndef XCOFF_TEST
00099 extern int main_called ();
00100 
00101 int
00102 shlib_maincall ()
00103 {
00104   return main_called ();
00105 }
00106 #endif
00107 
00108 /* This function is passed a function pointer to shlib_mainvar.  It
00109    confirms that the pointer compares equally.  */
00110 
00111 int 
00112 shlib_checkfunptr1 (p)
00113      int (*p) ();
00114 {
00115   return p == shlib_shlibvar1;
00116 }
00117 
00118 /* This function is passed a function pointer to main_called.  It
00119    confirms that the pointer compares equally.  */
00120 
00121 #ifndef XCOFF_TEST
00122 int
00123 shlib_checkfunptr2 (p)
00124      int (*p) ();
00125 {
00126   return p == main_called;
00127 }
00128 #endif
00129 
00130 /* This function returns a pointer to shlib_mainvar.  */
00131 
00132 int
00133 (*shlib_getfunptr1 ()) ()
00134 {
00135   return shlib_shlibvar1;
00136 }
00137 
00138 /* This function returns a pointer to main_called.  */
00139 
00140 #ifndef XCOFF_TEST
00141 int
00142 (*shlib_getfunptr2 ()) ()
00143 {
00144   return main_called;
00145 }
00146 #endif
00147 
00148 /* This function makes sure that constant data and local functions
00149    work.  */
00150 
00151 #ifndef __STDC__
00152 #define const
00153 #endif
00154 
00155 static int i = 6;
00156 static const char *str = "Hello, world\n";
00157 
00158 int
00159 shlib_check ()
00160 {
00161   const char *s1, *s2;
00162 
00163   if (i != 6)
00164     return 0;
00165 
00166   /* To isolate the test, don't rely on any external functions, such
00167      as strcmp.  */
00168   s1 = "Hello, world\n";
00169   s2 = str;
00170   while (*s1 != '\0')
00171     if (*s1++ != *s2++)
00172       return 0;
00173   if (*s2 != '\0')
00174     return 0;
00175 
00176   if (shlib_shlibvar1 () != 3)
00177     return 0;
00178 
00179   return 1;
00180 }
00181 
00182 #ifdef HIDDEN_WEAK_TEST
00183 #define HIDDEN_UNDEF_TEST
00184 #define WEAK_TEST
00185 #endif
00186 
00187 #ifdef PROTECTED_WEAK_TEST
00188 #define PROTECTED_UNDEF_TEST
00189 #define WEAK_TEST
00190 #endif
00191 
00192 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
00193 #ifdef WEAK_TEST
00194 #pragma weak visibility
00195 #endif
00196 extern int visibility ();
00197 #else
00198 int
00199 visibility ()
00200 {
00201   return 2;
00202 }
00203 #endif
00204 
00205 #ifdef HIDDEN_NORMAL_TEST
00206 asm (".hidden visibility_normal");
00207 
00208 int
00209 visibility_normal ()
00210 {
00211   return 2;
00212 }
00213 #endif
00214 
00215 int
00216 visibility_checkfunptr ()
00217 {
00218 #ifdef WEAK_TEST
00219   return 1;
00220 #else
00221 #ifdef HIDDEN_NORMAL_TEST
00222   int (*v) () = visibility_normal;
00223 #else
00224   int (*v) () = visibility;
00225 #endif
00226   return (*v) () == 2;
00227 #endif
00228 }
00229 
00230 int
00231 visibility_check ()
00232 {
00233 #ifdef WEAK_TEST
00234   if (&visibility)
00235     return visibility () == 1;
00236   else
00237     return 1;
00238 #else
00239 #ifdef HIDDEN_NORMAL_TEST
00240   return visibility_normal () == 2;
00241 #else
00242   return visibility () == 2;
00243 #endif
00244 #endif
00245 }
00246 
00247 void *
00248 visibility_funptr ()
00249 {
00250 #ifdef WEAK_TEST
00251   if (&visibility == NULL)
00252     return NULL;
00253   else
00254 #endif
00255     return visibility;
00256 }
00257 
00258 #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
00259 #ifdef WEAK_TEST
00260 #pragma weak visibility_var
00261 #endif
00262 extern int visibility_var;
00263 #else
00264 int visibility_var = 2;
00265 #endif
00266 
00267 #ifdef HIDDEN_NORMAL_TEST
00268 asm (".hidden visibility_var_normal");
00269 
00270 int visibility_var_normal = 2;
00271 #endif
00272 
00273 int
00274 visibility_checkvarptr ()
00275 {
00276 #ifdef WEAK_TEST
00277   if (&visibility_var)
00278     return visibility_var == 1;
00279   else
00280     return 1;
00281 #else
00282 #ifdef HIDDEN_NORMAL_TEST
00283   int *v = &visibility_var_normal;
00284 #else
00285   int *v = &visibility_var;
00286 #endif
00287   return *v == 2;
00288 #endif
00289 }
00290 
00291 int
00292 visibility_checkvar ()
00293 {
00294 #ifdef WEAK_TEST
00295   return 1;
00296 #else
00297 #ifdef HIDDEN_NORMAL_TEST
00298   return visibility_var_normal == 2;
00299 #else
00300   return visibility_var == 2;
00301 #endif
00302 #endif
00303 }
00304 
00305 void *
00306 visibility_varptr ()
00307 {
00308 #ifdef WEAK_TEST
00309   if (&visibility_var == NULL)
00310     return NULL;
00311   else
00312 #endif
00313     return &visibility_var;
00314 }
00315 
00316 int
00317 visibility_varval ()
00318 {
00319 #ifdef WEAK_TEST
00320   if (&visibility_var == NULL)
00321     return 0;
00322   else
00323 #endif
00324     return visibility_var;
00325 }
00326 
00327 #if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
00328 asm (".hidden visibility");
00329 asm (".hidden visibility_var");
00330 #else
00331 #if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
00332 asm (".protected visibility");
00333 asm (".protected visibility_var");
00334 #endif
00335 #endif
00336 
00337 #ifdef HIDDEN_NORMAL_TEST
00338 int shlib_visibility_com;
00339 asm (".hidden shlib_visibility_com");
00340 
00341 int
00342 shlib_visibility_checkcom ()
00343 {
00344   return shlib_visibility_com == 0;
00345 }
00346 
00347 int
00348 shlib_visibility_checkweak ()
00349 {
00350   return 1;
00351 }
00352 #elif defined (HIDDEN_WEAK_TEST)
00353 #pragma weak shlib_visibility_undef_var_weak
00354 extern int shlib_visibility_undef_var_weak;
00355 asm (".hidden shlib_visibility_undef_var_weak");
00356 
00357 #pragma weak shlib_visibility_undef_func_weak
00358 extern int shlib_visibility_undef_func_weak ();
00359 asm (".hidden shlib_visibility_undef_func_weak");
00360 
00361 #pragma weak shlib_visibility_var_weak
00362 extern int shlib_visibility_var_weak;
00363 asm (".hidden shlib_visibility_var_weak");
00364 
00365 #pragma weak shlib_visibility_func_weak
00366 extern int shlib_visibility_func_weak ();
00367 asm (".hidden shlib_visibility_func_weak");
00368 
00369 int
00370 shlib_visibility_checkcom ()
00371 {
00372   return 1;
00373 }
00374 
00375 int
00376 shlib_visibility_checkweak ()
00377 {
00378   return &shlib_visibility_undef_var_weak == NULL
00379         && &shlib_visibility_undef_func_weak == NULL
00380         && &shlib_visibility_func_weak == NULL
00381         && &shlib_visibility_var_weak == NULL;
00382 }
00383 #else
00384 int
00385 shlib_visibility_checkcom ()
00386 {
00387   return 1;
00388 }
00389 
00390 int
00391 shlib_visibility_checkweak ()
00392 {
00393   return 1;
00394 }
00395 #endif
00396 
00397 #ifdef PROTECTED_TEST
00398 #ifdef SHARED
00399 int shared_data = 100;
00400 #else
00401 extern int shared_data;
00402 #endif
00403  
00404 int *
00405 shared_data_p ()
00406 {
00407   return &shared_data;
00408 }
00409  
00410 int
00411 shared_func ()
00412 {
00413   return 100;
00414 }
00415  
00416 void *
00417 shared_func_p ()
00418 {
00419   return shared_func;
00420 }
00421 #endif