This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, ARM] Fix invalid immediate constant acceptance for carry-setting addw,subw.


Hi,

Widening carry-setting thumb2 add and sub accepted invalid immediates
which were flat 12-bit encoded. ADDS.W and SUBS.W's immediates have to
be modified immediate constants(unlike addw and subw). Attached is a
patch that adds this check and fixes it in gas. Regression tested on
arm-none-eabi.

OK?

--
Tejas Belagod
ARM.

gas/testsuite/

2010-08-23 Tejas Belagod <tejas.belagod@arm.com>

	* gas/arm/addsw-bad.s: New file.
	* gas/arm/addsw-bad.l: New file.
	* gas/arm/addsw-bad.d: New file.

gas/

2010-08-23 Tejas Belagod <tejas.belagod@arm.com>

	* config/tc-arm.c (md_apply_fix): Check if widened add, sub are
	flag-setting and handle accordingly.
Index: gas/config/tc-arm.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.c,v
retrieving revision 1.452
diff -u -p -r1.452 tc-arm.c
--- gas/config/tc-arm.c	8 Jul 2010 22:40:26 -0000	1.452
+++ gas/config/tc-arm.c	23 Aug 2010 16:24:09 -0000
@@ -20218,17 +20218,20 @@ md_apply_fix (fixS *	fixP,
 	  /* Turn add/sum into addw/subw.  */
 	  if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
 	    newval = (newval & 0xfeffffff) | 0x02000000;
-
-	  /* 12 bit immediate for addw/subw.  */
-	  if (value < 0)
+	  /* No flat 12-bit imm encoding for addsw/subsw.  */
+	  if ((newval & 0x00100000) == 0)
 	    {
-	      value = -value;
-	      newval ^= 0x00a00000;
+	      /* 12 bit immediate for addw/subw.  */
+	      if (value < 0)
+		{
+		  value = -value;
+		  newval ^= 0x00a00000;
+		}
+	      if (value > 0xfff)
+		newimm = (unsigned int) FAIL;
+	      else
+		newimm = value;
 	    }
-	  if (value > 0xfff)
-	    newimm = (unsigned int) FAIL;
-	  else
-	    newimm = value;
 	}
 
       if (newimm == (unsigned int)FAIL)
Index: gas/testsuite/gas/arm/addsw-bad.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/arm/addsw-bad.d
--- /dev/null	2010-06-14 17:20:13.293370595 +0100
+++ gas/testsuite/gas/arm/addsw-bad.d	2010-08-23 17:01:11.168099000 +0100
@@ -0,0 +1,3 @@
+#name: Invalid Immediate field for flag-setting add,sub
+#skip: *-*-*coff *-*-pe *-*-wince *-*-*aout* *-*-netbsd
+#error-output: addsw-bad.l
Index: gas/testsuite/gas/arm/addsw-bad.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/arm/addsw-bad.s
--- /dev/null	2010-06-14 17:20:13.293370595 +0100
+++ gas/testsuite/gas/arm/addsw-bad.s	2010-08-23 17:06:20.805577000 +0100
@@ -0,0 +1,7 @@
+.text
+.thumb
+.cpu cortex-a8
+.syntax unified
+subs r4, r6, #0x496
+adds r4, r6, #0x496
Index: gas/testsuite/gas/arm/addsw-bad.l
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/arm/addsw-bad.l
--- /dev/null	2010-06-14 17:20:13.293370595 +0100
+++ gas/testsuite/gas/arm/addsw-bad.l	2010-08-23 17:17:43.538736000 +0100
@@ -0,0 +1,3 @@
+[^:]*: Assembler messages:
+[^:]*:5: Error: invalid constant \(496\) after fixup
+[^:]*:6: Error: invalid constant \(496\) after fixup

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]