[3/4] S12Z: GAS: Fix incorrect range test for 16-bit PC relative offsets.

Message ID 20190131180442.31410-3-john@darrington.wattle.id.au
State New
Headers show
Series
  • [1/4] S12Z: GAS: Disallow immediate destination operands
Related show

Commit Message

John Darrington Jan. 31, 2019, 6:04 p.m.
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/config/tc-s12z.c                 |  2 +-
 gas/testsuite/gas/s12z/pc-rel-bad.d  |  9 +++++++++
 gas/testsuite/gas/s12z/pc-rel-bad.l  |  3 +++
 gas/testsuite/gas/s12z/pc-rel-bad.s  |  8 ++++++++
 gas/testsuite/gas/s12z/pc-rel-good.d | 24 ++++++++++++++++++++++++
 gas/testsuite/gas/s12z/pc-rel-good.s |  6 ++++++
 gas/testsuite/gas/s12z/s12z.exp      |  2 ++
 7 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 gas/testsuite/gas/s12z/pc-rel-bad.d
 create mode 100644 gas/testsuite/gas/s12z/pc-rel-bad.l
 create mode 100644 gas/testsuite/gas/s12z/pc-rel-bad.s
 create mode 100644 gas/testsuite/gas/s12z/pc-rel-good.d
 create mode 100644 gas/testsuite/gas/s12z/pc-rel-good.s

-- 
2.11.0

Comments

Nick Clifton Feb. 1, 2019, 10:51 a.m. | #1
Hi John,

> 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.


Approved - please apply.

Cheers
  Nick

Patch

diff --git a/gas/config/tc-s12z.c b/gas/config/tc-s12z.c
index a0131490ba..8b56b685b8 100644
--- a/gas/config/tc-s12z.c
+++ b/gas/config/tc-s12z.c
@@ -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
index 0000000000..ae01a7fa63
--- /dev/null
+++ b/gas/testsuite/gas/s12z/pc-rel-bad.d
@@ -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
index 0000000000..e3d63c3c09
--- /dev/null
+++ b/gas/testsuite/gas/s12z/pc-rel-bad.l
@@ -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
index 0000000000..a79b4d6244
--- /dev/null
+++ b/gas/testsuite/gas/s12z/pc-rel-bad.s
@@ -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
index 0000000000..acc7e6301c
--- /dev/null
+++ b/gas/testsuite/gas/s12z/pc-rel-good.d
@@ -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
index 0000000000..f64d1975da
--- /dev/null
+++ b/gas/testsuite/gas/s12z/pc-rel-good.s
@@ -0,0 +1,6 @@ 
+
+	bne .label
+	.fill 0x3FFC, 1, 0
+.label:
+	.fill 0x4000, 1, 0
+	bne .label
diff --git a/gas/testsuite/gas/s12z/s12z.exp b/gas/testsuite/gas/s12z/s12z.exp
index a6546d76ac..d9746d3d91 100644
--- a/gas/testsuite/gas/s12z/s12z.exp
+++ b/gas/testsuite/gas/s12z/s12z.exp
@@ -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