blob: 617a596d5e8c92c28a5e3fcc82a99eebf5bd4d58 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Test local STT_GNU_IFUNC symbols:
2
3 1. Direct function call.
4 2. Function pointer.
5 */
6
7#include <stdlib.h>
8#include "ifunc-sel.h"
9
10extern int foo (void);
11
12static int
13one (void)
14{
15 return -30;
16}
17
18static void * foo_ifunc (void) __asm__ ("foo");
19__asm__(".type foo, %gnu_indirect_function");
20
21static void *
22__attribute__ ((used))
23foo_ifunc (void)
24{
25 return ifunc_one (one);
26}
27
28typedef int (*foo_p) (void);
29
30foo_p foo_ptr = foo;
31
32foo_p
33__attribute__ ((noinline))
34get_foo_p (void)
35{
36 return foo_ptr;
37}
38
39foo_p
40__attribute__ ((noinline))
41get_foo (void)
42{
43 return foo;
44}
45
46int
47main (void)
48{
49 foo_p p;
50
51 p = get_foo ();
52 if (p != foo)
53 abort ();
54 if ((*p) () != -30)
55 abort ();
56
57 p = get_foo_p ();
58 if (p != foo)
59 abort ();
60 if ((*p) () != -30)
61 abort ();
62
63 if (foo_ptr != foo)
64 abort ();
65 if ((*foo_ptr) () != -30)
66 abort ();
67 if (foo () != -30)
68 abort ();
69
70 return 0;
71}