(root)/
binutils-2.41/
ld/
testsuite/
ld-shared/
sh1.c
       1  /* This is part of the shared library ld test.  This file becomes part
       2     of a shared library.  */
       3  
       4  /* This variable is supplied by the main program.  */
       5  extern int mainvar;
       6  
       7  /* This variable is defined in the shared library, and overridden by
       8     the main program.  */
       9  #ifndef XCOFF_TEST
      10  int overriddenvar = -1;
      11  #endif
      12  
      13  /* This variable is defined in the shared library.  */
      14  int shlibvar1 = 3;
      15  
      16  /* This variable is defined by another object in the shared library.  */
      17  extern int shlibvar2;
      18  
      19  /* These functions return the values of the above variables as seen in
      20     the shared library.  */
      21  
      22  int
      23  shlib_mainvar ()
      24  {
      25    return mainvar;
      26  }
      27  
      28  #ifndef XCOFF_TEST
      29  int
      30  shlib_overriddenvar ()
      31  {
      32    return overriddenvar;
      33  }
      34  #endif
      35  
      36  int
      37  shlib_shlibvar1 ()
      38  {
      39    return shlibvar1;
      40  }
      41  
      42  int
      43  shlib_shlibvar2 ()
      44  {
      45    return shlibvar2;
      46  }
      47  
      48  /* This function calls a function defined by another object in the
      49     shared library.  */
      50  
      51  extern int shlib_shlibcalled ();
      52  
      53  int
      54  shlib_shlibcall ()
      55  {
      56    return shlib_shlibcalled ();
      57  }
      58  
      59  #ifndef XCOFF_TEST
      60  /* This function calls a function defined in this object in the shared
      61     library.  The main program will override the called function.  */
      62  
      63  extern int shlib_overriddencall2 ();
      64  
      65  int
      66  shlib_shlibcall2 ()
      67  {
      68    return shlib_overriddencall2 ();
      69  }
      70  #endif
      71  
      72  /* This function calls a function defined by the main program.  */
      73  
      74  extern int main_called ();
      75  
      76  int
      77  shlib_maincall ()
      78  {
      79    return main_called ();
      80  }
      81  
      82  /* This function is passed a function pointer to shlib_mainvar.  It
      83     confirms that the pointer compares equally.  */
      84  
      85  int 
      86  shlib_checkfunptr1 (p)
      87       int (*p) ();
      88  {
      89    return p == shlib_shlibvar1;
      90  }
      91  
      92  /* This function is passed a function pointer to main_called.  It
      93     confirms that the pointer compares equally.  */
      94  
      95  int
      96  shlib_checkfunptr2 (p)
      97       int (*p) ();
      98  {
      99    return p == main_called;
     100  }
     101  
     102  /* This function returns a pointer to shlib_mainvar.  */
     103  
     104  int
     105  (*shlib_getfunptr1 ()) ()
     106  {
     107    return shlib_shlibvar1;
     108  }
     109  
     110  /* This function returns a pointer to main_called.  */
     111  
     112  int
     113  (*shlib_getfunptr2 ()) ()
     114  {
     115    return main_called;
     116  }
     117  
     118  /* This function makes sure that constant data and local functions
     119     work.  */
     120  
     121  #ifndef __STDC__
     122  #define const
     123  #endif
     124  
     125  static int i = 6;
     126  static const char *str = "Hello, world\n";
     127  
     128  int
     129  shlib_check ()
     130  {
     131    const char *s1, *s2;
     132  
     133    if (i != 6)
     134      return 0;
     135  
     136    /* To isolate the test, don't rely on any external functions, such
     137       as strcmp.  */
     138    s1 = "Hello, world\n";
     139    s2 = str;
     140    while (*s1 != '\0')
     141      if (*s1++ != *s2++)
     142        return 0;
     143    if (*s2 != '\0')
     144      return 0;
     145  
     146    if (shlib_shlibvar1 () != 3)
     147      return 0;
     148  
     149    return 1;
     150  }