public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@imgtec.com>
To: <binutils@sourceware.org>
Subject: [committed] MIPS/GAS: Correct BFD_RELOC_MIPS16_16_PCREL_S1 fixup size
Date: Tue, 25 Apr 2017 11:00:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.00.1704251002370.25796@tp.orcam.me.uk> (raw)

Correct the size of a BFD_RELOC_MIPS16_16_PCREL_S1 fixup made in 
`md_convert_frag', fixing a bug introduced with commit c9775dde3277 
("MIPS16: Add R_MIPS16_PC16_S1 branch relocation support)".  Add test 
cases to verify that the overflow of this fixup's in-place addend is 
still correctly detected.

	gas/
	* config/tc-mips.c (md_convert_frag): Correct 
	BFD_RELOC_MIPS16_16_PCREL_S1 fixup size.
	* testsuite/gas/mips/mips16-branch-addend-4.d: New test.
	* testsuite/gas/mips/mips16-branch-addend-5.d: New test.
	* testsuite/gas/mips/mips16-branch-addend-5.l: New stderr 
	output.
	* testsuite/gas/mips/mips16-branch-addend-4.s: New test source.
	* testsuite/gas/mips/mips16-branch-addend-5.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.
---
binutils-mips16-gas-r-mips16-pc16-size.diff
Index: binutils/gas/config/tc-mips.c
===================================================================
--- binutils.orig/gas/config/tc-mips.c	2017-04-24 20:04:15.162961844 +0100
+++ binutils/gas/config/tc-mips.c	2017-04-24 21:36:34.426492279 +0100
@@ -18445,15 +18445,11 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNU
 	      exp.X_add_symbol = fragp->fr_symbol;
 	      exp.X_add_number = fragp->fr_offset;
 
-	      fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp,
+	      fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp,
 				  TRUE, reloc);
 
 	      fixp->fx_file = fragp->fr_file;
 	      fixp->fx_line = fragp->fr_line;
-
-	      /* These relocations can have an addend that won't fit
-		 in 2 octets.  */
-	      fixp->fx_no_overflow = 1;
 	    }
 	  else
 	    as_bad_where (fragp->fr_file, fragp->fr_line,
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp	2017-04-24 23:28:01.167061456 +0100
+++ binutils/gas/testsuite/gas/mips/mips.exp	2017-04-24 23:28:04.181501054 +0100
@@ -1552,6 +1552,8 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "mips16-branch-addend-1"
     run_dump_test "mips16-branch-addend-2"
     run_dump_test "mips16-branch-addend-3"
+    run_dump_test "mips16-branch-addend-4"
+    run_dump_test "mips16-branch-addend-5"
     run_dump_test "mips16-branch-absolute"
     run_dump_test "mips16-branch-absolute-addend"
     if $has_newabi {
Index: binutils/gas/testsuite/gas/mips/mips16-branch-addend-4.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-addend-4.d	2017-04-24 23:28:04.191553533 +0100
@@ -0,0 +1,30 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 branch relocation with addend 4
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f7ef 101f 	b	00011002 <foo\+0x10002>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ef 601f 	bteqz	00011006 <foo\+0x10006>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ef 611f 	btnez	0001100a <foo\+0x1000a>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ef 221f 	beqz	v0,0001100e <foo\+0x1000e>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ef 2a1f 	bnez	v0,00011012 <foo\+0x10012>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f010 1000 	b	ffff1018 <foo\+0xffff0018>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f010 6000 	bteqz	ffff101c <foo\+0xffff001c>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f010 6100 	btnez	ffff1020 <foo\+0xffff0020>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f010 2200 	beqz	v0,ffff1024 <foo\+0xffff0024>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f010 2a00 	bnez	v0,ffff1028 <foo\+0xffff0028>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-addend-4.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-addend-4.s	2017-04-24 23:28:04.206688368 +0100
@@ -0,0 +1,24 @@
+	.text
+
+	.space	0x1000
+
+	.ent	foo
+	.set	mips16
+foo:
+	b	bar + 4 + (0x7fff << 1)
+	bteqz	bar + 4 + (0x7fff << 1)
+	btnez	bar + 4 + (0x7fff << 1)
+	beqz	$2, bar + 4 + (0x7fff << 1)
+	bnez	$2, bar + 4 + (0x7fff << 1)
+	b	bar + 4 - (0x8000 << 1)
+	bteqz	bar + 4 - (0x8000 << 1)
+	btnez	bar + 4 - (0x8000 << 1)
+	beqz	$2, bar + 4 - (0x8000 << 1)
+	bnez	$2, bar + 4 - (0x8000 << 1)
+	nop
+	.set	nomips16
+	.end	foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16
Index: binutils/gas/testsuite/gas/mips/mips16-branch-addend-5.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-addend-5.d	2017-04-24 23:28:04.224852644 +0100
@@ -0,0 +1,4 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 branch relocation with addend 5
+#as: -32
+#error-output: mips16-branch-addend-5.l
Index: binutils/gas/testsuite/gas/mips/mips16-branch-addend-5.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-addend-5.l	2017-04-24 23:28:04.234983124 +0100
@@ -0,0 +1,11 @@
+.*: Assembler messages:
+.*:8: Error: relocation overflow
+.*:9: Error: relocation overflow
+.*:10: Error: relocation overflow
+.*:11: Error: relocation overflow
+.*:12: Error: relocation overflow
+.*:13: Error: relocation overflow
+.*:14: Error: relocation overflow
+.*:15: Error: relocation overflow
+.*:16: Error: relocation overflow
+.*:17: Error: relocation overflow
Index: binutils/gas/testsuite/gas/mips/mips16-branch-addend-5.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-addend-5.s	2017-04-24 23:28:04.320468378 +0100
@@ -0,0 +1,24 @@
+	.text
+
+	.space	0x1000
+
+	.ent	foo
+	.set	mips16
+foo:
+	b	bar + 4 + (0x8000 << 1)
+	bteqz	bar + 4 + (0x8000 << 1)
+	btnez	bar + 4 + (0x8000 << 1)
+	beqz	$2, bar + 4 + (0x8000 << 1)
+	bnez	$2, bar + 4 + (0x8000 << 1)
+	b	bar + 4 - (0x8001 << 1)
+	bteqz	bar + 4 - (0x8001 << 1)
+	btnez	bar + 4 - (0x8001 << 1)
+	beqz	$2, bar + 4 - (0x8001 << 1)
+	bnez	$2, bar + 4 - (0x8001 << 1)
+	nop
+	.set	nomips16
+	.end	foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16

                 reply	other threads:[~2017-04-25 11:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.00.1704251002370.25796@tp.orcam.me.uk \
    --to=macro@imgtec.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).