1 | /* Test STT_GNU_IFUNC symbols without direct function call. */ |
---|---|
2 | #include "ifunc-sel.h" |
3 | |
4 | int global = -1; |
5 | /* Can't use __attribute__((visibility("protected"))) until the GCC bug: |
6 | |
7 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248 |
8 | |
9 | is fixed. */ |
10 | asm (".protected global"); |
11 | |
12 | static int |
13 | one (void) |
14 | { |
15 | return 1; |
16 | } |
17 | |
18 | static int |
19 | minus_one (void) |
20 | { |
21 | return -1; |
22 | } |
23 | |
24 | static int |
25 | zero (void) |
26 | { |
27 | return 0; |
28 | } |
29 | |
30 | void * foo_ifunc (void) __asm__ ("foo"); |
31 | __asm__(".type foo, %gnu_indirect_function"); |
32 | |
33 | void * |
34 | inhibit_stack_protector |
35 | foo_ifunc (void) |
36 | { |
37 | return ifunc_sel (f1: one, f2: minus_one, f3: zero); |
38 | } |
39 | |
40 | void * foo_hidden_ifunc (void) __asm__ ("foo_hidden"); |
41 | __asm__(".type foo_hidden, %gnu_indirect_function"); |
42 | |
43 | void * |
44 | inhibit_stack_protector |
45 | foo_hidden_ifunc (void) |
46 | { |
47 | return ifunc_sel (f1: minus_one, f2: one, f3: zero); |
48 | } |
49 | |
50 | void * foo_protected_ifunc (void) __asm__ ("foo_protected"); |
51 | __asm__(".type foo_protected, %gnu_indirect_function"); |
52 | |
53 | void * |
54 | inhibit_stack_protector |
55 | foo_protected_ifunc (void) |
56 | { |
57 | return ifunc_sel (f1: one, f2: zero, f3: minus_one); |
58 | } |
59 | |
60 | /* Test hidden indirect function. */ |
61 | __asm__(".hidden foo_hidden"); |
62 | |
63 | /* Test protected indirect function. */ |
64 | __asm__(".protected foo_protected"); |
65 |