dwp_test_2.cc 2.8 KB

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