Back to index

cell-binutils  2.17cvs20070401
sh1.c
Go to the documentation of this file.
00001 /* This is part of the shared library ld test.  This file becomes part
00002    of a shared library.  */
00003 
00004 /* This variable is supplied by the main program.  */
00005 #ifndef XCOFF_TEST
00006 extern int mainvar;
00007 #endif
00008 
00009 /* This variable is defined in the shared library, and overridden by
00010    the main program.  */
00011 #ifndef XCOFF_TEST
00012 int overriddenvar = -1;
00013 #endif
00014 
00015 /* This variable is defined in the shared library.  */
00016 int shlibvar1 = 3;
00017 
00018 /* This variable is defined by another object in the shared library.  */
00019 extern int shlibvar2;
00020 
00021 /* These functions return the values of the above variables as seen in
00022    the shared library.  */
00023 
00024 #ifndef XCOFF_TEST
00025 int
00026 shlib_mainvar ()
00027 {
00028   return mainvar;
00029 }
00030 #endif
00031 
00032 #ifndef XCOFF_TEST
00033 int
00034 shlib_overriddenvar ()
00035 {
00036   return overriddenvar;
00037 }
00038 #endif
00039 
00040 int
00041 shlib_shlibvar1 ()
00042 {
00043   return shlibvar1;
00044 }
00045 
00046 int
00047 shlib_shlibvar2 ()
00048 {
00049   return shlibvar2;
00050 }
00051 
00052 /* This function calls a function defined by another object in the
00053    shared library.  */
00054 
00055 extern int shlib_shlibcalled ();
00056 
00057 int
00058 shlib_shlibcall ()
00059 {
00060   return shlib_shlibcalled ();
00061 }
00062 
00063 #ifndef XCOFF_TEST
00064 /* This function calls a function defined in this object in the shared
00065    library.  The main program will override the called function.  */
00066 
00067 extern int shlib_overriddencall2 ();
00068 
00069 int
00070 shlib_shlibcall2 ()
00071 {
00072   return shlib_overriddencall2 ();
00073 }
00074 
00075 int
00076 shlib_overriddencall2 ()
00077 {
00078   return 7;
00079 }
00080 #endif
00081 
00082 /* This function calls a function defined by the main program.  */
00083 
00084 #ifndef XCOFF_TEST
00085 extern int main_called ();
00086 
00087 int
00088 shlib_maincall ()
00089 {
00090   return main_called ();
00091 }
00092 #endif
00093 
00094 /* This function is passed a function pointer to shlib_mainvar.  It
00095    confirms that the pointer compares equally.  */
00096 
00097 int 
00098 shlib_checkfunptr1 (p)
00099      int (*p) ();
00100 {
00101   return p == shlib_shlibvar1;
00102 }
00103 
00104 /* This function is passed a function pointer to main_called.  It
00105    confirms that the pointer compares equally.  */
00106 
00107 #ifndef XCOFF_TEST
00108 int
00109 shlib_checkfunptr2 (p)
00110      int (*p) ();
00111 {
00112   return p == main_called;
00113 }
00114 #endif
00115 
00116 /* This function returns a pointer to shlib_mainvar.  */
00117 
00118 int
00119 (*shlib_getfunptr1 ()) ()
00120 {
00121   return shlib_shlibvar1;
00122 }
00123 
00124 /* This function returns a pointer to main_called.  */
00125 
00126 #ifndef XCOFF_TEST
00127 int
00128 (*shlib_getfunptr2 ()) ()
00129 {
00130   return main_called;
00131 }
00132 #endif
00133 
00134 /* This function makes sure that constant data and local functions
00135    work.  */
00136 
00137 #ifndef __STDC__
00138 #define const
00139 #endif
00140 
00141 static int i = 6;
00142 static const char *str = "Hello, world\n";
00143 
00144 int
00145 shlib_check ()
00146 {
00147   const char *s1, *s2;
00148 
00149   if (i != 6)
00150     return 0;
00151 
00152   /* To isolate the test, don't rely on any external functions, such
00153      as strcmp.  */
00154   s1 = "Hello, world\n";
00155   s2 = str;
00156   while (*s1 != '\0')
00157     if (*s1++ != *s2++)
00158       return 0;
00159   if (*s2 != '\0')
00160     return 0;
00161 
00162   if (shlib_shlibvar1 () != 3)
00163     return 0;
00164 
00165   return 1;
00166 }