1 # Copyright
(C
) 1993-2024 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*-*-*ecoff" "alpha*-*-osf*"
49 # This test does not work correctly
on XCOFF targets
, because XCOFF
50 # does not enter static symbols in the symbol table.
51 if [is_xcoff_format
] {
55 set got
[binutils_run $NM
"$NMFLAGS $tempfile"]
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
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)"
77 pass
"nm (no arguments)"
82 set got
[binutils_run $NM
"$NMFLAGS -g $tempfile"]
84 if [info exists vars
] then { unset vars
}
85 while {[regexp
"(\[a-z_\]*_symbol)(.*)" $got all symbol rest]} {
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
)]} {
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*-*-*ecoff" "alpha*-*-osf*"
107 # This test does not work correctly
on XCOFF targets
, because XCOFF
108 # does not enter static symbols in the symbol table.
109 if [is_xcoff_format
] {
113 set got
[binutils_run $NM
"$NMFLAGS -P $tempfile"]
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\]*"
117 if [regexp $want $got
] then {
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 {
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"
138 fail
"nm --format posix"
142 # Test nm
--size
-sort
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.
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"
167 set nm_1_src
"nm-1.s"
170 if {![binutils_assemble $srcdir
/$subdir
/$nm_1_src tmpdir
/nm
-1.o
]} then {
171 fail
"nm --size-sort (assembling)"
174 if [is_remote host
] {
175 set tempfile
[remote_download host tmpdir
/nm
-1.o
]
177 set tempfile tmpdir
/nm
-1.o
180 set got
[binutils_run $NM
"$NMFLAGS --size-sort $tempfile"]
182 set want
"0*4 T text_symbol3.*0*8 T text_symbol2.*0*c T text_symbol1"
184 if [regexp $want $got
] then {
185 pass
"nm --size-sort"
187 fail
"nm --size-sort"
193 # Test nm
-g
on a unique global symbol.
194 if {![binutils_assemble $srcdir
/$subdir
/unique.s tmpdir
/unique.o
]} then {
195 unsupported
"nm -g on unique symbols"
197 if [is_remote host
] {
198 set tmpfile
[remote_download host tmpdir
/unique.o
]
200 set tmpfile tmpdir
/unique.o
203 set got
[binutils_run $NM
"$NMFLAGS -g $tmpfile"]
205 if [regexp
"u foo" $got] then {
206 pass
"nm -g on unique symbols"
208 fail
"nm -g on unique symbols"
211 if { $verbose
< 1 } {
212 remote_file host
delete "tmpdir/unique.o"
217 # Test nm
--with
-symbol
-versions
219 if {![binutils_assemble $srcdir
/$subdir
/nm
-ver.s tmpdir
/nm
-ver.o
]} then {
220 fail
"nm --with-symbol-versions (assembling)"
222 if [is_remote host
] {
223 set tmpfile
[remote_download host tmpdir
/nm
-ver.o
]
225 set tmpfile tmpdir
/nm
-ver.o
228 set got
[binutils_run $NM
"$NMFLAGS --with-symbol-versions --format sysv $tmpfile"]
230 if {! [regexp
"foo@VER_1" $got]} then {
231 fail
"nm --with-symbol-versions (grep for @VER_1)"
233 if {! [regexp
"foo@VER_1" $got]} then {
234 fail
"nm --with-symbol-versions (grep for @@VER_2)"
236 pass
"nm --with-symbol-versions"
240 if { $verbose
< 1 } {
241 remote_file host
delete "tmpdir/nm-ver.o"
246 # Test nm
--line
-numbers
on DWARF
-4 debug
info.
247 set testname
"nm --line-numbers on DWARF-4 debug info"
249 # The SH targets complain that the pseudo
-ops used to construct
250 # the DWARF data are misaligned.
251 setup_xfail
"sh*-*-*"
252 # The pre
-compiled dwarf
info in dw4.s is not compatible with the
253 # ALPHA
, HPPA
, IA64 and MIPS targets.
254 setup_xfail
"alpha*-*-*" "hppa*-*-*" "ia64*-*-*" "mips*-*-*"
255 # Assembling the source file triggers an ICE in the FT32 assembler.
256 # FIXME
: Fix the ICE...
257 setup_xfail
"ft32-*-*"
258 # The AVR
, MSP430
, NDS32
, PRU and XTENSA targets
do not assemble the
259 #
(64-bit
) source file.
260 setup_xfail
"avr-*-*" "msp430-*-*" "nds32*-*-*" "pru-*-*" "xtensa-*-*"
262 if {![binutils_assemble $srcdir
/$subdir
/dw4.s tmpdir
/dw4.o
]} then {
263 fail
"$testname (assembly)"
265 # The test source is only intended
for 64-bit targets.
266 # FIXME
: Create a
32-bit version of this test.
267 if {! [is_elf64 tmpdir
/dw4.o
]} {
268 unsupported
"$testname (needs a 64-bit target)"
270 if [is_remote host
] {
271 set tmpfile
[remote_download host tmpdir
/dw4r.o
]
273 set tmpfile tmpdir
/dw4.o
276 set got
[binutils_run $NM
"$NMFLAGS --line-numbers $tmpfile"]
278 if {! [regexp
"g_my_externd_global.*tests/main.c:3" $got]} then {
279 fail
"$testname (grep for externd global file/line)"
285 if { $verbose
< 1 } {
286 remote_file host
delete $tmpfile
291 # Test nm
--ifunc
-chars
on a indirect symbols.
293 # The following targets are known to not support ifuncs.
294 setup_xfail
"alpha*-*-*"
295 setup_xfail
"arm*-elf" "arm*-*-nto*" "arm*-*-netbsd*"
296 setup_xfail
"*-*-hpux*"
297 setup_xfail
"mips*-*-*" "tx39*-*-*"
298 setup_xfail
"msp430*-*-*"
299 setup_xfail
"kvx*-*-*"
300 setup_xfail
"visium*-*-*"
301 setup_xfail
"x86_64-*-cloudabi*"
303 set testname
"nm --ifunc-chars"
304 if {![binutils_assemble $srcdir
/$subdir
/ifunc.s tmpdir
/ifunc.o
]} then {
305 fail
"$testname (assembly)"
307 if [is_remote host
] {
308 set tmpfile
[remote_download host tmpdir
/ifunc.o
]
310 set tmpfile tmpdir
/ifunc.o
313 set got
[binutils_run $NM
"$NMFLAGS --ifunc-chars=Ff $tmpfile"]
315 if [regexp
"F global_foo" $got] then {
316 pass
"$testname (global ifunc)"
318 fail
"$testname (global ifunc)"
321 if [regexp
"f local_foo" $got] then {
322 pass
"$testname (local ifunc)"
324 fail
"$testname (local ifunc)"
327 if { $verbose
< 1 } {
328 remote_file host
delete "tmpdir/ifunc.o"
332 set testname
"nm --no-weak"
333 if {![binutils_assemble $srcdir
/$subdir
/no
-weak.s tmpdir
/no
-weak.o
]} then {
334 fail
"$testname (assembly)"
336 if [is_remote host
] {
337 set tmpfile
[remote_download host tmpdir
/no
-weak.o
]
339 set tmpfile tmpdir
/no
-weak.o
342 set got
[binutils_run $NM
"$NMFLAGS --no-weak $tmpfile"]
344 if [regexp
"weak_with_default_value" $got] then {
345 fail
"$testname (weak symbol with default value)"
347 pass
"$testname (weak symbol with default value)"
350 if [regexp
"weak_without_default_value" $got] then {
351 fail
"$testname (weak symbol without default value)"
353 pass
"$testname (weak symbol without default value)"
356 # FIXME
: We should re run this test without the
--no
-weak option
357 # and verify that the expected symbol names
*are
* shown...
359 if { $verbose
< 1 } {
360 remote_file host
delete "tmpdir/no0weak.o"
365 # There are certainly other tests that could be run.