Commit | Line | Data |
---|---|---|
82704155 | 1 | # Copyright (C) 1993-2019 Free Software Foundation, Inc. |
252b5132 RH |
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 | |
32866df7 | 5 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 RH |
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 | |
b43b5d5f | 15 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
252b5132 RH |
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 { | |
f795c494 | 34 | fail "nm (assembling)" |
252b5132 | 35 | } else { |
252b5132 | 36 | |
f795c494 AM |
37 | if [is_remote host] { |
38 | set tempfile [remote_download host tmpdir/bintest.o] | |
39 | } else { | |
40 | set tempfile tmpdir/bintest.o | |
41 | } | |
252b5132 | 42 | |
f795c494 | 43 | # Test nm with no arguments. |
252b5132 | 44 | |
f795c494 AM |
45 | # This test does not work correctly on ECOFF targets, because ECOFF |
46 | # stores most symbols twice, which messes up the nm output. | |
b4b594e3 | 47 | setup_xfail "alpha*-*-osf*" |
f795c494 | 48 | setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*" |
5972ac73 | 49 | setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*" |
252b5132 | 50 | |
f795c494 AM |
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*" | |
252b5132 | 54 | |
f795c494 | 55 | set got [binutils_run $NM "$NMFLAGS $tempfile"] |
252b5132 | 56 | |
f795c494 AM |
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 | } | |
252b5132 | 62 | |
f795c494 AM |
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 | } | |
252b5132 | 79 | |
f795c494 | 80 | # Test nm -g |
252b5132 | 81 | |
f795c494 | 82 | set got [binutils_run $NM "$NMFLAGS -g $tempfile"] |
252b5132 | 83 | |
f795c494 AM |
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 | } | |
252b5132 | 89 | |
f795c494 AM |
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" | |
4baeffab | 97 | } else { |
f795c494 | 98 | pass "nm -g" |
4baeffab | 99 | } |
0ba0c2b3 | 100 | |
f795c494 | 101 | # Test nm -P |
252b5132 | 102 | |
f795c494 AM |
103 | # This test does not work correctly on ECOFF targets, because ECOFF |
104 | # stores most symbols twice, which messes up the nm output. | |
b4b594e3 | 105 | setup_xfail "alpha*-*-osf*" |
f795c494 | 106 | setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*" |
5972ac73 | 107 | setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*" |
252b5132 | 108 | |
f795c494 AM |
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*" | |
252b5132 | 112 | |
f795c494 | 113 | set got [binutils_run $NM "$NMFLAGS -P $tempfile"] |
252b5132 | 114 | |
f795c494 | 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\]*" |
252b5132 | 116 | |
f795c494 AM |
117 | if [regexp $want $got] then { |
118 | pass "nm -P" | |
119 | } else { | |
120 | fail "nm -P" | |
121 | } | |
252b5132 RH |
122 | } |
123 | ||
8b64b65e TG |
124 | # Test nm --size-sort |
125 | ||
4d9eb7f4 HPN |
126 | # The target exceptions here are intended for targets that have ELF as |
127 | # an intermediate format or otherwise require the ELF-variant syntax | |
3ce958b2 NC |
128 | # for proper size annotation. It would be nice if is_elf_format found |
129 | # all the ELF variants, but adding the patterns here to that proc then | |
130 | # introduces a whole slew of new regressions in the GAS and LD testsuites. | |
131 | if { [is_elf_format] | |
96037eb0 | 132 | || [istarget *-*-beos] |
3ce958b2 NC |
133 | || [istarget *-*-dragonfly*] |
134 | || [istarget *-*-*elf] | |
135 | || [istarget *-*-freebsd*] | |
136 | || [istarget *-*-lynxos*] | |
137 | || [istarget "mmix-knuth-mmixware"] | |
3ce958b2 NC |
138 | || [istarget *-*-nto*] |
139 | || [istarget *-*-rdos*] | |
140 | || [istarget *-*-tpf*] | |
141 | || [istarget *-*-uclinux*] | |
142 | || [istarget ia64-*-*vms*] | |
f96bd6c2 PC |
143 | || [istarget *-*-vxworks*] |
144 | || [istarget wasm32-*-*] } { | |
8b64b65e TG |
145 | set nm_1_src "nm-elf-1.s" |
146 | } else { | |
147 | set nm_1_src "nm-1.s" | |
148 | } | |
149 | ||
150 | if {![binutils_assemble $srcdir/$subdir/$nm_1_src tmpdir/nm-1.o]} then { | |
f795c494 | 151 | fail "nm --size-sort (assembling)" |
8b64b65e | 152 | } else { |
8b64b65e | 153 | |
f795c494 AM |
154 | if [is_remote host] { |
155 | set tempfile [remote_download host tmpdir/nm-1.o] | |
156 | } else { | |
157 | set tempfile tmpdir/nm-1.o | |
158 | } | |
8b64b65e | 159 | |
f795c494 AM |
160 | # This test does not work correctly on ECOFF targets, because ECOFF |
161 | # stores most symbols twice, which messes up the nm output. | |
b4b594e3 | 162 | setup_xfail "alpha*-*-osf*" |
f795c494 | 163 | setup_xfail "mips*-*-ultrix*" "mips*-*-ecoff*" "mips*-*-irix4*" |
5972ac73 | 164 | setup_xfail "mips*-*-riscos*" "mips*-*-sysv3*" |
8b64b65e | 165 | |
f795c494 | 166 | set got [binutils_run $NM "$NMFLAGS --size-sort $tempfile"] |
8b64b65e | 167 | |
f795c494 AM |
168 | set want "0*4 T text_symbol3.*0*8 T text_symbol2.*0*c T text_symbol1" |
169 | ||
170 | if [regexp $want $got] then { | |
171 | pass "nm --size-sort" | |
172 | } else { | |
173 | fail "nm --size-sort" | |
174 | } | |
8b64b65e TG |
175 | } |
176 | ||
df2c87b5 | 177 | if [is_elf_format] { |
f795c494 AM |
178 | # PR binutils/12753 |
179 | # Test nm -g on a unique global symbol. | |
180 | if {![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o]} then { | |
181 | unsupported "nm -g on unique symbols" | |
182 | } else { | |
183 | if [is_remote host] { | |
184 | set tmpfile [remote_download host tmpdir/unique.o] | |
185 | } else { | |
186 | set tmpfile tmpdir/unique.o | |
187 | } | |
188 | ||
189 | set got [binutils_run $NM "$NMFLAGS -g $tmpfile"] | |
190 | ||
191 | if [regexp "u foo" $got] then { | |
192 | pass "nm -g on unique symbols" | |
193 | } else { | |
194 | fail "nm -g on unique symbols" | |
195 | } | |
196 | ||
197 | if { $verbose < 1 } { | |
198 | remote_file host delete "tmpdir/unique.o" | |
199 | } | |
200 | } | |
201 | ||
df2c87b5 NC |
202 | # PR binutils/20751 |
203 | # Test nm --with-symbol-versions | |
204 | ||
205 | if {![binutils_assemble $srcdir/$subdir/nm-ver.s tmpdir/nm-ver.o]} then { | |
206 | fail "nm --with-symbol-versions (assembling)" | |
207 | } else { | |
208 | if [is_remote host] { | |
209 | set tmpfile [remote_download host tmpdir/nm-ver.o] | |
210 | } else { | |
211 | set tmpfile tmpdir/nm-ver.o | |
212 | } | |
213 | ||
214 | set got [binutils_run $NM "$NMFLAGS --with-symbol-versions --format sysv $tmpfile"] | |
215 | ||
216 | if {! [regexp "foo@VER_1" $got]} then { | |
217 | fail "nm --with-symbol-versions (grep for @VER_1)" | |
218 | } else { | |
219 | if {! [regexp "foo@VER_1" $got]} then { | |
220 | fail "nm --with-symbol-versions (grep for @@VER_2)" | |
221 | } else { | |
222 | pass "nm --with-symbol-versions" | |
223 | } | |
224 | } | |
225 | ||
226 | if { $verbose < 1 } { | |
227 | remote_file host delete "tmpdir/nm-ver.o" | |
228 | } | |
229 | } | |
230 | } | |
231 | ||
252b5132 | 232 | # There are certainly other tests that could be run. |