two_file_test_1_v1.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // two_file_test_1_v1.cc -- a two file test case for gold, file 1 of 2
  2. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. // This is an alternate version of the source file two_file_test_1.cc,
  18. // used to test incremental linking. We build a binary first using this
  19. // source file, then do an incremental link with the primary version of
  20. // the file.
  21. // This tests references between files. This is file 1, and
  22. // two_file_test_2.cc is file 2. We test in several different ways:
  23. // Files 1 and 2 linked together in executable.
  24. // File 1 in executable, file 2 in shared library.
  25. // File 1 in shared library, file 2 in executable.
  26. // Files 1 and 2 linked together in shared library.
  27. // Files 1 and 2 in different shared libraries.
  28. // We test the following cases.
  29. // 1 Code in file 1 calls code in file 2.
  30. // 2 Code in file 1 refers to global data in file 2.
  31. // 3 Code in file 1 referes to common symbol in file 2.
  32. // 4 Code in file 1 refers to offset within global data in file 2.
  33. // 5 Code in file 1 refers to offset within common symbol in file 2.
  34. // 6 Data in file 1 refers to global data in file 2.
  35. // 7 Data in file 1 refers to common symbol in file 2.
  36. // 8 Data in file 1 refers to offset within global data in file 2.
  37. // 9 Data in file 1 refers to offset within common symbol in file 2.
  38. // 10 Data in file 1 refers to function in file 2.
  39. // 11 Pass function pointer from file 1 to file 2.
  40. // 12 Compare address of function for equality in both files.
  41. // 13 Compare address of inline function for equality in both files.
  42. // 14 Compare string constants in file 1 and file 2.
  43. // 15 Compare wide string constants in file 1 and file 2.
  44. // 16 Call a function directly after its address has been taken.
  45. // 17 File 1 checks array of string constants defined in file 2.
  46. // 18 File 1 checks string constants referenced in code in file 2.
  47. #include "two_file_test.h"
  48. // 1 Code in file 1 calls code in file 2.
  49. bool
  50. t1()
  51. {
  52. return t1_2() == 0; // Intentionally wrong.
  53. }
  54. // 2 Code in file 1 refers to global data in file 2.
  55. bool
  56. t2()
  57. {
  58. return v2 == 0; // Intentionally wrong.
  59. }
  60. // 3 Code in file 1 referes to common symbol in file 2.
  61. bool
  62. t3()
  63. {
  64. return v3 == 0; // Intentionally wrong.
  65. }
  66. // 4 Code in file 1 refers to offset within global data in file 2.
  67. bool
  68. t4()
  69. {
  70. return v4[5] == ',';
  71. }
  72. // 5 Code in file 1 refers to offset within common symbol in file 2.
  73. bool
  74. t5()
  75. {
  76. return v5[7] == 'w';
  77. }
  78. // 6 Data in file 1 refers to global data in file 2.
  79. int* p6 = &v2;
  80. bool
  81. t6()
  82. {
  83. return *p6 == 456;
  84. }
  85. // 7 Data in file 1 refers to common symbol in file 2.
  86. int* p7 = &v3;
  87. bool
  88. t7()
  89. {
  90. return *p7 == 789;
  91. }
  92. // 8 Data in file 1 refers to offset within global data in file 2.
  93. char* p8 = &v4[6];
  94. bool
  95. t8()
  96. {
  97. return *p8 == ' ';
  98. }
  99. // 9 Data in file 1 refers to offset within common symbol in file 2.
  100. char* p9 = &v5[8];
  101. bool
  102. t9()
  103. {
  104. return *p9 == 'o';
  105. }
  106. // 10 Data in file 1 refers to function in file 2.
  107. int (*pfn)() = &f10;
  108. bool
  109. t10()
  110. {
  111. return (*pfn)() == 135;
  112. }
  113. // 11 Pass function pointer from file 1 to file 2.
  114. int
  115. f11a()
  116. {
  117. return 246;
  118. }
  119. bool
  120. t11()
  121. {
  122. return f11b(&f11a) == 246;
  123. }
  124. // 12 Compare address of function for equality in both files.
  125. bool
  126. t12()
  127. {
  128. return &t12 == f12();
  129. }
  130. // 13 Compare address of inline function for equality in both files.
  131. bool
  132. t13()
  133. {
  134. return &f13i == f13();
  135. }
  136. // 14 Compare string constants in file 1 and file 2.
  137. bool
  138. t14()
  139. {
  140. const char* s1 = TEST_STRING_CONSTANT;
  141. const char* s2 = f14();
  142. while (*s1 != '\0')
  143. if (*s1++ != *s2++)
  144. return false;
  145. return *s2 == '\0';
  146. }
  147. // 15 Compare wide string constants in file 1 and file 2.
  148. bool
  149. t15()
  150. {
  151. const wchar_t* s1 = TEST_WIDE_STRING_CONSTANT;
  152. const wchar_t* s2 = f15();
  153. while (*s1 != '\0')
  154. if (*s1++ != *s2++)
  155. return false;
  156. return *s2 == '\0';
  157. }
  158. // 16 Call a function directly after its address has been taken.
  159. bool
  160. t16()
  161. {
  162. return f10() == 135;
  163. }
  164. // 17 File 1 checks array of string constants defined in file 2.
  165. bool
  166. t17()
  167. {
  168. char c = 'a';
  169. for (int i = 0; i < T17_COUNT; ++i)
  170. {
  171. if (t17data[i][0] != c || t17data[i][1] != '\0')
  172. return false;
  173. ++c;
  174. }
  175. return true;
  176. }
  177. // 18 File 1 checks string constants referenced in code in file 2.
  178. bool
  179. t18()
  180. {
  181. // Stubbed out; full implementation in two_file_test_1.cc.
  182. return true;
  183. }