test.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifdef DEF
  5. DEF(This)
  6. DEF(is)
  7. DEF(a)
  8. DEF(test)
  9. DEF(of)
  10. DEF(string)
  11. DEF(array)
  12. DEF(for)
  13. DEF(use)
  14. DEF(with)
  15. DEF(elfhack)
  16. DEF(to)
  17. DEF(see)
  18. DEF(whether)
  19. DEF(it)
  20. DEF(breaks)
  21. DEF(anything)
  22. DEF(but)
  23. DEF(one)
  24. DEF(needs)
  25. DEF(quite)
  26. DEF(some)
  27. DEF(strings)
  28. DEF(before)
  29. DEF(the)
  30. DEF(program)
  31. DEF(can)
  32. DEF(do)
  33. DEF(its)
  34. DEF(work)
  35. DEF(efficiently)
  36. DEF(Without)
  37. DEF(enough)
  38. DEF(data)
  39. DEF(relocation)
  40. DEF(sections)
  41. DEF(are)
  42. DEF(not)
  43. DEF(sufficiently)
  44. DEF(large)
  45. DEF(and)
  46. DEF(injected)
  47. DEF(code)
  48. DEF(wouldnt)
  49. DEF(fit)
  50. DEF(Said)
  51. DEF(otherwise)
  52. DEF(we)
  53. DEF(need)
  54. DEF(more)
  55. DEF(words)
  56. DEF(than)
  57. DEF(up)
  58. DEF(here)
  59. DEF(so)
  60. DEF(that)
  61. DEF(relocations)
  62. DEF(take)
  63. DEF(significant)
  64. DEF(bytes)
  65. DEF(amounts)
  66. DEF(which)
  67. DEF(isnt)
  68. DEF(exactly)
  69. DEF(easily)
  70. DEF(achieved)
  71. DEF(like)
  72. DEF(this)
  73. DEF(Actually)
  74. DEF(I)
  75. DEF(must)
  76. DEF(cheat)
  77. DEF(by)
  78. DEF(including)
  79. DEF(these)
  80. DEF(phrases)
  81. DEF(several)
  82. DEF(times)
  83. #else
  84. #pragma GCC visibility push(default)
  85. #include <stdlib.h>
  86. #include <stdio.h>
  87. #define DEF(w) static const char str_ ## w[] = #w;
  88. #include "test.c"
  89. #undef DEF
  90. const char *strings[] = {
  91. #define DEF(w) str_ ## w,
  92. #include "test.c"
  93. #include "test.c"
  94. #include "test.c"
  95. };
  96. /* Create a hole between two zones of relative relocations */
  97. const int hole[] = {
  98. 42, 42, 42, 42
  99. };
  100. const char *strings2[] = {
  101. #include "test.c"
  102. #include "test.c"
  103. #include "test.c"
  104. #include "test.c"
  105. #include "test.c"
  106. #undef DEF
  107. };
  108. static int ret = 1;
  109. int print_status() {
  110. fprintf(stderr, "%s\n", ret ? "FAIL" : "PASS");
  111. return ret;
  112. }
  113. /* On ARM, this creates a .tbss section before .init_array, which
  114. * elfhack could then pick instead of .init_array.
  115. * Also, when .tbss is big enough, elfhack may wrongfully consider
  116. * following sections as part of the PT_TLS segment.
  117. * Finally, gold makes TLS segments end on an aligned virtual address,
  118. * even when the underlying section ends before that, and elfhack
  119. * sanity checks may yield an error. */
  120. __thread int foo;
  121. __thread long long int bar[512];
  122. void end_test() {
  123. static int count = 0;
  124. /* Only exit when both constructors have been called */
  125. if (++count == 2)
  126. ret = 0;
  127. }
  128. void test() {
  129. int i = 0, j = 0;
  130. #define DEF_(a,i,w) \
  131. if (a[i++] != str_ ## w) return;
  132. #define DEF(w) DEF_(strings,i,w)
  133. #include "test.c"
  134. #include "test.c"
  135. #include "test.c"
  136. #undef DEF
  137. #define DEF(w) DEF_(strings2,j,w)
  138. #include "test.c"
  139. #include "test.c"
  140. #include "test.c"
  141. #include "test.c"
  142. #include "test.c"
  143. #undef DEF
  144. if (i != sizeof(strings)/sizeof(strings[0]) &&
  145. j != sizeof(strings2)/sizeof(strings2[0]))
  146. fprintf(stderr, "WARNING: Test doesn't cover the whole array\n");
  147. end_test();
  148. }
  149. #pragma GCC visibility pop
  150. #endif