1 # Copyright (C) 1993-2020 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
20 # This file was written by Rob Savoye <rob@cygnus.com>
21 # and rewritten by Ian Lance Taylor <ian@cygnus.com>
23 if ![is_remote host] {
24 if {[which $NM] == 0} then {
25 perror "$NM does not exist"
30 send_user "Version [binutil_version $NM]"
33 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
34 fail "nm (assembling)"
38 set tempfile [remote_download host tmpdir/bintest.o]
40 set tempfile tmpdir/bintest.o
43 # Test nm with no arguments.
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*"
51 # This test does not work correctly on XCOFF targets, because XCOFF
52 # does not enter static symbols in the symbol table.
53 if [is_xcoff_format] {
57 set got [binutils_run $NM "$NMFLAGS $tempfile"]
59 if [info exists vars] then { unset vars }
60 while {[regexp "(\[a-zA-Z\]) (\[a-z_\]*_symbol)(.*)" $got all type symbol rest]} {
61 set vars($symbol) $type
65 if {![info exists vars(text_symbol)] \
66 || $vars(text_symbol) != "T" \
67 || ![info exists vars(data_symbol)] \
68 || $vars(data_symbol) != "D" \
69 || ![info exists vars(common_symbol)] \
70 || $vars(common_symbol) != "C" \
71 || ![info exists vars(external_symbol)] \
72 || $vars(external_symbol) != "U" \
73 || ![info exists vars(static_text_symbol)] \
74 || $vars(static_text_symbol) != "t" \
75 || ![info exists vars(static_data_symbol)] \
76 || $vars(static_data_symbol) != "d"} {
77 fail "nm (no arguments)"
79 pass "nm (no arguments)"
84 set got [binutils_run $NM "$NMFLAGS -g $tempfile"]
86 if [info exists vars] then { unset vars }
87 while {[regexp "(\[a-z_\]*_symbol)(.*)" $got all symbol rest]} {
92 if {![info exists vars(text_symbol)] \
93 || ![info exists vars(data_symbol)] \
94 || ![info exists vars(common_symbol)] \
95 || ![info exists vars(external_symbol)] \
96 || [info exists vars(static_text_symbol)] \
97 || [info exists vars(static_data_symbol)]} {
105 # This test does not work correctly on ECOFF targets, because ECOFF
106 # stores most symbols twice, which messes up the nm output.
107 setup_xfail "alpha*-*-osf*"
108 setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
109 setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
111 # This test does not work correctly on XCOFF targets, because XCOFF
112 # does not enter static symbols in the symbol table.
113 if [is_xcoff_format] {
117 set got [binutils_run $NM "$NMFLAGS -P $tempfile"]
119 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\]*"
121 if [regexp $want $got] then {
128 # Look for leading zeroes and only the digits 0..9 in the actual value.
129 set got [binutils_run $NM "$NMFLAGS -t d $tempfile"]
130 if [regexp "0+\[1-9\]\[0-9\]* T text_symbol3" $got] then {
136 # Test nm --format=posix
137 # ref: PR 24507 - no leading zeros.
138 set got [binutils_run $NM "$NMFLAGS --format=posix $tempfile"]
139 if [regexp "text_symbol3 T \[1-9a-f\]\[0-9a-f\]*" $got] then {
140 pass "nm --format posix"
142 fail "nm --format posix"
146 # Test nm --size-sort
148 # The target exceptions here are intended for targets that have ELF as
149 # an intermediate format or otherwise require the ELF-variant syntax
150 # for proper size annotation. It would be nice if is_elf_format found
151 # all the ELF variants, but adding the patterns here to that proc then
152 # introduces a whole slew of new regressions in the GAS and LD testsuites.
154 || [istarget *-*-beos]
155 || [istarget *-*-dragonfly*]
156 || [istarget *-*-*elf]
157 || [istarget *-*-freebsd*]
158 || [istarget *-*-lynxos*]
159 || [istarget *-*-moss*]
160 || [istarget "mmix-knuth-mmixware"]
161 || [istarget *-*-nto*]
162 || [istarget *-*-rdos*]
163 || [istarget *-*-tpf*]
164 || [istarget *-*-uclinux*]
165 || [istarget ia64-*-*vms*]
166 || [istarget *-*-vxworks*]
167 || [istarget wasm32-*-*]
168 || [istarget bpf-*-*]} {
169 set nm_1_src "nm-elf-1.s"
171 set nm_1_src "nm-1.s"
174 if {![binutils_assemble $srcdir/$subdir/$nm_1_src tmpdir/nm-1.o]} then {
175 fail "nm --size-sort (assembling)"
178 if [is_remote host] {
179 set tempfile [remote_download host tmpdir/nm-1.o]
181 set tempfile tmpdir/nm-1.o
184 # This test does not work correctly on ECOFF targets, because ECOFF
185 # stores most symbols twice, which messes up the nm output.
186 setup_xfail "alpha*-*-osf*"
187 setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
188 setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
190 set got [binutils_run $NM "$NMFLAGS --size-sort $tempfile"]
192 set want "0*4 T text_symbol3.*0*8 T text_symbol2.*0*c T text_symbol1"
194 if [regexp $want $got] then {
195 pass "nm --size-sort"
197 fail "nm --size-sort"
203 # Test nm -g on a unique global symbol.
204 if {![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o]} then {
205 unsupported "nm -g on unique symbols"
207 if [is_remote host] {
208 set tmpfile [remote_download host tmpdir/unique.o]
210 set tmpfile tmpdir/unique.o
213 set got [binutils_run $NM "$NMFLAGS -g $tmpfile"]
215 if [regexp "u foo" $got] then {
216 pass "nm -g on unique symbols"
218 fail "nm -g on unique symbols"
221 if { $verbose < 1 } {
222 remote_file host delete "tmpdir/unique.o"
227 # Test nm --with-symbol-versions
229 if {![binutils_assemble $srcdir/$subdir/nm-ver.s tmpdir/nm-ver.o]} then {
230 fail "nm --with-symbol-versions (assembling)"
232 if [is_remote host] {
233 set tmpfile [remote_download host tmpdir/nm-ver.o]
235 set tmpfile tmpdir/nm-ver.o
238 set got [binutils_run $NM "$NMFLAGS --with-symbol-versions --format sysv $tmpfile"]
240 if {! [regexp "foo@VER_1" $got]} then {
241 fail "nm --with-symbol-versions (grep for @VER_1)"
243 if {! [regexp "foo@VER_1" $got]} then {
244 fail "nm --with-symbol-versions (grep for @@VER_2)"
246 pass "nm --with-symbol-versions"
250 if { $verbose < 1 } {
251 remote_file host delete "tmpdir/nm-ver.o"
256 # Test nm --line-numbers on DWARF-4 debug info.
257 set testname "nm --line-numbers on DWARF-4 debug info"
259 # The RISCV target does not (currently) support .uleb128.
260 setup_xfail "riscv*-*-*"
261 # The SH targets complain that the pseudo-ops used to construct
262 # the DWARF data are misaligned.
263 setup_xfail "sh*-*-*"
264 # The pre-compiled dwarf info in dw4.s is not compatible with the
265 # ALPHA, HPPA, IA64 and MIPS targets.
266 setup_xfail "alpha*-*-*" "hppa*-*-*" "ia64*-*-*" "mips*-*-*"
267 # Assembling the source file triggers an ICE in the FT32 assembler.
268 # FIXME: Fix the ICE...
269 setup_xfail "ft32-*-*"
270 # The AVR, MSP430, NDS32, PRU and XTENSA targets do not assemble the
271 # (64-bit) source file.
272 setup_xfail "avr-*-*" "msp430-*-*" "nds32*-*-*" "pru-*-*" "xtensa-*-*"
274 if {![binutils_assemble $srcdir/$subdir/dw4.s tmpdir/dw4.o]} then {
275 fail "$testname (assembly)"
277 # The test source is only intended for 64-bit targets.
278 # FIXME: Create a 32-bit version of this test.
279 if {! [is_elf64 tmpdir/dw4.o]} {
280 unsupported "$testname (needs a 64-bit target)"
282 if [is_remote host] {
283 set tmpfile [remote_download host tmpdir/dw4r.o]
285 set tmpfile tmpdir/dw4.o
288 set got [binutils_run $NM "$NMFLAGS --line-numbers $tmpfile"]
290 if {! [regexp "g_my_externd_global.*tests/main.c:3" $got]} then {
291 fail "$testname (grep for externd global file/line)"
297 if { $verbose < 1 } {
298 remote_file host delete $tmpfile
303 # There are certainly other tests that could be run.