initpri2.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* initpri2.c -- test mixing init_array and ctor priorities.
  2. Copyright (C) 2011-2015 Free Software Foundation, Inc.
  3. Copied from the gcc configury, where the test was contributed by
  4. H.J. Lu <hongjiu.lu@intel.com>.
  5. This file is part of gold.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. MA 02110-1301, USA. */
  18. /* This tests that the linker correctly combines .ctor and .init_array
  19. sections when both have priorities. */
  20. #include <stdlib.h>
  21. static int count;
  22. static void
  23. init1005 (void)
  24. {
  25. if (count != 0)
  26. abort ();
  27. count = 1005;
  28. }
  29. void (*const init_array1005[]) (void)
  30. __attribute__ ((section (".init_array.01005"), aligned (sizeof (void *))))
  31. = { init1005 };
  32. static void
  33. fini1005 (void)
  34. {
  35. if (count != 1005)
  36. abort ();
  37. }
  38. void (*const fini_array1005[]) (void)
  39. __attribute__ ((section (".fini_array.01005"), aligned (sizeof (void *))))
  40. = { fini1005 };
  41. static void
  42. ctor1007 (void)
  43. {
  44. if (count != 1005)
  45. abort ();
  46. count = 1007;
  47. }
  48. void (*const ctors1007[]) (void)
  49. __attribute__ ((section (".ctors.64528"), aligned (sizeof (void *))))
  50. = { ctor1007 };
  51. static void
  52. dtor1007 (void)
  53. {
  54. if (count != 1007)
  55. abort ();
  56. count = 1005;
  57. }
  58. void (*const dtors1007[]) (void)
  59. __attribute__ ((section (".dtors.64528"), aligned (sizeof (void *))))
  60. = { dtor1007 };
  61. static void
  62. init65530 (void)
  63. {
  64. if (count != 1007)
  65. abort ();
  66. count = 65530;
  67. }
  68. void (*const init_array65530[]) (void)
  69. __attribute__ ((section (".init_array.65530"), aligned (sizeof (void *))))
  70. = { init65530 };
  71. static void
  72. fini65530 (void)
  73. {
  74. if (count != 65530)
  75. abort ();
  76. count = 1007;
  77. }
  78. void (*const fini_array65530[]) (void)
  79. __attribute__ ((section (".fini_array.65530"), aligned (sizeof (void *))))
  80. = { fini65530 };
  81. static void
  82. ctor65535 (void)
  83. {
  84. if (count != 65530)
  85. abort ();
  86. count = 65535;
  87. }
  88. void (*const ctors65535[]) (void)
  89. __attribute__ ((section (".ctors"), aligned (sizeof (void *))))
  90. = { ctor65535 };
  91. static void
  92. dtor65535 (void)
  93. {
  94. if (count != 65535)
  95. abort ();
  96. count = 65530;
  97. }
  98. void (*const dtors65535[]) (void)
  99. __attribute__ ((section (".dtors"), aligned (sizeof (void *))))
  100. = { dtor65535 };
  101. int
  102. main (void)
  103. {
  104. return 0;
  105. }