gas: fix overflow diagnostics
[deliverable/binutils-gdb.git] / gas / testsuite / gas / all / gas.exp
CommitLineData
250d07de 1# Copyright (C) 2012-2021 Free Software Foundation, Inc.
5bf135a7
NC
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
252b5132
RH
17#
18# These tests should be valid on all targets.
19#
20
21# I think currently all targets fail this one when listings are enabled.
22gas_test "p2425.s" "" "" "pcrel values in assignment"
23
24# p1480.s uses a ".space" directive which for most assemblers means
25# "allocate some space". On the PA it means "switch into this space".
26#
27# Therefore this test (as it is currently written) is completely bogus
28# for any PA target. Do not bother trying to run it and just claim
29# it fails.
39bec121
TW
30#
31# The C54x uses ".space" to allocate bits, and requires absolute expressions;
32# The ".space" directive is taken care of in the C54x-specific tests, so fail
33# here
34#
280d71bf
DB
35# The test also doesn't work on mep targets, since they use RELC, and it
36# will avoid simplifying the expression since it conservatively assumes
37# ugly expressions can be saved until link-time.
38if { [istarget hppa*-*-*] || [istarget *c54x*-*-*] || [istarget mep*-*-*]} then {
252b5132
RH
39 setup_xfail *-*-*
40 fail "simplifiable double subtraction"
41} else {
42 gas_test "p1480.s" "" "-a>" "simplifiable double subtraction"
43}
44
3c9b82ba
NC
45# No floating point support in assembly code for CRIS and Z80.
46if { ![istarget cris-*-*] && ![istarget crisv32-*-*]
47 && ![istarget z80-*-*] } then {
483f05e3
HPN
48 gas_test "float.s" "" "" "simple FP constants"
49}
252b5132
RH
50
51# This test is meaningless for the PA; the difference of two undefined
52# symbols is something that is (and must be) supported on the PA.
3ee6e4fb 53# The same is true for ALPHA-VMS.
569006e5 54#
3ee6e4fb
NC
55# The AVR, MICROBLAZE, MN10300, RL78 and RX ports all support link time
56# relaxation, which in turn allows for link time resolution of the
57# differences of two previously undefined symbols. Hence this test will
58# not pass for these targets.
59if { ![istarget alpha*-*-*vms*]
60 && ![istarget am3*-*-*]
edc9e9a6 61 && ![istarget avr-*-*]
81b42bca 62 && ![istarget ft32-*-*]
3ee6e4fb
NC
63 && ![istarget hppa*-*-*]
64 && ![istarget microblaze-*-*]
c7927a3c 65 && ![istarget mn10300-*-*]
13761a11 66 && ![istarget msp430*-*-*]
8d6502d2 67 && ![istarget powerpc*-*-aix*]
8dfa5d5a 68 && ![istarget riscv*-*-*]
3ee6e4fb 69 && ![istarget rl78-*-*]
8d6502d2 70 && ![istarget rs6000*-*-aix*]
3ee6e4fb 71 && ![istarget rx-*-*] } then {
252b5132
RH
72 gas_test_error "diff1.s" "" "difference of two undefined symbols"
73}
74
9497f5ac
NC
75gas_test_error "equiv1.s" "" ".equiv for symbol already set to another one"
76gas_test_error "equiv2.s" "" ".equiv for symbol already set to an expression"
77
ca60b3af
SL
78# The inode comparison used to detect identical input and output files
79# doesn't work on non-Posix hosts.
80if { ![ishost "*-*-mingw*"] } then {
81 gas_test_error "none.s" "-o $srcdir/$subdir/none.s" "Output file must be distinct from input"
82}
67f846b5 83
9497f5ac 84# .equ works differently on some targets.
e3696f67
AM
85switch -glob $target_triplet {
86 hppa*-*-* { }
87 *c54x*-*-* { }
9497f5ac
NC
88 default {
89 gas_test "equ-ok.s" "" "" ".equ for symbol already set"
90 gas_test_error "equ-bad.s" "" ".equ for symbol already set through .eqv"
91 }
92}
93
94gas_test "eqv-ok.s" "" "" ".eqv support"
95gas_test_error "eqv-bad.s" "" ".eqv for symbol already set"
66e3eb08
SC
96if { [istarget "pdp11-*-*"] } then {
97 run_dump_test eqv-dot-pdp11
98} else {
99 run_dump_test eqv-dot
100}
9497f5ac 101
3f904b16
AM
102if { ![istarget "bfin-*-*"] } then {
103 gas_test "assign-ok.s" "" "" "== assignment support"
104}
9497f5ac 105gas_test_error "assign-bad.s" "" "== assignment for symbol already set"
2a50b401 106run_dump_test assign-bad-recursive
d27aad4e 107run_dump_test local-label-overflow
9497f5ac 108
1f38083f 109run_dump_test simple-forward
7553c869 110run_dump_test forward
9497f5ac 111
e8044f35 112# aout relocs are often weird, so is mep. don't bother testing
f9022510
AM
113# som doesn't use a .text section
114# mmix doesn't like .L1:
115# ti addresses aren't octets.
116if { ![is_aout_format] } {
e3696f67
AM
117 switch -glob $target_triplet {
118 hppa*64*-*-* {
01c51e44
DA
119 run_dump_test fwdexp
120 }
e3696f67
AM
121 alpha-*-*linux*ecoff { }
122 alpha-*-osf* { }
123 hppa*-*-hpux* { }
124 mep-*-* { }
125 mmix-*-* { }
126 nds32*-*-* { }
127 tic30*-*-* { }
128 tic4x*-*-* { }
129 tic54x*-*-* { }
f9022510
AM
130 default {
131 run_dump_test fwdexp
132 }
133 }
134}
135
9497f5ac 136# .set works differently on some targets.
f42fb574
AM
137# most of the tests won't work on targets that set linkrelax.
138# 4 octet bytes confuse address matching on ti targets.
139# pdp11 gets unexpected reloc types.
e3696f67
AM
140switch -glob $target_triplet {
141 alpha*-*-* { }
142 am3*-*-* { }
143 cr16*-*-* { }
144 crx*-*-* { }
145 h8300-*-* { }
146 mips*-*-* { }
147 mn10200-*-* { }
148 mn10300-*-* { }
149 msp430*-*-* { }
150 nds32*-*-* { }
151 pdp11-*-* { }
152 tic30*-*-* { }
153 tic4x*-*-* { }
154 tic54x*-*-* { }
155 xtensa*-*-* { }
156 z80-*-* { }
9497f5ac 157 default {
9497f5ac 158 run_dump_test redef
8b0aac0f
AM
159 # These targets fail redef2 because they disallow redefined
160 # symbols on relocs.
3ee6e4fb 161 setup_xfail "m68hc1*-*-*" "m6811-*-*" "m6812-*-*" "rl78-*-*"
e23eba97 162 setup_xfail "riscv*-*-*" "rx-*-*" "vax*-*-*" "xgate*-*-*" "z8k-*-*"
5ca0ee01 163 run_dump_test redef2
3ee6e4fb 164 setup_xfail "m68hc1*-*-*" "m6811-*-*" "m6812-*-*" "rl78-*-*"
e23eba97 165 setup_xfail "riscv*-*-*" "rx-*-*" "vax*-*-*" "xgate*-*-*" "z8k-*-*"
8b0aac0f 166 # rs6000-aix disallows redefinition via .comm.
34e79798
AM
167 if [is_xcoff_format] {
168 setup_xfail *-*-*
169 }
8b0aac0f
AM
170 # These targets fail redef3 because section contents for the
171 # word referencing the .comm sym is not zero and/or its reloc
172 # has a non-zero addend. Relaxing the test would hide real
73589c9d 173 # failures.
8b0aac0f
AM
174 setup_xfail "bfin-*-*" "i\[3-7\]86-*-*coff" \
175 "i\[3-7\]86-*-*pe" "i\[3-7\]86-*-go32*" \
3ee6e4fb
NC
176 "i\[3-7\]86-*-cygwin*" "i\[3-7\]86-*-mingw*" \
177 "x86_64-*-cygwin*" "x86_64-*-mingw*"
92757bc9 178 run_dump_test redef3
92757bc9 179 gas_test_error "redef4.s" "" ".set for symbol already used as label"
92757bc9 180 gas_test_error "redef5.s" "" ".set for symbol already defined through .comm"
9497f5ac
NC
181 }
182}
183
252b5132
RH
184proc do_comment {} {
185 set testname "comment.s: comments in listings"
186 set x1 0
187 set x2 0
188 set x3 0
189 set white {[ \t]*}
190 gas_start "comment.s" "-al"
191 while 1 {
192# Apparently CRLF is received when using ptys for subprocesses; hence the
193# \r\n for line 3.
194 expect {
195 -re "^ +1\[ \t\]+# This\[^\n\]*\n" { set x1 1 }
196 -re "^ +2\[ \t\]+# correctly\[^\n\]*\n" { set x2 1 }
7f6a71ff 197 -re "^ +3\[ \t\]+/. C comments too. ./\r?\r?\n" { set x3 1 }
252b5132
RH
198 -re "\[^\n\]*\n" { }
199 timeout { perror "timeout\n"; break }
200 eof { break }
201 }
202 }
203 gas_finish
204 if [all_ones $x1 $x2 $x3] then { pass $testname } else { fail $testname }
205}
206
27cdfa03 207do_comment
252b5132 208
83f10cb2
NC
209# This test checks the output of the -ag switch. It must detect at least
210# the name of the input file, output file, and options passed.
211proc general_info_section {} {
212 set testname "general info section in listings"
213 set x1 0
214 set x2 0
215 set x3 0
216 set white {[ \t]*}
217 gas_start "comment.s" "-agn"
218 while 1 {
219 expect {
c7927a3c 220 -re "^ \[^\n\]*\t: .*\-agn\[^\n\]*\n" { set x1 1 }
83f10cb2
NC
221 -re "^ \[^\n\]*\t: \[^\n\]*comment\.s\[^\n\]*\n" { set x2 1 }
222 -re "^ \[^\n\]*\t: a\.out\[^\n\]*\n" { set x3 1 }
223 -re "\[^\n\]*\n" { }
224 timeout { perror "timeout\n"; break }
225 eof { break }
226 }
227 }
228 gas_finish
229 if [all_ones $x1 $x2 $x3] then { pass $testname } else { fail $testname }
230}
231
232general_info_section
233
252b5132
RH
234#
235# Test x930509a -- correct assembly of differences involving forward
236# references.
237#
238
239proc do_930509a {} {
240 set testname "difference between forward references"
241 set x 0
242 gas_start "x930509.s" "-al"
243 while 1 {
c29ae970 244# We need to accommodate both byte orders here.
252b5132
RH
245# If ".long" means an 8-byte value on some target someday, this test will have
246# to be fixed.
247 expect {
224de7a5
AM
248 -re "^ +1 .... 00 ?00 ?00 ?00" { fail $testname; set x 1 }
249 -re "^ +1 .... 04 ?00 ?00 ?00" { pass $testname; set x 1 }
250 -re "^ +1 .... 00 ?00 ?00 ?04" { pass $testname; set x 1 }
252b5132
RH
251 -re "\[^\n\]*\n" { }
252 timeout { perror "timeout\n"; break }
253 eof { break }
254 }
255 }
256 gas_finish
257 if !$x then { fail $testname }
258}
259
3ccac826
NC
260# This test is meaningless for the PA and CR16/CRX: the difference of two
261# symbols cannot be resolved by the assembler.
39bec121 262# C54x assembler (for compatibility) does not allow differences between
3ccac826 263# forward references.
8bda4946 264# C30 counts a four byte offset as a difference of one.
3ee6e4fb
NC
265if { ![istarget *c30*-*-*]
266 && ![istarget *c4x*-*-*]
267 && ![istarget *c54x*-*-*]
268 && ![istarget cr16*-*-*]
269 && ![istarget crx*-*-*]
81b42bca 270 && ![istarget ft32-*-*]
3ee6e4fb
NC
271 && ![istarget h8300*-*-*]
272 && ![istarget hppa*-*-*] } then {
273 # The vax fails because VMS can apparently actually handle this
252b5132 274 # case in relocs, so gas doesn't handle it itself.
e23eba97 275 # msp430, mn10[23]00 and riscv emit two relocs to handle the difference of two symbols.
75800d2c 276 setup_xfail "am3*-*-*" "mn10200-*-*" "mn10300*-*-*" "msp430*-*-*" "riscv*-*-*" "vax*-*-vms*"
252b5132
RH
277 do_930509a
278}
279
39bec121
TW
280# ".struct" and ".align" have different meanings on c54x
281# These directives are done in the c54x-specific tests instead
e3696f67
AM
282switch -glob $target_triplet {
283 hppa*-*-* { }
284 *c4x*-*-* { }
285 *c54x*-*-* { }
252b5132
RH
286 default {
287 run_dump_test struct
288 run_dump_test align
76101304 289 run_dump_test align2
252b5132
RH
290 }
291}
292
5069eab2 293# '<' and '>' appear to have special meanings on the excluded targets
e3696f67
AM
294switch -glob $target_triplet {
295 frv-*-* { }
296 hppa*-*-* { }
297 m32r-*-* { }
298 mmix-*-* { }
299 *c4x*-*-* { }
300 *c54x*-*-* { }
301 bfin-*-* { }
5069eab2
NC
302 default {
303 run_dump_test altmacro
304 # The second test is valid only when '!' is not a comment
305 # character (it is allowed to be a line comment character).
26a78d4a 306 if [string match "" [lindex [gas_run excl.s "-o /dev/null" ""] 0]] {
5069eab2 307 run_dump_test altmac2
c29ae970 308 # Similarly this test does not work when ! is a line separator.
9497f5ac 309 run_dump_test eval
5069eab2
NC
310 }
311 }
312}
caa32fe5 313
252b5132 314# This test is for any COFF target.
252b5132
RH
315# We omit the ARM toolchains because they define locals to
316# start with '.', which eliminates .eos, .text etc from the output.
39bec121 317# Omit c54x, since .tag and .def mean something different on that target
8c5fc800
JM
318if { ([istarget *-*-coff*] && ![istarget arm*-*-coff] && ![istarget *c4x*-*-coff] && ![istarget *c54x*-*-coff]) \
319 ||([istarget *-*-pe*] && ![istarget arm*-*-pe*]) \
252b5132
RH
320 || [istarget i*86-*-aix*] \
321 || [istarget i*86-*-sco*] \
322 || [istarget i*86-*-isc*] \
323 || [istarget i*86-*-go32*] \
324 || [istarget i*86-*-cygwin*] \
42037fe5 325 || [istarget x86_64-*-mingw*] \
252b5132 326 || [istarget i*86-*-*nt] \
a8eb42a8 327 || [istarget i*86-*-interix*] } {
252b5132
RH
328 run_dump_test cofftag
329}
330
331# Test omitting conditionals from listings.
332proc test_cond {} {
333 global comp_output
334 global srcdir
335 global subdir
336
337 set testname "conditional listings"
66e3eb08
SC
338 if { [istarget "pdp11-*-*"] } then {
339 set listing "cond-pdp11.l"
340 } else {
341 set listing "cond.l"
342 }
224de7a5 343 gas_run cond.s "-alc" ">dump.out"
252b5132
RH
344 if ![string match "" $comp_output] {
345 send_log "$comp_output\n"
346 fail $testname
347 } else {
66e3eb08 348 if { [regexp_diff dump.out $srcdir/$subdir/$listing] } {
252b5132
RH
349 fail $testname
350 } else {
351 pass $testname
352 }
353 }
354}
355
c8060cba
JL
356# This test is not suitable for the PA for various reasons
357# not limited to the fact that it depends on specific section
358# names appearing in the output file.
3ee6e4fb 359# Again, p2align doesn't work on c54x and related targets.
e3696f67
AM
360switch -glob $target_triplet {
361 alpha-*-linux*ecoff { }
362 alpha-*-osf* { }
363 hppa*-*-* { }
364 *c4x*-*-* { }
365 *c54x*-*-* { }
366 rl78-*-* { }
367 rx-*-* { }
aceebfd6
NC
368 default {
369 test_cond
7f6a71ff 370 remote_download host "$srcdir/$subdir/incbin.dat"
aceebfd6
NC
371 run_dump_test incbin
372 }
39bec121 373}
c9e38879 374
4504a634
JB
375# Various targets use too custom handling to be able to sensibly create
376# common expecations for this test. Also .equ works differently on some
377# targets.
378if { ![istarget avr-*-*]
379 && ![istarget bfin-*-*]
380 && ![istarget cris*-*-*]
381 && ![istarget dlx-*-*]
382 && ![istarget hppa*-*-*]
383 && ![istarget m68k-*-*]
384 && ![istarget nios2-*-*]
385 && ![istarget pj-*-*]
386 && ![istarget sh*-*-*]
387 && ![istarget *c4x-*-*]
388 && ![istarget *c54x-*-*]
389 && ![istarget *c6x-*-*]
390 && ![istarget z80-*-*] } then {
391 # Some further targets' custom handling fails to recognize the overflows.
392 setup_xfail "crx-*-*" "h8300-*-*" "mcore-*-*" "mn10200-*-*" "mn10300-*-*" "msp430-*-*" "ns32k-*-*"
393 run_list_test "overflow"
394}
395
01ed09aa 396if { ([istarget "i*86-*-*pe*"] && ![istarget "i*86-*-openbsd*"]) \
b46c1691
NC
397 || [istarget "i*86-*-cygwin*"] \
398 || [istarget "i*86-*-mingw32*"] } {
399 gas_test "fastcall.s" "" "" "fastcall labels"
400}
a7eec876 401
35c08157 402if { ![istarget "bfin-*-*"] && ![istarget "nds32*-*-*"] } then {
3f904b16
AM
403 run_dump_test assign
404}
e5604d79 405run_dump_test sleb128
956a6ba3
JB
406run_dump_test sleb128-2
407run_dump_test sleb128-3
408run_dump_test sleb128-4
409run_dump_test sleb128-5
4455e9ad
JB
410# .byte is not 8 bits on either tic4x or tic54x
411if { ![istarget "tic4x*-*-*"] && ![istarget "tic54x*-*-*"] } {
412 run_dump_test sleb128-7
1a94eb29 413 run_dump_test sleb128-8
4455e9ad 414}
ba8826a8 415run_dump_test sleb128-9
ddc07134 416
5e9ed83f 417# .byte is 32 bits on tic4x, and .p2align isn't supported on tic54x
17b939cd 418# .space is different on hppa*-hpux.
ec0c103c
NC
419# MeP put bytes into packets.
420if { ![istarget "tic4x*-*-*"] && ![istarget "tic54x*-*-*"] && ![istarget "hppa*-*-hpux*"] && ![istarget "mep*-*-*"] } {
5e9ed83f
L
421 run_dump_test relax
422}
423
a8eb42a8 424run_dump_test quad
66e3eb08
SC
425
426# poor little PDP-11 can't handle 16-byte values
427if { ![istarget "pdp11-*-*"] } {
428 run_dump_test octa
429}
3c9b82ba
NC
430
431# .set works differently on some targets.
e3696f67
AM
432switch -glob $target_triplet {
433 alpha*-*-* { }
434 mips*-*-* { }
435 *c54x*-*-* { }
436 z80-*-* { }
3c9b82ba
NC
437 default {
438 run_dump_test weakref1
439 run_dump_test weakref1g
440 run_dump_test weakref1l
441 run_dump_test weakref1u
442 run_dump_test weakref1w
443 }
444}
06e77878
AO
445gas_test_error "weakref2.s" "" "e: would close weakref loop: e => a => b => c => d => e"
446gas_test_error "weakref3.s" "" "a: would close weakref loop: a => b => c => d => e => a"
b54788f8 447gas_test_error "weakref4.s" "" "is already defined"
06e77878 448
38a57ae7 449run_dump_test string
740bdc67
AM
450if [is_elf_format] {
451 run_dump_test none
452}
38a57ae7 453
d02603dc
NC
454run_dump_test quoted-sym-names
455
93a24ba7
MR
456run_list_test pr20312
457
a7eec876
HPN
458load_lib gas-dg.exp
459dg-init
460dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/err-*.s $srcdir/$subdir/warn-*.s]] "" ""
461dg-finish
9875b365
MR
462
463# Set $nop_type appropriately to indicate the NOP instruction mnemonic.
b1766e7c 464# Note - this code is made obsolete by the new .nops pseudo-op.
e3696f67
AM
465switch -glob $target_triplet {
466 bpf-*-* {
f8861f5d
JM
467 set nop_type 6
468 }
e3696f67 469 mmix-*-* {
9875b365
MR
470 set nop_type 5
471 }
e3696f67 472 or1k*-*-* {
9875b365
MR
473 set nop_type 2
474 }
e3696f67 475 ia64-*-* {
9875b365
MR
476 set nop_type 1
477 }
478 default {
479 set nop_type 0
480 }
481}
482run_dump_test "org-1" [list [list as "--defsym nop_type=$nop_type"]]
483run_dump_test "org-2"
484run_dump_test "org-3"
485run_dump_test "org-4"
486run_dump_test "org-5"
487run_dump_test "org-6"
4f2358bc 488
fa57faa0 489run_dump_test "fill-1"
0acc7632
AM
490
491gas_test "pr23938.s" "" "" ".xstabs"
b1766e7c
NC
492
493run_dump_test "nop"
3d955acb 494run_dump_test "asciz"
4a68fcd7 495run_dump_test "pr27384"
284beb43 496run_dump_test "pr27381"
This page took 0.965738 seconds and 4 git commands to generate.