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 __attribute__ ((visibility ("hidden"))) = -1; 10 11 static int one(void)12one (void) 13 { 14 return 1; 15 } 16 17 static int minus_one(void)18minus_one (void) 19 { 20 return -1; 21 } 22 23 static int zero(void)24zero (void) 25 { 26 return 0; 27 } 28 29 void * foo_ifunc (void) __asm__ ("foo"); 30 __asm__(".type foo, %gnu_indirect_function"); 31 32 void * foo_ifunc(void)33foo_ifunc (void) 34 { 35 return ifunc_sel (one, minus_one, zero); 36 } 37 38 void * foo_hidden_ifunc (void) __asm__ ("foo_hidden"); 39 __asm__(".type foo_hidden, %gnu_indirect_function"); 40 41 void * foo_hidden_ifunc(void)42foo_hidden_ifunc (void) 43 { 44 return ifunc_sel (minus_one, one, zero); 45 } 46 47 void * foo_protected_ifunc (void) __asm__ ("foo_protected"); 48 __asm__(".type foo_protected, %gnu_indirect_function"); 49 50 void * foo_protected_ifunc(void)51foo_protected_ifunc (void) 52 { 53 return ifunc_sel (one, zero, minus_one); 54 } 55 56 /* Test hidden indirect function. */ 57 __asm__(".hidden foo_hidden"); 58 59 /* Test protected indirect function. */ 60 __asm__(".protected foo_protected"); 61 62 extern int foo (void); 63 extern int foo_hidden (void); 64 extern int foo_protected (void); 65 extern int ret_foo; 66 extern int ret_foo_hidden; 67 extern int ret_foo_protected; 68 69 #define FOO_P 70 typedef int (*foo_p) (void); 71 72 extern foo_p get_foo_p (void); 73 extern foo_p get_foo_hidden_p (void); 74 extern foo_p get_foo_protected_p (void); 75 76 foo_p get_foo_p(void)77get_foo_p (void) 78 { 79 ret_foo = foo (); 80 return foo; 81 } 82 83 foo_p get_foo_hidden_p(void)84get_foo_hidden_p (void) 85 { 86 ret_foo_hidden = foo_hidden (); 87 return foo_hidden; 88 } 89 90 foo_p get_foo_protected_p(void)91get_foo_protected_p (void) 92 { 93 ret_foo_protected = foo_protected (); 94 return foo_protected; 95 } 96