Back to index

cell-binutils  2.17cvs20070401
main.c
Go to the documentation of this file.
00001 #ifdef PROTECTED_CHECK
00002 #include <features.h>
00003 #include <stdio.h>
00004 
00005 int
00006 main (void)
00007 {
00008 #if defined (__GLIBC__) && (__GLIBC__ > 2 \
00009                          || (__GLIBC__ == 2 \
00010                             &&  __GLIBC_MINOR__ >= 2))
00011   puts ("yes");
00012 #else
00013   puts ("no");
00014 #endif
00015   return 0;
00016 }
00017 #else
00018 /* This is the main program for the shared library test.  */
00019 
00020 #include <stdio.h>
00021 
00022 int mainvar = 1;
00023 int overriddenvar = 2;
00024 extern int shlibvar1;
00025 
00026 extern int shlib_mainvar ();
00027 extern int shlib_overriddenvar ();
00028 extern int shlib_shlibvar1 ();
00029 extern int shlib_shlibvar2 ();
00030 extern int shlib_shlibcall ();
00031 extern int shlib_maincall ();
00032 extern int shlib_checkfunptr1 ();
00033 extern int shlib_checkfunptr2 ();
00034 extern int (*shlib_getfunptr1 ()) ();
00035 extern int (*shlib_getfunptr2 ()) ();
00036 extern int shlib_check ();
00037 extern int shlib_shlibcall2 ();
00038 extern int visibility_check ();
00039 extern int visibility_checkfunptr ();
00040 extern void *visibility_funptr ();
00041 extern int visibility_checkvar ();
00042 extern int visibility_checkvarptr ();
00043 extern int visibility_varval ();
00044 extern void *visibility_varptr ();
00045 extern int shlib_visibility_checkcom ();
00046 extern int shlib_visibility_checkweak ();
00047 
00048 int shlib_visibility_com = 1;
00049 
00050 int shlib_visibility_var_weak = 1;
00051 
00052 int
00053 shlib_visibility_func_weak ()
00054 {
00055   return 1;
00056 }
00057 
00058 #ifdef HIDDEN_WEAK_TEST
00059 #define WEAK_TEST
00060 #endif
00061 
00062 #ifdef PROTECTED_WEAK_TEST
00063 #define WEAK_TEST
00064 #endif
00065 
00066 #ifdef PROTECTED_UNDEF_TEST
00067 #define PROTECTED_TEST
00068 #endif
00069 
00070 #ifndef WEAK_TEST
00071 extern int visibility ();
00072 extern int visibility_var;
00073 #endif
00074 
00075 #if !defined (HIDDEN_TEST) && defined (PROTECTED_TEST)
00076 int
00077 visibility (void)
00078 {
00079   return 1;
00080 }
00081 
00082 static int
00083 main_visibility_check (void)
00084 {
00085   return ((int (*) (void)) visibility_funptr ()) != visibility;
00086 }
00087 
00088 int visibility_var = 1;
00089 
00090 static int
00091 main_visibility_checkvar (void)
00092 {
00093   return visibility_varval () != visibility_var
00094         && visibility_varptr () != &visibility_var;
00095 }
00096 
00097 #ifndef PROTECTED_UNDEF_TEST
00098 int shared_data = 1;
00099 asm (".protected shared_data");
00100 
00101 int
00102 shared_func (void)
00103 {
00104   return 1;
00105 }
00106 
00107 asm (".protected shared_func");
00108 
00109 extern int * shared_data_p ();
00110 typedef int (*func) ();
00111 extern func shared_func_p ();
00112 #endif
00113 #else
00114 static int
00115 main_visibility_check (void)
00116 {
00117 #ifdef WEAK_TEST
00118   return visibility_funptr () == NULL;
00119 #else
00120   return ((int (*) (void)) visibility_funptr ()) == visibility;
00121 #endif
00122 }
00123 
00124 static int
00125 main_visibility_checkvar (void)
00126 {
00127 #ifdef WEAK_TEST
00128   return visibility_varval () == 0
00129         && visibility_varptr () == NULL;
00130 #else
00131   return visibility_varval () == visibility_var
00132         && visibility_varptr () == &visibility_var;
00133 #endif
00134 }
00135 #endif
00136 
00137 /* This function is called by the shared library.  */
00138 
00139 int
00140 main_called (void)
00141 {
00142   return 6;
00143 }
00144 
00145 /* This function overrides a function in the shared library.  */
00146 
00147 int
00148 shlib_overriddencall2 (void)
00149 {
00150   return 8;
00151 }
00152 
00153 #ifdef HIDDEN_NORMAL_TEST
00154 int visibility_com;
00155 asm (".hidden visibility_com");
00156 
00157 int
00158 main_visibility_checkcom (void)
00159 {
00160   return visibility_com == 0;
00161 }
00162 
00163 int
00164 main_visibility_checkweak (void)
00165 {
00166   return 1;
00167 }
00168 #elif defined (HIDDEN_WEAK_TEST)
00169 int
00170 main_visibility_checkcom (void)
00171 {
00172   return 1;
00173 }
00174 
00175 #pragma weak visibility_undef_var_weak
00176 extern int visibility_undef_var_weak;
00177 asm (".hidden visibility_undef_var_weak");
00178 
00179 #pragma weak visibility_undef_func_weak
00180 extern int visibility_undef_func_weak ();
00181 asm (".hidden visibility_undef_func_weak");
00182 
00183 #pragma weak visibility_var_weak
00184 extern int visibility_var_weak;
00185 asm (".hidden visibility_var_weak");
00186 
00187 #pragma weak visibility_func_weak
00188 extern int visibility_func_weak ();
00189 asm (".hidden visibility_func_weak");
00190 
00191 int
00192 main_visibility_checkweak ()
00193 {
00194   return &visibility_undef_var_weak == NULL
00195         && &visibility_undef_func_weak == NULL
00196         && &visibility_func_weak == NULL
00197         && &visibility_var_weak == NULL;
00198 }
00199 #elif defined (HIDDEN_UNDEF_TEST)
00200 extern int visibility_def;
00201 asm (".hidden visibility_def");
00202 extern int visibility_func ();
00203 asm (".hidden visibility_func");
00204 
00205 int
00206 main_visibility_checkcom (void)
00207 {
00208   return & visibility_def != NULL && visibility_def == 2;
00209 }
00210 
00211 int
00212 main_visibility_checkweak (void)
00213 {
00214   return & visibility_func != NULL && visibility_func () == 2;
00215 }
00216 #else
00217 int
00218 main_visibility_checkcom (void)
00219 {
00220   return 1;
00221 }
00222 
00223 int
00224 main_visibility_checkweak (void)
00225 {
00226   return 1;
00227 }
00228 #endif
00229 
00230 int
00231 main (void)
00232 {
00233   int (*p) ();
00234   int ret = 0;
00235 
00236   printf ("mainvar == %d\n", mainvar);
00237   printf ("overriddenvar == %d\n", overriddenvar);
00238   printf ("shlibvar1 == %d\n", shlibvar1);
00239 #ifndef XCOFF_TEST
00240   printf ("shlib_mainvar () == %d\n", shlib_mainvar ());
00241   printf ("shlib_overriddenvar () == %d\n", shlib_overriddenvar ());
00242 #endif
00243   printf ("shlib_shlibvar1 () == %d\n", shlib_shlibvar1 ());
00244   printf ("shlib_shlibvar2 () == %d\n", shlib_shlibvar2 ());
00245   printf ("shlib_shlibcall () == %d\n", shlib_shlibcall ());
00246 #ifndef XCOFF_TEST
00247   printf ("shlib_shlibcall2 () == %d\n", shlib_shlibcall2 ());
00248   printf ("shlib_maincall () == %d\n", shlib_maincall ());
00249 #endif
00250   printf ("main_called () == %d\n", main_called ());
00251   printf ("shlib_checkfunptr1 (shlib_shlibvar1) == %d\n",
00252          shlib_checkfunptr1 (shlib_shlibvar1));
00253 #ifndef XCOFF_TEST
00254   printf ("shlib_checkfunptr2 (main_called) == %d\n",
00255          shlib_checkfunptr2 (main_called));
00256 #endif
00257   p = shlib_getfunptr1 ();
00258   printf ("shlib_getfunptr1 () ");
00259   if (p == shlib_shlibvar1)
00260     printf ("==");
00261   else
00262     printf ("!=");
00263   printf (" shlib_shlibvar1\n");
00264 #ifndef XCOFF_TEST
00265   p = shlib_getfunptr2 ();
00266   printf ("shlib_getfunptr2 () ");
00267   if (p == main_called)
00268     printf ("==");
00269   else
00270     printf ("!=");
00271   printf (" main_called\n");
00272 #endif
00273   printf ("shlib_check () == %d\n", shlib_check ());
00274   printf ("visibility_check () == %d\n", visibility_check ());
00275   printf ("visibility_checkfunptr () == %d\n",
00276          visibility_checkfunptr ());
00277   printf ("main_visibility_check () == %d\n", main_visibility_check ());
00278   printf ("visibility_checkvar () == %d\n", visibility_checkvar ());
00279   printf ("visibility_checkvarptr () == %d\n",
00280          visibility_checkvarptr ());
00281   printf ("main_visibility_checkvar () == %d\n",
00282          main_visibility_checkvar ());
00283   printf ("main_visibility_checkcom () == %d\n",
00284          main_visibility_checkcom ());
00285   printf ("shlib_visibility_checkcom () == %d\n",
00286          shlib_visibility_checkcom ());
00287   printf ("main_visibility_checkweak () == %d\n",
00288          main_visibility_checkweak ());
00289   printf ("shlib_visibility_checkweak () == %d\n",
00290          shlib_visibility_checkweak ());
00291 
00292 #if !defined (PROTECTED_UNDEF_TEST) && defined (PROTECTED_TEST)
00293   if (&shared_data != shared_data_p ())
00294     ret = 1;
00295   p = shared_func_p ();
00296   if (shared_func != p)
00297     ret = 1;
00298   if (shared_data != *shared_data_p ())
00299     ret = 1;
00300   if (shared_func () != (*p) () )
00301     ret = 1;
00302 #endif
00303 
00304   return ret;
00305 }
00306 #endif