Commit | Line | Data |
---|---|---|
f0323c2f ILT |
1 | #!/bin/sh |
2 | ||
3 | # debug_msg.sh -- a test case for printing debug info for missing symbols. | |
4 | ||
60e8b3fc CC |
5 | # Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013 |
6 | # Free Software Foundation, Inc. | |
f0323c2f ILT |
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 | { | |
79e052ea | 33 | if ! grep -q "$2" "$1" |
f0323c2f | 34 | then |
79e052ea ILT |
35 | echo "Did not find expected error in $1:" |
36 | echo " $2" | |
f0323c2f ILT |
37 | echo "" |
38 | echo "Actual error output below:" | |
79e052ea ILT |
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" | |
f0323c2f ILT |
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. | |
60e8b3fc CC |
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'" | |
79e052ea | 62 | |
2db70501 CD |
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. | |
308ecdc7 ILT |
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()'" | |
9df9de2c CC |
70 | if test "$DEFAULT_TARGET" != "powerpc" |
71 | then | |
72 | check debug_msg.err ".*/debug_msg.cc:.*: error: undefined reference to 'undef_int'" | |
73 | fi | |
f0323c2f | 74 | |
a55ce7fe | 75 | # Check we detected the ODR (One Definition Rule) violation. |
79e052ea | 76 | check debug_msg.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):" |
71ff8986 | 77 | check debug_msg.err "odr_violation1.cc:6" |
ed16fd1b | 78 | check debug_msg.err "odr_violation2.cc:12" |
71ff8986 ILT |
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" | |
9691462b ILT |
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):" | |
71ff8986 | 88 | check_missing debug_msg.err "odr_violation1.cc:16" |
ed16fd1b | 89 | check_missing debug_msg.err "odr_violation2.cc:23" |
9691462b | 90 | check debug_msg.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):" |
71ff8986 | 91 | check debug_msg.err "debug_msg.cc:68" |
ed16fd1b | 92 | check debug_msg.err "odr_violation2.cc:27" |
79e052ea | 93 | |
472076e4 CC |
94 | # Check for the same error messages when using --compressed-debug-sections. |
95 | if test -r debug_msg_cdebug.err | |
96 | then | |
60e8b3fc CC |
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'" | |
472076e4 CC |
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()'" | |
9df9de2c CC |
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 | |
472076e4 CC |
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 | ||
79e052ea ILT |
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. | |
f073bbf7 CD |
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'" | |
79e052ea | 126 | check debug_msg_so.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):" |
71ff8986 | 127 | check debug_msg_so.err "odr_violation1.cc:6" |
ed16fd1b | 128 | check debug_msg_so.err "odr_violation2.cc:12" |
472076e4 CC |
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" | |
79e052ea ILT |
137 | |
138 | # These messages shouldn't need any debug info to detect: | |
f073bbf7 CD |
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'" | |
79e052ea ILT |
142 | # However, we shouldn't detect or declare any ODR violation |
143 | check_missing debug_msg_ndebug.err "(possible ODR violation)" | |
a55ce7fe | 144 | |
f0323c2f | 145 | exit 0 |