Fix discrepancies in nm's --line-number output by adding support for the DW_AT_specif...
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / nm.exp
1 # Copyright (C) 1993-2020 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
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, MA 02110-1301, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
19
20 # This file was written by Rob Savoye <rob@cygnus.com>
21 # and rewritten by Ian Lance Taylor <ian@cygnus.com>
22
23 if ![is_remote host] {
24 if {[which $NM] == 0} then {
25 perror "$NM does not exist"
26 return
27 }
28 }
29
30 send_user "Version [binutil_version $NM]"
31
32
33 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
34 fail "nm (assembling)"
35 } else {
36
37 if [is_remote host] {
38 set tempfile [remote_download host tmpdir/bintest.o]
39 } else {
40 set tempfile tmpdir/bintest.o
41 }
42
43 # Test nm with no arguments.
44
45 # This test does not work correctly on ECOFF targets, because ECOFF
46 # stores most symbols twice, which messes up the nm output.
47 setup_xfail "alpha*-*-osf*"
48 setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
49 setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
50
51 # This test does not work correctly on XCOFF targets, because XCOFF
52 # does not enter static symbols in the symbol table.
53 setup_xfail "*-*-aix*"
54
55 set got [binutils_run $NM "$NMFLAGS $tempfile"]
56
57 if [info exists vars] then { unset vars }
58 while {[regexp "(\[a-zA-Z\]) (\[a-z_\]*_symbol)(.*)" $got all type symbol rest]} {
59 set vars($symbol) $type
60 set got $rest
61 }
62
63 if {![info exists vars(text_symbol)] \
64 || $vars(text_symbol) != "T" \
65 || ![info exists vars(data_symbol)] \
66 || $vars(data_symbol) != "D" \
67 || ![info exists vars(common_symbol)] \
68 || $vars(common_symbol) != "C" \
69 || ![info exists vars(external_symbol)] \
70 || $vars(external_symbol) != "U" \
71 || ![info exists vars(static_text_symbol)] \
72 || $vars(static_text_symbol) != "t" \
73 || ![info exists vars(static_data_symbol)] \
74 || $vars(static_data_symbol) != "d"} {
75 fail "nm (no arguments)"
76 } else {
77 pass "nm (no arguments)"
78 }
79
80 # Test nm -g
81
82 set got [binutils_run $NM "$NMFLAGS -g $tempfile"]
83
84 if [info exists vars] then { unset vars }
85 while {[regexp "(\[a-z_\]*_symbol)(.*)" $got all symbol rest]} {
86 set vars($symbol) 1
87 set got $rest
88 }
89
90 if {![info exists vars(text_symbol)] \
91 || ![info exists vars(data_symbol)] \
92 || ![info exists vars(common_symbol)] \
93 || ![info exists vars(external_symbol)] \
94 || [info exists vars(static_text_symbol)] \
95 || [info exists vars(static_data_symbol)]} {
96 fail "nm -g"
97 } else {
98 pass "nm -g"
99 }
100
101 # Test nm -P
102
103 # This test does not work correctly on ECOFF targets, because ECOFF
104 # stores most symbols twice, which messes up the nm output.
105 setup_xfail "alpha*-*-osf*"
106 setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
107 setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
108
109 # This test does not work correctly on XCOFF targets, because XCOFF
110 # does not enter static symbols in the symbol table.
111 setup_xfail "*-*-aix*"
112
113 set got [binutils_run $NM "$NMFLAGS -P $tempfile"]
114
115 set want "common_symbol C \[0\]*4.*data_symbol D \[0-9a-fA-F\]*.*external_symbol U.*static_data_symbol d \[0-9a-fA-F\]*.*static_text_symbol t \[0-9a-fA-F\]*.*text_symbol T \[0-9a-fA-F\]*"
116
117 if [regexp $want $got] then {
118 pass "nm -P"
119 } else {
120 fail "nm -P"
121 }
122
123 # Test nm -t d
124 # Look for leading zeroes and only the digits 0..9 in the actual value.
125 set got [binutils_run $NM "$NMFLAGS -t d $tempfile"]
126 if [regexp "0+\[1-9\]\[0-9\]* T text_symbol3" $got] then {
127 pass "nm -t d"
128 } else {
129 fail "nm -t d"
130 }
131
132 # Test nm --format=posix
133 # ref: PR 24507 - no leading zeros.
134 set got [binutils_run $NM "$NMFLAGS --format=posix $tempfile"]
135 if [regexp "text_symbol3 T \[1-9a-f\]\[0-9a-f\]*" $got] then {
136 pass "nm --format posix"
137 } else {
138 fail "nm --format posix"
139 }
140 }
141
142 # Test nm --size-sort
143
144 # The target exceptions here are intended for targets that have ELF as
145 # an intermediate format or otherwise require the ELF-variant syntax
146 # for proper size annotation. It would be nice if is_elf_format found
147 # all the ELF variants, but adding the patterns here to that proc then
148 # introduces a whole slew of new regressions in the GAS and LD testsuites.
149 if { [is_elf_format]
150 || [istarget *-*-beos]
151 || [istarget *-*-dragonfly*]
152 || [istarget *-*-*elf]
153 || [istarget *-*-freebsd*]
154 || [istarget *-*-lynxos*]
155 || [istarget *-*-moss*]
156 || [istarget "mmix-knuth-mmixware"]
157 || [istarget *-*-nto*]
158 || [istarget *-*-rdos*]
159 || [istarget *-*-tpf*]
160 || [istarget *-*-uclinux*]
161 || [istarget ia64-*-*vms*]
162 || [istarget *-*-vxworks*]
163 || [istarget wasm32-*-*]
164 || [istarget bpf-*-*]} {
165 set nm_1_src "nm-elf-1.s"
166 } else {
167 set nm_1_src "nm-1.s"
168 }
169
170 if {![binutils_assemble $srcdir/$subdir/$nm_1_src tmpdir/nm-1.o]} then {
171 fail "nm --size-sort (assembling)"
172 } else {
173
174 if [is_remote host] {
175 set tempfile [remote_download host tmpdir/nm-1.o]
176 } else {
177 set tempfile tmpdir/nm-1.o
178 }
179
180 # This test does not work correctly on ECOFF targets, because ECOFF
181 # stores most symbols twice, which messes up the nm output.
182 setup_xfail "alpha*-*-osf*"
183 setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
184 setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
185
186 set got [binutils_run $NM "$NMFLAGS --size-sort $tempfile"]
187
188 set want "0*4 T text_symbol3.*0*8 T text_symbol2.*0*c T text_symbol1"
189
190 if [regexp $want $got] then {
191 pass "nm --size-sort"
192 } else {
193 fail "nm --size-sort"
194 }
195 }
196
197 if [is_elf_format] {
198 # PR binutils/12753
199 # Test nm -g on a unique global symbol.
200 if {![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o]} then {
201 unsupported "nm -g on unique symbols"
202 } else {
203 if [is_remote host] {
204 set tmpfile [remote_download host tmpdir/unique.o]
205 } else {
206 set tmpfile tmpdir/unique.o
207 }
208
209 set got [binutils_run $NM "$NMFLAGS -g $tmpfile"]
210
211 if [regexp "u foo" $got] then {
212 pass "nm -g on unique symbols"
213 } else {
214 fail "nm -g on unique symbols"
215 }
216
217 if { $verbose < 1 } {
218 remote_file host delete "tmpdir/unique.o"
219 }
220 }
221
222 # PR binutils/20751
223 # Test nm --with-symbol-versions
224
225 if {![binutils_assemble $srcdir/$subdir/nm-ver.s tmpdir/nm-ver.o]} then {
226 fail "nm --with-symbol-versions (assembling)"
227 } else {
228 if [is_remote host] {
229 set tmpfile [remote_download host tmpdir/nm-ver.o]
230 } else {
231 set tmpfile tmpdir/nm-ver.o
232 }
233
234 set got [binutils_run $NM "$NMFLAGS --with-symbol-versions --format sysv $tmpfile"]
235
236 if {! [regexp "foo@VER_1" $got]} then {
237 fail "nm --with-symbol-versions (grep for @VER_1)"
238 } else {
239 if {! [regexp "foo@VER_1" $got]} then {
240 fail "nm --with-symbol-versions (grep for @@VER_2)"
241 } else {
242 pass "nm --with-symbol-versions"
243 }
244 }
245
246 if { $verbose < 1 } {
247 remote_file host delete "tmpdir/nm-ver.o"
248 }
249 }
250
251 # PR binutils/25676
252 # Test nm --line-numbers on DWARF-4 debug info.
253 set testname "nm --line-numbers on DWARF-4 debug info"
254
255 # The RISCV target does not (currently) support .uleb128.
256 setup_xfail "riscv*-*-*"
257 # The SH targets complain that the pseudo-ops used to construct
258 # the DWARF data are misaligned.
259 setup_xfail "sh*-*-*"
260 # The pre-compiled dwarf info in dw4.s is not compatible with the
261 # ALPHA, HPPA, IA64 and MIPS targets.
262 setup_xfail "alpha*-*-*" "hppa*-*-*" "ia64*-*-*" "mips*-*-*"
263 # Assembling the source file triggers an ICE in the FT32 assembler.
264 # FIXME: Fix the ICE...
265 setup_xfail "ft32-*-*"
266 # The AVR, MSP430, NDS32, PRU and XTENSA targets do not assemble the
267 # (64-bit) source file.
268 setup_xfail "avr-*-*" "msp430-*-*" "nds32*-*-*" "pru-*-*" "xtensa-*-*"
269
270 if {![binutils_assemble $srcdir/$subdir/dw4.s tmpdir/dw4.o]} then {
271 fail "$testname (assembly)"
272 } else {
273 # The test source is only intended for 64-bit targets.
274 # FIXME: Create a 32-bit version of this test.
275 if {! [is_elf64 tmpdir/dw4.o]} {
276 unsupported "$testname (needs a 64-bit target)"
277 } else {
278 if [is_remote host] {
279 set tmpfile [remote_download host tmpdir/dw4r.o]
280 } else {
281 set tmpfile tmpdir/dw4.o
282 }
283
284 set got [binutils_run $NM "$NMFLAGS --line-numbers $tmpfile"]
285
286 if {! [regexp "g_my_externd_global.*tests/main.c:3" $got]} then {
287 fail "$testname (grep for externd global file/line)"
288 } else {
289 pass $testname
290 }
291 }
292
293 if { $verbose < 1 } {
294 remote_file host delete $tmpfile
295 }
296 }
297 }
298
299 # There are certainly other tests that could be run.
This page took 0.036372 seconds and 4 git commands to generate.