1/* Test STT_GNU_IFUNC symbols with dynamic function pointer only. */
2
3#include <stdlib.h>
4
5extern int foo (void);
6extern int foo_protected (void);
7
8typedef int (*foo_p) (void);
9
10foo_p
11__attribute__ ((noinline))
12get_foo (void)
13{
14 return foo;
15}
16
17
18/* Address-significant access to protected symbols is not supported in
19 position-dependent mode on several architectures because GCC
20 generates relocations that assume that the address is local to the
21 main program. */
22#ifdef __PIE__
23foo_p
24__attribute__ ((noinline))
25get_foo_protected (void)
26{
27 return foo_protected;
28}
29#endif
30
31int
32main (void)
33{
34 foo_p p;
35
36 p = get_foo ();
37 if ((*p) () != -1)
38 abort ();
39
40#ifdef __PIE__
41 p = get_foo_protected ();
42 if ((*p) () != 0)
43 abort ();
44#endif
45
46 return 0;
47}
48

source code of glibc/elf/ifuncmain5.c