From: John Darrington Date: Fri, 1 Feb 2019 16:42:54 +0000 (+0100) Subject: S12Z: GAS: Fix incorrect range test for 16-bit PC relative offsets. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=91bae99160e9d81cfe340b937f9613d43dc90293;p=binutils-gdb.git S12Z: GAS: Fix incorrect range test for 16-bit PC relative offsets. 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. --- diff --git a/gas/ChangeLog b/gas/ChangeLog index e168d7280ad..a02430dd167 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,13 @@ +2019-01-31 John Darrington + + * 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 * config/tc-s12z.c (tfr): Emit warning if operands are the same. diff --git a/gas/config/tc-s12z.c b/gas/config/tc-s12z.c index a0131490ba6..8b56b685b8e 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 00000000000..ae01a7fa638 --- /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 00000000000..e3d63c3c094 --- /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 00000000000..a79b4d62449 --- /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 00000000000..acc7e6301c9 --- /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 00000000000..f64d1975da5 --- /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 a6546d76ac3..d9746d3d919 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