ifuncmain1vis.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Test STT_GNU_IFUNC symbols:
  2. 1. Direct function call.
  3. 2. Function pointer.
  4. 3. Visibility with override.
  5. */
  6. #include <stdlib.h>
  7. int __attribute__ ((noinline)) foo_hidden (void);
  8. int ret_foo;
  9. int ret_foo_hidden;
  10. int ret_foo_protected;
  11. extern int foo (void);
  12. extern int foo_protected (void);
  13. #ifndef FOO_P
  14. typedef int (*foo_p) (void);
  15. #endif
  16. foo_p foo_ptr = foo;
  17. foo_p foo_procted_ptr = foo_protected;
  18. extern foo_p get_foo_p (void);
  19. extern foo_p get_foo_hidden_p (void);
  20. extern foo_p get_foo_protected_p (void);
  21. int
  22. __attribute__ ((noinline))
  23. foo (void)
  24. {
  25. return -30;
  26. }
  27. int
  28. __attribute__ ((noinline))
  29. foo_hidden (void)
  30. {
  31. return -20;
  32. }
  33. int
  34. __attribute__ ((noinline))
  35. foo_protected (void)
  36. {
  37. return -40;
  38. }
  39. int
  40. main (void)
  41. {
  42. foo_p p;
  43. if (foo_ptr != foo)
  44. abort ();
  45. if ((*foo_ptr) () != -30)
  46. abort ();
  47. if (foo_procted_ptr != foo_protected)
  48. abort ();
  49. if ((*foo_procted_ptr) () != -40)
  50. abort ();
  51. p = get_foo_p ();
  52. if (p != foo)
  53. abort ();
  54. if (foo () != -30)
  55. abort ();
  56. if (ret_foo != -30 || (*p) () != ret_foo)
  57. abort ();
  58. p = get_foo_hidden_p ();
  59. if (foo_hidden () != -20)
  60. abort ();
  61. if (ret_foo_hidden != 1 || (*p) () != ret_foo_hidden)
  62. abort ();
  63. p = get_foo_protected_p ();
  64. if (p == foo_protected)
  65. abort ();
  66. if (foo_protected () != -40)
  67. abort ();
  68. if (ret_foo_protected != 0 || (*p) () != ret_foo_protected)
  69. abort ();
  70. return 0;
  71. }