gas: fix overflow diagnostics
[binutils-gdb.git] / gas / testsuite / gas / all / gas.exp
index 8fa89e41a83d7a19b59f6eb9797838d7ed01e999..389634f616546a0fc4dea85649320e42625bbb2d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2014 Free Software Foundation, Inc.
+# Copyright (C) 2012-2021 Free Software Foundation, Inc.
 
 # 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
@@ -50,28 +50,41 @@ if { ![istarget cris-*-*] && ![istarget crisv32-*-*]
 
 # This test is meaningless for the PA; the difference of two undefined
 # symbols is something that is (and must be) supported on the PA.
-# The same is true for alpha-vms
+# The same is true for ALPHA-VMS.
 #
-# The MN10300 port supports link time relaxation which in turn allows
-# for link time resolution of the differneces of two symbols which are
-# undefined at assembly time.  Hence this test will not pass for the
-# MN10300.  The same thing is true for the RX port as well.
-if { ![istarget hppa*-*-*]
-     && ![istarget alpha*-*-*vms*]
-     && ![istarget rx-*-*]
+# The AVR, MICROBLAZE, MN10300, RL78 and RX ports all support link time
+# relaxation, which in turn allows for link time resolution of the
+# differences of two previously undefined symbols.  Hence this test will
+# not pass for these targets.
+if {    ![istarget alpha*-*-*vms*]
+     && ![istarget am3*-*-*]
+     && ![istarget avr-*-*]
+     && ![istarget ft32-*-*]
+     && ![istarget hppa*-*-*]
+     && ![istarget microblaze-*-*]
      && ![istarget mn10300-*-*]
      && ![istarget msp430*-*-*]
-     && ![istarget am3*-*-*] } then {
+     && ![istarget powerpc*-*-aix*]
+     && ![istarget riscv*-*-*]
+     && ![istarget rl78-*-*]
+     && ![istarget rs6000*-*-aix*]
+     && ![istarget rx-*-*] } then {
     gas_test_error "diff1.s" "" "difference of two undefined symbols"
 }
 
 gas_test_error "equiv1.s" "" ".equiv for symbol already set to another one"
 gas_test_error "equiv2.s" "" ".equiv for symbol already set to an expression"
 
+# The inode comparison used to detect identical input and output files
+# doesn't work on non-Posix hosts.
+if { ![ishost "*-*-mingw*"] } then {
+    gas_test_error "none.s" "-o $srcdir/$subdir/none.s" "Output file must be distinct from input"
+}
+
 # .equ works differently on some targets.
-case $target_triplet in {
-    { hppa*-*-* } { }
-    { *c54x*-*-* } { }
+switch -glob $target_triplet {
+    hppa*-*-* { }
+    *c54x*-*-* { }
     default {
        gas_test "equ-ok.s" "" "" ".equ for symbol already set"
        gas_test_error "equ-bad.s" "" ".equ for symbol already set through .eqv"
@@ -80,47 +93,40 @@ case $target_triplet in {
 
 gas_test "eqv-ok.s" "" "" ".eqv support"
 gas_test_error "eqv-bad.s" "" ".eqv for symbol already set"
+if { [istarget "pdp11-*-*"] } then {
+    run_dump_test eqv-dot-pdp11
+} else {
+    run_dump_test eqv-dot
+}
 
 if { ![istarget "bfin-*-*"] } then {
     gas_test "assign-ok.s" "" "" "== assignment support"
 }
 gas_test_error "assign-bad.s" "" "== assignment for symbol already set"
+run_dump_test assign-bad-recursive
+run_dump_test local-label-overflow
 
-# .equ works differently on some targets.
-# linkrelax-ing prevents most forward references from working.
-case $target_triplet in {
-    { *c54x*-*-* } { }
-    { cr16*-*-* } { }
-    { crx*-*-* } { }
-    { h8300*-*-* } { }
-    { hppa*-*-* } { }
-    { mep-*-* } { }
-    { mn10\[23\]00*-*-* } { }
-    default {
-       # Some targets don't manage to resolve BFD_RELOC_8 for constants.
-       setup_xfail "alpha*-*-*" "*c30*-*-*" "*c4x*-*-*" \
-           "d\[13\]0v*-*-*" "i860-*-*" \
-           "nds32*-*-*" "pdp11-*-*" "xtensa*-*-*"
-       run_dump_test forward
-    }
-}
+run_dump_test simple-forward
+run_dump_test forward
 
 # aout relocs are often weird, so is mep. don't bother testing
 # som doesn't use a .text section
 # mmix doesn't like .L1:
 # ti addresses aren't octets.
 if { ![is_aout_format] } {
-    case $target_triplet in {
-       { hppa*64*-*-* } {
+    switch -glob $target_triplet {
+       hppa*64*-*-* {
            run_dump_test fwdexp
        }
-       { hppa*-*-hpux* } { }
-       { mep-*-* } { }
-       { mmix-*-* } { }
-       { nds32*-*-* } { }
-       { tic30*-*-* } { }
-       { tic4x*-*-* } { }
-       { tic54x*-*-* } { }
+       alpha-*-*linux*ecoff { }
+       alpha-*-osf* { }
+       hppa*-*-hpux* { }
+       mep-*-* { }
+       mmix-*-* { }
+       nds32*-*-* { }
+       tic30*-*-* { }
+       tic4x*-*-* { }
+       tic54x*-*-* { }
        default {
            run_dump_test fwdexp
        }
@@ -131,42 +137,44 @@ if { ![is_aout_format] } {
 # most of the tests won't work on targets that set linkrelax.
 # 4 octet bytes confuse address matching on ti targets.
 # pdp11 gets unexpected reloc types.
-case $target_triplet in {
-    { alpha*-*-* } { }
-    { cr16*-*-* } { }
-    { crx*-*-* } { }
-    { h8300-*-* } { }
-    { mips*-*-* } { }
-    { mn10200-*-* } { }
-    { mn10300-*-* } { }
-    { msp430*-*-* } { }
-    { nds32*-*-* } { }
-    { pdp11-*-* } { }
-    { tic30*-*-* } { }
-    { tic4x*-*-* } { }
-    { tic54x*-*-* } { }
-    { xtensa*-*-* } { }
-    { z80-*-* } { }
+switch -glob $target_triplet {
+    alpha*-*-* { }
+    am3*-*-* { }
+    cr16*-*-* { }
+    crx*-*-* { }
+    h8300-*-* { }
+    mips*-*-* { }
+    mn10200-*-* { }
+    mn10300-*-* { }
+    msp430*-*-* { }
+    nds32*-*-* { }
+    pdp11-*-* { }
+    tic30*-*-* { }
+    tic4x*-*-* { }
+    tic54x*-*-* { }
+    xtensa*-*-* { }
+    z80-*-* { }
     default {
        run_dump_test redef
        # These targets fail redef2 because they disallow redefined
        # symbols on relocs.
-       setup_xfail "m68hc1*-*-*" "m6811-*-*" "m6812-*-*"
-       setup_xfail "rx-*-*" "vax*-*-*" "xgate*-*-*" "z8k-*-*"
+       setup_xfail "m68hc1*-*-*" "m6811-*-*" "m6812-*-*" "rl78-*-*"
+       setup_xfail "riscv*-*-*" "rx-*-*" "vax*-*-*" "xgate*-*-*" "z8k-*-*"
        run_dump_test redef2
-       setup_xfail "m68hc1*-*-*" "m6811-*-*" "m6812-*-*"
-       setup_xfail "rx-*-*" "vax*-*-*" "xgate*-*-*" "z8k-*-*"
+       setup_xfail "m68hc1*-*-*" "m6811-*-*" "m6812-*-*" "rl78-*-*"
+       setup_xfail "riscv*-*-*" "rx-*-*" "vax*-*-*" "xgate*-*-*" "z8k-*-*"
        # rs6000-aix disallows redefinition via .comm.
-       setup_xfail "*-*-aix*"
-       # SOM uses a different syntax for .comm
-       setup_xfail "hppa*-*-hpux*"
+       if [is_xcoff_format] {
+           setup_xfail *-*-*
+       }
        # These targets fail redef3 because section contents for the
        # word referencing the .comm sym is not zero and/or its reloc
        # has a non-zero addend.  Relaxing the test would hide real
        # failures.
        setup_xfail "bfin-*-*" "i\[3-7\]86-*-*coff" \
            "i\[3-7\]86-*-*pe" "i\[3-7\]86-*-go32*" \
-           "i\[3-7\]86-*-cygwin*" "i\[3-7\]86-*-mingw*" "x86_64-*-mingw*"
+           "i\[3-7\]86-*-cygwin*" "i\[3-7\]86-*-mingw*" \
+           "x86_64-*-cygwin*" "x86_64-*-mingw*"
        run_dump_test redef3
        gas_test_error "redef4.s" "" ".set for symbol already used as label"
        gas_test_error "redef5.s" "" ".set for symbol already defined through .comm"
@@ -196,13 +204,7 @@ proc do_comment {} {
     if [all_ones $x1 $x2 $x3] then { pass $testname } else { fail $testname }
 }
 
-# m32c pads out sections, even empty ones.
-case $target_triplet in {
-    { m32c-*-* } { }
-    default {
-       do_comment
-    }
-}
+do_comment
 
 # This test checks the output of the -ag switch. It must detect at least
 # the name of the input file, output file, and options passed.
@@ -239,7 +241,7 @@ proc do_930509a {} {
     set x 0
     gas_start "x930509.s" "-al"
     while 1 {
-# We need to accomodate both byte orders here.
+# We need to accommodate both byte orders here.
 # If ".long" means an 8-byte value on some target someday, this test will have
 # to be fixed.
        expect {
@@ -260,25 +262,27 @@ proc do_930509a {} {
 # C54x assembler (for compatibility) does not allow differences between
 # forward references.
 # C30 counts a four byte offset as a difference of one.
-if { ![istarget hppa*-*-*] &&
-     ![istarget cr16*-*-*] &&
-     ![istarget  crx*-*-*] &&
-     ![istarget *c30*-*-*] &&
-     ![istarget *c4x*-*-*] &&
-     ![istarget *c54x*-*-*] } then {
-    # the vax fails because VMS can apparently actually handle this
+if {    ![istarget *c30*-*-*]
+     && ![istarget *c4x*-*-*]
+     && ![istarget *c54x*-*-*]
+     && ![istarget cr16*-*-*]
+     && ![istarget crx*-*-*]
+     && ![istarget ft32-*-*]
+     && ![istarget h8300*-*-*]
+     && ![istarget hppa*-*-*] } then {
+    # The vax fails because VMS can apparently actually handle this
     # case in relocs, so gas doesn't handle it itself.
-    # msp430 and mn10300 emit two relocs to handle the difference of two symbols.
-    setup_xfail "mn10300*-*-*" "msp430*-*-*" "vax*-*-vms*"
+    # msp430, mn10[23]00 and riscv emit two relocs to handle the difference of two symbols.
+    setup_xfail "am3*-*-*" "mn10200-*-*" "mn10300*-*-*" "msp430*-*-*" "riscv*-*-*" "vax*-*-vms*"
     do_930509a
 }
 
 # ".struct" and ".align" have different meanings on c54x
 # These directives are done in the c54x-specific tests instead
-case $target_triplet in {
-    { hppa*-*-* } { }
-    { *c4x*-*-* } { }
-    { *c54x*-*-* } { }
+switch -glob $target_triplet {
+    hppa*-*-* { }
+    *c4x*-*-* { }
+    *c54x*-*-* { }
     default {
        run_dump_test struct
        run_dump_test align
@@ -287,21 +291,21 @@ case $target_triplet in {
 }
 
 # '<' and '>' appear to have special meanings on the excluded targets
-case $target_triplet in {
-    { frv-*-* } { }
-    { hppa*-*-* } { }
-    { m32r-*-* } { }
-    { mmix-*-* } { }
-    { *c4x*-*-* } { }
-    { *c54x*-*-* } { }
-    { bfin-*-* } { }
+switch -glob $target_triplet {
+    frv-*-* { }
+    hppa*-*-* { }
+    m32r-*-* { }
+    mmix-*-* { }
+    *c4x*-*-* { }
+    *c54x*-*-* { }
+    bfin-*-* { }
     default {
        run_dump_test altmacro
        # The second test is valid only when '!' is not a comment
        # character (it is allowed to be a line comment character).
        if [string match "" [lindex [gas_run excl.s "-o /dev/null" ""] 0]] {
            run_dump_test altmac2
-           # Similarly this test does not work when ! is a line seperator.
+           # Similarly this test does not work when ! is a line separator.
            run_dump_test eval
        }
     }
@@ -320,8 +324,7 @@ if {   ([istarget *-*-coff*] && ![istarget arm*-*-coff] && ![istarget *c4x*-*-co
      || [istarget i*86-*-cygwin*] \
      || [istarget x86_64-*-mingw*] \
      || [istarget i*86-*-*nt] \
-     || [istarget i*86-*-interix*] \
-     || ([istarget i960-*-vxworks5.*] && ![istarget i960-*-vxworks5.0*]) } {
+     || [istarget i*86-*-interix*] } {
     run_dump_test cofftag
 }
 
@@ -332,12 +335,17 @@ proc test_cond {} {
     global subdir
 
     set testname "conditional listings"
+    if { [istarget "pdp11-*-*"] } then {
+       set listing "cond-pdp11.l"
+    } else {
+       set listing "cond.l"
+    }
     gas_run cond.s "-alc" ">dump.out"
     if ![string match "" $comp_output] {
        send_log "$comp_output\n"
        fail $testname
     } else {
-       if { [regexp_diff dump.out $srcdir/$subdir/cond.l] } {
+       if { [regexp_diff dump.out $srcdir/$subdir/$listing] } {
            fail $testname
        } else {
            pass $testname
@@ -348,12 +356,15 @@ proc test_cond {} {
 # This test is not suitable for the PA for various reasons
 # not limited to the fact that it depends on specific section
 # names appearing in the output file.
-# again, p2align doesn't work on c54x target
-case $target_triplet in {
-    { hppa*-*-* } { }
-    { *c4x*-*-* } { }
-    { *c54x*-*-* } { }
-    { rx-*-* } { }
+# Again, p2align doesn't work on c54x and related targets.
+switch -glob $target_triplet {
+    alpha-*-linux*ecoff { }
+    alpha-*-osf* { }
+    hppa*-*-* { }
+    *c4x*-*-* { }
+    *c54x*-*-* { }
+    rl78-*-* { }
+    rx-*-* { }
     default {
         test_cond
        remote_download host "$srcdir/$subdir/incbin.dat"
@@ -361,6 +372,27 @@ case $target_triplet in {
     }
 }
 
+# Various targets use too custom handling to be able to sensibly create
+# common expecations for this test.  Also .equ works differently on some
+# targets.
+if {    ![istarget avr-*-*]
+     && ![istarget bfin-*-*]
+     && ![istarget cris*-*-*]
+     && ![istarget dlx-*-*]
+     && ![istarget hppa*-*-*]
+     && ![istarget m68k-*-*]
+     && ![istarget nios2-*-*]
+     && ![istarget pj-*-*]
+     && ![istarget sh*-*-*]
+     && ![istarget *c4x-*-*]
+     && ![istarget *c54x-*-*]
+     && ![istarget *c6x-*-*]
+     && ![istarget z80-*-*] } then {
+    # Some further targets' custom handling fails to recognize the overflows.
+    setup_xfail "crx-*-*" "h8300-*-*" "mcore-*-*" "mn10200-*-*" "mn10300-*-*" "msp430-*-*" "ns32k-*-*"
+    run_list_test "overflow"
+}
+
 if {  ([istarget "i*86-*-*pe*"] && ![istarget "i*86-*-openbsd*"]) \
     || [istarget "i*86-*-cygwin*"] \
     || [istarget "i*86-*-mingw32*"] } {
@@ -373,13 +405,14 @@ if { ![istarget "bfin-*-*"] && ![istarget "nds32*-*-*"] } then {
 run_dump_test sleb128
 run_dump_test sleb128-2
 run_dump_test sleb128-3
-setup_xfail "nds32*-*-*"
 run_dump_test sleb128-4
 run_dump_test sleb128-5
 # .byte is not 8 bits on either tic4x or tic54x
 if { ![istarget "tic4x*-*-*"] && ![istarget "tic54x*-*-*"] } {
     run_dump_test sleb128-7
+    run_dump_test sleb128-8
 }
+run_dump_test sleb128-9
 
 # .byte is 32 bits on tic4x, and .p2align isn't supported on tic54x
 # .space is different on hppa*-hpux.
@@ -388,35 +421,20 @@ if { ![istarget "tic4x*-*-*"] && ![istarget "tic54x*-*-*"] && ![istarget "hppa*-
     run_dump_test relax
 }
 
-# powerpc and s390 allow a string argument to .byte
-if { ![istarget "powerpc*-*-*"] && ![istarget "rs6000*-*-*"] && ![istarget "s390*-*-*"] } {
-    run_dump_test byte
-}
+run_dump_test quad
 
-# .quad is 16 bytes on i960.
-if { ![istarget "i960-*-*"] } {
-    run_dump_test quad
-}
-
-# som doesn't use .data section.
-case $target_triplet in {
-    { hppa*64*-*-* } {
-       run_dump_test octa
-    }
-    { hppa*-*-hpux* } { }
-    default {
-       run_dump_test octa
-    }
+# poor little PDP-11 can't handle 16-byte values
+if { ![istarget "pdp11-*-*"] } {
+    run_dump_test octa
 }
 
 # .set works differently on some targets.
-case $target_triplet in {
-    { alpha*-*-* } { }
-    { mips*-*-* } { }
-    { *c54x*-*-* } { }
-    { z80-*-* } { }
+switch -glob $target_triplet {
+    alpha*-*-* { }
+    mips*-*-* { }
+    *c54x*-*-* { }
+    z80-*-* { }
     default {
-       setup_xfail "nds32*-*-*"
        run_dump_test weakref1
        run_dump_test weakref1g
        run_dump_test weakref1l
@@ -429,8 +447,50 @@ gas_test_error "weakref3.s" "" "a: would close weakref loop: a => b => c => d =>
 gas_test_error "weakref4.s" "" "is already defined"
 
 run_dump_test string
+if [is_elf_format] {
+    run_dump_test none
+}
+
+run_dump_test quoted-sym-names
+
+run_list_test pr20312
 
 load_lib gas-dg.exp
 dg-init
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/err-*.s $srcdir/$subdir/warn-*.s]] "" ""
 dg-finish
+
+# Set $nop_type appropriately to indicate the NOP instruction mnemonic.
+# Note - this code is made obsolete by the new .nops pseudo-op.
+switch -glob $target_triplet {
+    bpf-*-* {
+        set nop_type 6
+    }
+    mmix-*-* {
+       set nop_type 5
+    }
+    or1k*-*-* {
+       set nop_type 2
+    }
+    ia64-*-* {
+       set nop_type 1
+    }
+    default {
+       set nop_type 0
+    }
+}
+run_dump_test "org-1" [list [list as "--defsym nop_type=$nop_type"]]
+run_dump_test "org-2"
+run_dump_test "org-3"
+run_dump_test "org-4"
+run_dump_test "org-5"
+run_dump_test "org-6"
+
+run_dump_test "fill-1"
+
+gas_test "pr23938.s" "" "" ".xstabs"
+
+run_dump_test "nop"
+run_dump_test "asciz"
+run_dump_test "pr27384"
+run_dump_test "pr27381"