1# Copyright (C) 1993-2017 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 23if ![is_remote host] { 24 if {[which $NM] == 0} then { 25 perror "$NM does not exist" 26 return 27 } 28} 29 30send_user "Version [binutil_version $NM]" 31 32 33if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then { 34 return 35} 36 37if [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. 47setup_xfail "alpha*-*-osf*" "alpha*-*-netware*" 48setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*" 49setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*" "mips*-sony-bsd*" 50 51# This test does not work correctly on XCOFF targets, because XCOFF 52# does not enter static symbols in the symbol table. 53setup_xfail "*-*-aix*" 54 55set got [binutils_run $NM "$NMFLAGS $tempfile"] 56 57if [info exists vars] then { unset vars } 58while {[regexp "(\[a-zA-Z\]) (\[a-z_\]*_symbol)(.*)" $got all type symbol rest]} { 59 set vars($symbol) $type 60 set got $rest 61} 62 63if {![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 82set got [binutils_run $NM "$NMFLAGS -g $tempfile"] 83 84if [info exists vars] then { unset vars } 85while {[regexp "(\[a-z_\]*_symbol)(.*)" $got all symbol rest]} { 86 set vars($symbol) 1 87 set got $rest 88} 89 90if {![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 101if [is_elf_format] { 102 # PR binutils/12753 103 # Test nm -g on a unique global symbol. 104 105 # Only some targets support unique symbols. 106 if {([istarget "i?86-*-*"] 107 || [istarget "x86_64-*-*"] 108 || [istarget "arm-*-*"] 109 || [istarget "powerpc*-*-*"] 110 || [istarget "sparc*-*-*"])} then { 111 112 if {![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o]} then { 113 fail "nm -g on unique symbols (assembling)" 114 } else { 115 if [is_remote host] { 116 set tmpfile [remote_download host tmpdir/unique.o] 117 } else { 118 set tmpfile tmpdir/unique.o 119 } 120 121 set got [binutils_run $NM "$NMFLAGS -g $tmpfile"] 122 123 if [regexp "u foo" $got] then { 124 pass "nm -g on unique symbols" 125 } else { 126 fail "nm -g on unique symbols" 127 } 128 129 if { $verbose < 1 } { 130 remote_file host delete "tmpdir/unique.o" 131 } 132 } 133 } 134} 135 136# Test nm -P 137 138# This test does not work correctly on ECOFF targets, because ECOFF 139# stores most symbols twice, which messes up the nm output. 140setup_xfail "alpha*-*-osf*" "alpha*-*-netware*" 141setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*" 142setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*" "mips*-sony-bsd*" 143 144# This test does not work correctly on XCOFF targets, because XCOFF 145# does not enter static symbols in the symbol table. 146setup_xfail "*-*-aix*" 147 148set got [binutils_run $NM "$NMFLAGS -P $tempfile"] 149 150set 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\]*" 151 152if [regexp $want $got] then { 153 pass "nm -P" 154} else { 155 fail "nm -P" 156} 157 158# Test nm --size-sort 159 160# The target exceptions here are intended for targets that have ELF as 161# an intermediate format or otherwise require the ELF-variant syntax 162# for proper size annotation. It would be nice if is_elf_format found 163# all the ELF variants, but adding the patterns here to that proc then 164# introduces a whole slew of new regressions in the GAS and LD testsuites. 165if { [is_elf_format] 166 || [istarget *-*-beos] 167 || [istarget *-*-dragonfly*] 168 || [istarget *-*-*elf] 169 || [istarget *-*-freebsd*] 170 || [istarget *-*-lynxos*] 171 || [istarget "mmix-knuth-mmixware"] 172 || [istarget *-*-netware*] 173 || [istarget *-*-nto*] 174 || [istarget *-*-rdos*] 175 || [istarget *-*-tpf*] 176 || [istarget *-*-uclinux*] 177 || [istarget ia64-*-*vms*] 178 || [istarget *-*-vxworks*] } { 179 set nm_1_src "nm-elf-1.s" 180} else { 181 set nm_1_src "nm-1.s" 182} 183 184if {![binutils_assemble $srcdir/$subdir/$nm_1_src tmpdir/nm-1.o]} then { 185 return 186} 187 188if [is_remote host] { 189 set tempfile [remote_download host tmpdir/nm-1.o] 190} else { 191 set tempfile tmpdir/nm-1.o 192} 193 194# This test does not work correctly on ECOFF targets, because ECOFF 195# stores most symbols twice, which messes up the nm output. 196setup_xfail "alpha*-*-osf*" "alpha*-*-netware*" 197setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*" 198setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*" "mips*-sony-bsd*" 199 200set got [binutils_run $NM "$NMFLAGS --size-sort $tempfile"] 201 202set want "0*4 T text_symbol3.*0*8 T text_symbol2.*0*c T text_symbol1" 203 204if [regexp $want $got] then { 205 pass "nm --size-sort" 206} else { 207 fail "nm --size-sort" 208} 209 210if [is_elf_format] { 211 # PR binutils/20751 212 # Test nm --with-symbol-versions 213 214 if {![binutils_assemble $srcdir/$subdir/nm-ver.s tmpdir/nm-ver.o]} then { 215 fail "nm --with-symbol-versions (assembling)" 216 } else { 217 if [is_remote host] { 218 set tmpfile [remote_download host tmpdir/nm-ver.o] 219 } else { 220 set tmpfile tmpdir/nm-ver.o 221 } 222 223 set got [binutils_run $NM "$NMFLAGS --with-symbol-versions --format sysv $tmpfile"] 224 225 if {! [regexp "foo@VER_1" $got]} then { 226 fail "nm --with-symbol-versions (grep for @VER_1)" 227 } else { 228 if {! [regexp "foo@VER_1" $got]} then { 229 fail "nm --with-symbol-versions (grep for @@VER_2)" 230 } else { 231 pass "nm --with-symbol-versions" 232 } 233 } 234 235 if { $verbose < 1 } { 236 remote_file host delete "tmpdir/nm-ver.o" 237 } 238 } 239} 240 241# There are certainly other tests that could be run. 242