S12Z: GAS: Fix incorrect range test for 16-bit PC relative offsets.
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 1 Feb 2019 16:42:54 +0000 (17:42 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 1 Feb 2019 17:08:06 +0000 (18:08 +0100)
The limits for PC relative offsets were incorrect.  This change fixes
them and adds some tests.

gas/
* config/tc-s12z.c (md_apply_fix): Fix incorrect limits.
* testsuite/gas/s12z/pc-rel-bad.d: New file.
* testsuite/gas/s12z/pc-rel-bad.l: New file.
* testsuite/gas/s12z/pc-rel-bad.s: New file.
* testsuite/gas/s12z/pc-rel-good.d: New file.
* testsuite/gas/s12z/pc-rel-good.s: New file.
* testsuite/gas/s12z/s12z.exp: Add them.

gas/ChangeLog
gas/config/tc-s12z.c
gas/testsuite/gas/s12z/pc-rel-bad.d [new file with mode: 0644]
gas/testsuite/gas/s12z/pc-rel-bad.l [new file with mode: 0644]
gas/testsuite/gas/s12z/pc-rel-bad.s [new file with mode: 0644]
gas/testsuite/gas/s12z/pc-rel-good.d [new file with mode: 0644]
gas/testsuite/gas/s12z/pc-rel-good.s [new file with mode: 0644]
gas/testsuite/gas/s12z/s12z.exp

index e168d72..a02430d 100644 (file)
@@ -1,5 +1,15 @@
 2019-01-31  John Darrington <john@darrington.wattle.id.au>
 
+       * config/tc-s12z.c (md_apply_fix): Fix incorrect limits.
+       * testsuite/gas/s12z/pc-rel-bad.d: New file.
+       * testsuite/gas/s12z/pc-rel-bad.l: New file.
+       * testsuite/gas/s12z/pc-rel-bad.s: New file.
+       * testsuite/gas/s12z/pc-rel-good.d: New file.
+       * testsuite/gas/s12z/pc-rel-good.s: New file.
+       * testsuite/gas/s12z/s12z.exp: Add them.
+
+2019-01-31  John Darrington <john@darrington.wattle.id.au>
+
        * config/tc-s12z.c (tfr): Emit warning if operands are the same.
        * testsuite/gas/s12z/exg.d: New test case.
        * testsuite/gas/s12z/exg.l: New file.
index a013149..8b56b68 100644 (file)
@@ -3853,7 +3853,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
       bfd_putb32 ((bfd_vma) value, (unsigned char *) where);
       break;
     case BFD_RELOC_16_PCREL:
-      if (value < -0x8000 || value > 0x7FFF)
+      if (value < -0x4000 || value > 0x3FFF)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value out of 16-bit range."));
 
diff --git a/gas/testsuite/gas/s12z/pc-rel-bad.d b/gas/testsuite/gas/s12z/pc-rel-bad.d
new file mode 100644 (file)
index 0000000..ae01a7f
--- /dev/null
@@ -0,0 +1,9 @@
+#objdump: -d -r -t
+#name:    PC relative branches which are out of range.
+#source:  pc-rel-bad.s
+#error_output: pc-rel-bad.l
+
+.*:     file format elf32-s12z
+
+
+Disassembly of section .text:
diff --git a/gas/testsuite/gas/s12z/pc-rel-bad.l b/gas/testsuite/gas/s12z/pc-rel-bad.l
new file mode 100644 (file)
index 0000000..e3d63c3
--- /dev/null
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*:4: Error: Value out of 16-bit range.
+.*:8: Error: Value out of 16-bit range.
diff --git a/gas/testsuite/gas/s12z/pc-rel-bad.s b/gas/testsuite/gas/s12z/pc-rel-bad.s
new file mode 100644 (file)
index 0000000..a79b4d6
--- /dev/null
@@ -0,0 +1,8 @@
+
+;;; Both the BNE instructions should fail
+;;; because the destination is out of range.
+       bne .label
+       .fill 0x3FFD, 1, 0      ; 0x3FFF minus 3 (the length of the BNE insn)
+.label:
+       .fill 0x4001, 1, 0
+       bne .label
diff --git a/gas/testsuite/gas/s12z/pc-rel-good.d b/gas/testsuite/gas/s12z/pc-rel-good.d
new file mode 100644 (file)
index 0000000..acc7e63
--- /dev/null
@@ -0,0 +1,24 @@
+#objdump: -d -r -t
+#name:    PC relative branches (close to the limit)
+#source:  pc-rel-good.s
+
+
+.*:     file format elf32-s12z
+
+SYMBOL TABLE:
+00000000 l    d  .text 00000000 .text
+00000000 l    d  .data 00000000 .data
+00000000 l    d  .bss  00000000 .bss
+00003fff l       .text 00000000 .label
+
+
+
+Disassembly of section .text:
+
+00000000 <.label-0x3fff>:
+       0:      26 bf ff        bne .label
+       ...
+
+00003fff <.label>:
+       ...
+    7fff:      26 c0 00        bne .label
diff --git a/gas/testsuite/gas/s12z/pc-rel-good.s b/gas/testsuite/gas/s12z/pc-rel-good.s
new file mode 100644 (file)
index 0000000..f64d197
--- /dev/null
@@ -0,0 +1,6 @@
+
+       bne .label
+       .fill 0x3FFC, 1, 0
+.label:
+       .fill 0x4000, 1, 0
+       bne .label
index a6546d7..d9746d3 100644 (file)
@@ -90,6 +90,8 @@ run_dump_test opr-idx3-reg
 run_dump_test opr-idx3-xysp-24
 run_dump_test or-imm
 run_dump_test or-opr
+run_dump_test pc-rel-bad
+run_dump_test pc-rel-good
 run_dump_test page2-inh
 run_dump_test psh-pul
 run_dump_test qmul