two_file_test_2.cc 2.9 KB

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