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