lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* 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 | |
| 9 | int 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. */ |
| 15 | asm (".protected global"); |
| 16 | |
| 17 | static int |
| 18 | one (void) |
| 19 | { |
| 20 | return 1; |
| 21 | } |
| 22 | |
| 23 | static int |
| 24 | minus_one (void) |
| 25 | { |
| 26 | return -1; |
| 27 | } |
| 28 | |
| 29 | static int |
| 30 | zero (void) |
| 31 | { |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | void * foo_ifunc (void) __asm__ ("foo"); |
| 36 | __asm__(".type foo, %gnu_indirect_function"); |
| 37 | |
| 38 | void * |
| 39 | foo_ifunc (void) |
| 40 | { |
| 41 | return ifunc_sel (one, minus_one, zero); |
| 42 | } |
| 43 | |
| 44 | void * foo_hidden_ifunc (void) __asm__ ("foo_hidden"); |
| 45 | __asm__(".type foo_hidden, %gnu_indirect_function"); |
| 46 | |
| 47 | void * |
| 48 | foo_hidden_ifunc (void) |
| 49 | { |
| 50 | return ifunc_sel (minus_one, one, zero); |
| 51 | } |
| 52 | |
| 53 | void * foo_protected_ifunc (void) __asm__ ("foo_protected"); |
| 54 | __asm__(".type foo_protected, %gnu_indirect_function"); |
| 55 | |
| 56 | void * |
| 57 | foo_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 | |
| 68 | extern int foo (void); |
| 69 | extern int foo_hidden (void); |
| 70 | extern int foo_protected (void); |
| 71 | extern int ret_foo; |
| 72 | extern int ret_foo_hidden; |
| 73 | extern int ret_foo_protected; |
| 74 | |
| 75 | #define FOO_P |
| 76 | typedef int (*foo_p) (void); |
| 77 | |
| 78 | foo_p |
| 79 | get_foo_p (void) |
| 80 | { |
| 81 | ret_foo = foo (); |
| 82 | return foo; |
| 83 | } |
| 84 | |
| 85 | foo_p |
| 86 | get_foo_hidden_p (void) |
| 87 | { |
| 88 | ret_foo_hidden = foo_hidden (); |
| 89 | return foo_hidden; |
| 90 | } |
| 91 | |
| 92 | foo_p |
| 93 | get_foo_protected_p (void) |
| 94 | { |
| 95 | ret_foo_protected = foo_protected (); |
| 96 | return foo_protected; |
| 97 | } |