ifuncmain6pie.c 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Test STT_GNU_IFUNC symbols in PIE:
  2. 1. Direct function call.
  3. 2. Function pointer.
  4. 3. Reference from a shared library.
  5. */
  6. #include <stdlib.h>
  7. #include "ifunc-sel.h"
  8. typedef int (*foo_p) (void);
  9. extern foo_p foo_ptr;
  10. static int
  11. one (void)
  12. {
  13. return -30;
  14. }
  15. void * foo_ifunc (void) __asm__ ("foo");
  16. __asm__(".type foo, %gnu_indirect_function");
  17. void *
  18. foo_ifunc (void)
  19. {
  20. return ifunc_one (one);
  21. }
  22. extern int foo (void);
  23. extern foo_p get_foo (void);
  24. extern foo_p get_foo_p (void);
  25. foo_p my_foo_ptr = foo;
  26. int
  27. main (void)
  28. {
  29. foo_p p;
  30. p = get_foo ();
  31. if (p != foo)
  32. abort ();
  33. if ((*p) () != -30)
  34. abort ();
  35. p = get_foo_p ();
  36. if (p != foo)
  37. abort ();
  38. if ((*p) () != -30)
  39. abort ();
  40. if (foo_ptr != foo)
  41. abort ();
  42. if (my_foo_ptr != foo)
  43. abort ();
  44. if ((*foo_ptr) () != -30)
  45. abort ();
  46. if ((*my_foo_ptr) () != -30)
  47. abort ();
  48. if (foo () != -30)
  49. abort ();
  50. return 0;
  51. }