2019-01-01 18:31:27 +08:00
# Copyright (C) 1993-2019 Free Software Foundation, Inc.
1999-05-03 15:29:11 +08:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2007-07-06 00:54:46 +08:00
# the Free Software Foundation; either version 3 of the License, or
1999-05-03 15:29:11 +08:00
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
2005-05-08 22:17:41 +08:00
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
1999-05-03 15:29:11 +08:00
# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@prep.ai.mit.edu
# This file was written by Rob Savoye <rob@cygnus.com>
# and rewritten by Ian Lance Taylor <ian@cygnus.com>
if ![is_remote host] {
if {[which $NM] == 0} then {
perror "$NM does not exist"
return
}
}
send_user "Version [binutil_version $NM]"
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
2017-12-15 14:38:56 +08:00
fail "nm (assembling)"
1999-05-03 15:29:11 +08:00
} else {
2017-12-15 14:38:56 +08:00
if [is_remote host] {
set tempfile [remote_download host tmpdir/bintest.o]
} else {
set tempfile tmpdir/bintest.o
}
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
# Test nm with no arguments.
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
# This test does not work correctly on ECOFF targets, because ECOFF
# stores most symbols twice, which messes up the nm output.
2018-04-16 13:41:22 +08:00
setup_xfail "alpha*-*-osf*"
2017-12-15 14:38:56 +08:00
setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
2018-04-16 13:43:07 +08:00
setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
# This test does not work correctly on XCOFF targets, because XCOFF
# does not enter static symbols in the symbol table.
setup_xfail "*-*-aix*"
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
set got [binutils_run $NM "$NMFLAGS $tempfile"]
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
if [info exists vars] then { unset vars }
while {[regexp "(\[a-zA-Z\]) (\[a-z_\]*_symbol)(.*)" $got all type symbol rest]} {
set vars($symbol) $type
set got $rest
}
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
if {![info exists vars(text_symbol)] \
|| $vars(text_symbol) != "T" \
|| ![info exists vars(data_symbol)] \
|| $vars(data_symbol) != "D" \
|| ![info exists vars(common_symbol)] \
|| $vars(common_symbol) != "C" \
|| ![info exists vars(external_symbol)] \
|| $vars(external_symbol) != "U" \
|| ![info exists vars(static_text_symbol)] \
|| $vars(static_text_symbol) != "t" \
|| ![info exists vars(static_data_symbol)] \
|| $vars(static_data_symbol) != "d"} {
fail "nm (no arguments)"
} else {
pass "nm (no arguments)"
}
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
# Test nm -g
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
set got [binutils_run $NM "$NMFLAGS -g $tempfile"]
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
if [info exists vars] then { unset vars }
while {[regexp "(\[a-z_\]*_symbol)(.*)" $got all symbol rest]} {
set vars($symbol) 1
set got $rest
}
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
if {![info exists vars(text_symbol)] \
|| ![info exists vars(data_symbol)] \
|| ![info exists vars(common_symbol)] \
|| ![info exists vars(external_symbol)] \
|| [info exists vars(static_text_symbol)] \
|| [info exists vars(static_data_symbol)]} {
fail "nm -g"
2017-12-14 16:27:02 +08:00
} else {
2017-12-15 14:38:56 +08:00
pass "nm -g"
2017-12-14 16:27:02 +08:00
}
2011-05-19 00:35:03 +08:00
2017-12-15 14:38:56 +08:00
# Test nm -P
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
# This test does not work correctly on ECOFF targets, because ECOFF
# stores most symbols twice, which messes up the nm output.
2018-04-16 13:41:22 +08:00
setup_xfail "alpha*-*-osf*"
2017-12-15 14:38:56 +08:00
setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
2018-04-16 13:43:07 +08:00
setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
# This test does not work correctly on XCOFF targets, because XCOFF
# does not enter static symbols in the symbol table.
setup_xfail "*-*-aix*"
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
set got [binutils_run $NM "$NMFLAGS -P $tempfile"]
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
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\]*"
1999-05-03 15:29:11 +08:00
2017-12-15 14:38:56 +08:00
if [regexp $want $got] then {
pass "nm -P"
} else {
fail "nm -P"
}
1999-05-03 15:29:11 +08:00
}
2013-08-19 23:08:52 +08:00
# Test nm --size-sort
2013-08-21 06:50:11 +08:00
# The target exceptions here are intended for targets that have ELF as
# an intermediate format or otherwise require the ELF-variant syntax
2013-08-22 19:29:43 +08:00
# for proper size annotation. It would be nice if is_elf_format found
# all the ELF variants, but adding the patterns here to that proc then
# introduces a whole slew of new regressions in the GAS and LD testsuites.
if { [is_elf_format]
2016-06-22 21:42:26 +08:00
|| [istarget *-*-beos]
2013-08-22 19:29:43 +08:00
|| [istarget *-*-dragonfly*]
|| [istarget *-*-*elf]
|| [istarget *-*-freebsd*]
|| [istarget *-*-lynxos*]
2019-04-09 02:34:32 +08:00
|| [istarget *-*-moss*]
2013-08-22 19:29:43 +08:00
|| [istarget "mmix-knuth-mmixware"]
|| [istarget *-*-nto*]
|| [istarget *-*-rdos*]
|| [istarget *-*-tpf*]
|| [istarget *-*-uclinux*]
|| [istarget ia64-*-*vms*]
2017-03-30 17:57:21 +08:00
|| [istarget *-*-vxworks*]
|| [istarget wasm32-*-*] } {
2013-08-19 23:08:52 +08:00
set nm_1_src "nm-elf-1.s"
} else {
set nm_1_src "nm-1.s"
}
if {![binutils_assemble $srcdir/$subdir/$nm_1_src tmpdir/nm-1.o]} then {
2017-12-15 14:38:56 +08:00
fail "nm --size-sort (assembling)"
2013-08-19 23:08:52 +08:00
} else {
2017-12-15 14:38:56 +08:00
if [is_remote host] {
set tempfile [remote_download host tmpdir/nm-1.o]
} else {
set tempfile tmpdir/nm-1.o
}
2013-08-19 23:08:52 +08:00
2017-12-15 14:38:56 +08:00
# This test does not work correctly on ECOFF targets, because ECOFF
# stores most symbols twice, which messes up the nm output.
2018-04-16 13:41:22 +08:00
setup_xfail "alpha*-*-osf*"
2017-12-15 14:38:56 +08:00
setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*"
2018-04-16 13:43:07 +08:00
setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*"
2013-08-19 23:08:52 +08:00
2017-12-15 14:38:56 +08:00
set got [binutils_run $NM "$NMFLAGS --size-sort $tempfile"]
2013-08-19 23:08:52 +08:00
2017-12-15 14:38:56 +08:00
set want "0*4 T text_symbol3.*0*8 T text_symbol2.*0*c T text_symbol1"
if [regexp $want $got] then {
pass "nm --size-sort"
} else {
fail "nm --size-sort"
}
2013-08-19 23:08:52 +08:00
}
2016-11-11 19:49:45 +08:00
if [is_elf_format] {
2017-12-15 14:38:56 +08:00
# PR binutils/12753
# Test nm -g on a unique global symbol.
if {![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o]} then {
unsupported "nm -g on unique symbols"
} else {
if [is_remote host] {
set tmpfile [remote_download host tmpdir/unique.o]
} else {
set tmpfile tmpdir/unique.o
}
set got [binutils_run $NM "$NMFLAGS -g $tmpfile"]
if [regexp "u foo" $got] then {
pass "nm -g on unique symbols"
} else {
fail "nm -g on unique symbols"
}
if { $verbose < 1 } {
remote_file host delete "tmpdir/unique.o"
}
}
2016-11-11 19:49:45 +08:00
# PR binutils/20751
# Test nm --with-symbol-versions
if {![binutils_assemble $srcdir/$subdir/nm-ver.s tmpdir/nm-ver.o]} then {
fail "nm --with-symbol-versions (assembling)"
} else {
if [is_remote host] {
set tmpfile [remote_download host tmpdir/nm-ver.o]
} else {
set tmpfile tmpdir/nm-ver.o
}
set got [binutils_run $NM "$NMFLAGS --with-symbol-versions --format sysv $tmpfile"]
if {! [regexp "foo@VER_1" $got]} then {
fail "nm --with-symbol-versions (grep for @VER_1)"
} else {
if {! [regexp "foo@VER_1" $got]} then {
fail "nm --with-symbol-versions (grep for @@VER_2)"
} else {
pass "nm --with-symbol-versions"
}
}
if { $verbose < 1 } {
remote_file host delete "tmpdir/nm-ver.o"
}
}
}
1999-05-03 15:29:11 +08:00
# There are certainly other tests that could be run.