blob: 0b6138056daf7c7dfed2f455cc0845197100a995 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Test STT_GNU_IFUNC symbols:
2
3 1. Direct function call.
4 2. Function pointer.
5 3. Visibility.
6 */
7#include "ifunc-sel.h"
8
9int global = -1;
10/* Can't use __attribute__((visibility("protected"))) until the GCC bug:
11
12 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248
13
14 is fixed. */
15asm (".protected global");
16
17static int
18one (void)
19{
20 return 1;
21}
22
23static int
24minus_one (void)
25{
26 return -1;
27}
28
29static int
30zero (void)
31{
32 return 0;
33}
34
35void * foo_ifunc (void) __asm__ ("foo");
36__asm__(".type foo, %gnu_indirect_function");
37
38void *
39foo_ifunc (void)
40{
41 return ifunc_sel (one, minus_one, zero);
42}
43
44void * foo_hidden_ifunc (void) __asm__ ("foo_hidden");
45__asm__(".type foo_hidden, %gnu_indirect_function");
46
47void *
48foo_hidden_ifunc (void)
49{
50 return ifunc_sel (minus_one, one, zero);
51}
52
53void * foo_protected_ifunc (void) __asm__ ("foo_protected");
54__asm__(".type foo_protected, %gnu_indirect_function");
55
56void *
57foo_protected_ifunc (void)
58{
59 return ifunc_sel (one, zero, minus_one);
60}
61
62/* Test hidden indirect function. */
63__asm__(".hidden foo_hidden");
64
65/* Test protected indirect function. */
66__asm__(".protected foo_protected");
67
68extern int foo (void);
69extern int foo_hidden (void);
70extern int foo_protected (void);
71extern int ret_foo;
72extern int ret_foo_hidden;
73extern int ret_foo_protected;
74
75#define FOO_P
76typedef int (*foo_p) (void);
77
78foo_p
79get_foo_p (void)
80{
81 ret_foo = foo ();
82 return foo;
83}
84
85foo_p
86get_foo_hidden_p (void)
87{
88 ret_foo_hidden = foo_hidden ();
89 return foo_hidden;
90}
91
92foo_p
93get_foo_protected_p (void)
94{
95 ret_foo_protected = foo_protected ();
96 return foo_protected;
97}