1  /* Test STT_GNU_IFUNC symbols:
       2  
       3     1. Direct function call.
       4     2. Function pointer.
       5     3. Visibility without override.
       6   */
       7  
       8  #include <stdlib.h>
       9  
      10  int ret_foo;
      11  int ret_foo_hidden;
      12  int ret_foo_protected;
      13  
      14  extern int foo (void);
      15  extern int foo_protected (void);
      16  
      17  #ifndef FOO_P
      18  typedef int (*foo_p) (void);
      19  #endif
      20  
      21  foo_p foo_ptr = foo;
      22  
      23  /* Address-significant access to protected symbols is not supported in
      24     position-dependent mode on several architectures because GCC
      25     generates relocations that assume that the address is local to the
      26     main program.  */
      27  #ifdef __PIE__
      28  foo_p foo_procted_ptr = foo_protected;
      29  #endif
      30  
      31  extern foo_p get_foo_p (void);
      32  extern foo_p get_foo_hidden_p (void);
      33  extern foo_p get_foo_protected_p (void);
      34  
      35  int
      36  main (void)
      37  {
      38    foo_p p;
      39  
      40    if (foo_ptr != foo)
      41      abort ();
      42    if (foo () != -1)
      43      abort ();
      44    if ((*foo_ptr) () != -1)
      45      abort ();
      46  
      47  #ifdef __PIE__
      48    if (foo_procted_ptr != foo_protected)
      49      abort ();
      50  #endif
      51    if (foo_protected () != 0)
      52      abort ();
      53  #ifdef __PIE__
      54    if ((*foo_procted_ptr) () != 0)
      55      abort ();
      56  #endif
      57  
      58    p = get_foo_p ();
      59    if (p != foo)
      60      abort ();
      61    if (ret_foo != -1 || (*p) () != ret_foo)
      62      abort ();
      63  
      64    p = get_foo_hidden_p ();
      65    if (ret_foo_hidden != 1 || (*p) () != ret_foo_hidden)
      66      abort ();
      67  
      68    p = get_foo_protected_p ();
      69  #ifdef __PIE__
      70    if (p != foo_protected)
      71      abort ();
      72  #endif
      73    if (ret_foo_protected != 0 || (*p) () != ret_foo_protected)
      74      abort ();
      75  
      76    return 0;
      77  }