debug_msg.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/sh
  2. # debug_msg.sh -- a test case for printing debug info for missing symbols.
  3. # Copyright (C) 2006-2015 Free Software Foundation, Inc.
  4. # Written by Ian Lance Taylor <iant@google.com>.
  5. # This file is part of gold.
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. # This file goes with debug_msg.cc, a C++ source file constructed to
  19. # have undefined references. We compile that file with debug
  20. # information and then try to link it, and make sure the proper errors
  21. # are displayed. The errors will be found in debug_msg.err.
  22. check()
  23. {
  24. if ! grep -q "$2" "$1"
  25. then
  26. echo "Did not find expected error in $1:"
  27. echo " $2"
  28. echo ""
  29. echo "Actual error output below:"
  30. cat "$1"
  31. exit 1
  32. fi
  33. }
  34. check_missing()
  35. {
  36. if grep -q "$2" "$1"
  37. then
  38. echo "Found unexpected error in $1:"
  39. echo " $2"
  40. echo ""
  41. echo "Actual error output below:"
  42. cat "$1"
  43. exit 1
  44. fi
  45. }
  46. # We don't know how the compiler might order these variables, so we
  47. # can't test for the actual offset from .data, hence the regexp.
  48. check debug_msg.err "debug_msg.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn1()'"
  49. check debug_msg.err "debug_msg.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn2()'"
  50. check debug_msg.err "debug_msg.o:debug_msg.cc:badref1: error: undefined reference to 'undef_int'"
  51. # These tests check only for the source file's file name (not the complete
  52. # path) because use of -fdebug-prefix-map may change the path to the source
  53. # file recorded in the objects.
  54. check debug_msg.err ".*/debug_msg.cc:50: error: undefined reference to 'undef_fn1()'"
  55. check debug_msg.err ".*/debug_msg.cc:55: error: undefined reference to 'undef_fn2()'"
  56. check debug_msg.err ".*/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
  57. check debug_msg.err ".*/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
  58. if test "$DEFAULT_TARGET" != "powerpc"
  59. then
  60. check debug_msg.err ".*/debug_msg.cc:.*: error: undefined reference to 'undef_int'"
  61. fi
  62. # Check we detected the ODR (One Definition Rule) violation.
  63. check debug_msg.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
  64. check debug_msg.err "odr_violation1.cc:6"
  65. check debug_msg.err "odr_violation2.cc:1[25]"
  66. # Check we don't have ODR false positives:
  67. check_missing debug_msg.err "OdrDerived::~OdrDerived()"
  68. check_missing debug_msg.err "__adjust_heap"
  69. # We block ODR detection for combinations of C weak and strong
  70. # symbols, to allow people to use the linker to override things. We
  71. # still flag it for C++ symbols since those are more likely to be
  72. # unintentional.
  73. check_missing debug_msg.err ": symbol 'OverriddenCFunction' defined in multiple places (possible ODR violation):"
  74. check_missing debug_msg.err "odr_violation1.cc:16"
  75. check_missing debug_msg.err "odr_violation2.cc:23"
  76. check debug_msg.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
  77. check debug_msg.err "debug_msg.cc:68"
  78. check debug_msg.err "odr_violation2.cc:2[78]"
  79. # Check for the same error messages when using --compressed-debug-sections.
  80. if test -r debug_msg_cdebug.err
  81. then
  82. check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn1()'"
  83. check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn2()'"
  84. check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:badref1: error: undefined reference to 'undef_int'"
  85. check debug_msg_cdebug.err ".*/debug_msg.cc:50: error: undefined reference to 'undef_fn1()'"
  86. check debug_msg_cdebug.err ".*/debug_msg.cc:55: error: undefined reference to 'undef_fn2()'"
  87. check debug_msg_cdebug.err ".*/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
  88. check debug_msg_cdebug.err ".*/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
  89. if test "$DEFAULT_TARGET" != "powerpc"
  90. then
  91. check debug_msg_cdebug.err ".*/debug_msg.cc:.*: error: undefined reference to 'undef_int'"
  92. fi
  93. check debug_msg_cdebug.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
  94. check debug_msg_cdebug.err "odr_violation1.cc:6"
  95. check debug_msg_cdebug.err "odr_violation2.cc:1[25]"
  96. check_missing debug_msg_cdebug.err "OdrDerived::~OdrDerived()"
  97. check_missing debug_msg_cdebug.err "__adjust_heap"
  98. check_missing debug_msg_cdebug.err ": symbol 'OverriddenCFunction' defined in multiple places (possible ODR violation):"
  99. check_missing debug_msg_cdebug.err "odr_violation1.cc:16"
  100. check_missing debug_msg_cdebug.err "odr_violation2.cc:23"
  101. check debug_msg_cdebug.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
  102. check debug_msg_cdebug.err "debug_msg.cc:68"
  103. check debug_msg_cdebug.err "odr_violation2.cc:2[78]"
  104. fi
  105. # When linking together .so's, we don't catch the line numbers, but we
  106. # still find all the undefined variables, and the ODR violation.
  107. check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_fn1()'"
  108. check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_fn2()'"
  109. check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_int'"
  110. check debug_msg_so.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
  111. check debug_msg_so.err "odr_violation1.cc:6"
  112. check debug_msg_so.err "odr_violation2.cc:1[25]"
  113. check_missing debug_msg_so.err "OdrDerived::~OdrDerived()"
  114. check_missing debug_msg_so.err "__adjust_heap"
  115. check_missing debug_msg_so.err ": symbol 'OverriddenCFunction' defined in multiple places (possible ODR violation):"
  116. check_missing debug_msg_so.err "odr_violation1.cc:16"
  117. check_missing debug_msg_so.err "odr_violation2.cc:23"
  118. check debug_msg_so.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
  119. check debug_msg_so.err "debug_msg.cc:68"
  120. check debug_msg_so.err "odr_violation2.cc:2[78]"
  121. # These messages shouldn't need any debug info to detect:
  122. check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_fn1()'"
  123. check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_fn2()'"
  124. check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_int'"
  125. # However, we shouldn't detect or declare any ODR violation
  126. check_missing debug_msg_ndebug.err "(possible ODR violation)"
  127. exit 0