two_file_test_2_v1.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // two_file_test_2_v1.cc -- a two file test case for gold, file 2 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_2.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 2, and
  22. // two_file_test_1.cc is file 1. See file 1 for details.
  23. #include "two_file_test.h"
  24. // 1 Code in file 1 calls code in file 2.
  25. int
  26. t1_2()
  27. {
  28. return 0;
  29. }
  30. bool
  31. t1a()
  32. {
  33. return t1_2() == 0;
  34. }
  35. // 2 Code in file 1 refers to global data in file 2.
  36. int v2 = 1;
  37. // 3 Code in file 1 referes to common symbol in file 2. This is
  38. // initialized at runtime to 789.
  39. int v3;
  40. // 4 Code in file 1 refers to offset within global data in file 2.
  41. char v4[] = "World, hello";
  42. // 5 Code in file 1 refers to offset within common symbol in file 2.
  43. // This is initialized at runtime to a copy of v4.
  44. char v5[13];
  45. // 6 Data in file 1 refers to global data in file 2. This reuses v2.
  46. // 7 Data in file 1 refers to common symbol in file 2. This reuses v3.
  47. // 8 Data in file 1 refers to offset within global data in file 2.
  48. // This reuses v4.
  49. // 9 Data in file 1 refers to offset within common symbol in file 2.
  50. // This reuses v5.
  51. // 10 Data in file 1 refers to function in file 2.
  52. int
  53. f10()
  54. {
  55. return 0;
  56. }
  57. // 11 Pass function pointer from file 1 to file 2.
  58. int
  59. f11b(int (*pfn)())
  60. {
  61. return (*pfn)();
  62. }
  63. // 12 Compare address of function for equality in both files.
  64. bool
  65. (*f12())()
  66. {
  67. return &t12;
  68. }
  69. // 13 Compare address of inline function for equality in both files.
  70. void
  71. (*f13())()
  72. {
  73. return &f13i;
  74. }
  75. // 14 Compare string constants in file 1 and file 2.
  76. const char*
  77. f14()
  78. {
  79. return TEST_STRING_CONSTANT;
  80. }
  81. // 15 Compare wide string constants in file 1 and file 2.
  82. const wchar_t*
  83. f15()
  84. {
  85. return TEST_WIDE_STRING_CONSTANT;
  86. }
  87. // 17 File 1 checks array of string constants defined in file 2.
  88. const char* t17data[T17_COUNT] =
  89. {
  90. "0", "1", "2", "3", "4"
  91. };
  92. // 18 File 1 checks string constants referenced directly in file 2.
  93. const char*
  94. f18(int i)
  95. {
  96. switch (i)
  97. {
  98. case 0:
  99. return "0";
  100. case 1:
  101. return "1";
  102. case 2:
  103. return "2";
  104. case 3:
  105. return "3";
  106. case 4:
  107. return "4";
  108. default:
  109. return 0;
  110. }
  111. }