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] Make ARM GAS accept valid STR instruction


`str r0,[pc,#4]' is a valid instruction although the use of PC is deprecated. But currently GAS rejects this instruction. This patch should fix it. Tested using GAS testsuite for arm-none-eabi target. Is it OK?


Regards, -- Jie Zhang CodeSourcery
	* config/tc-arm.c (encode_arm_addr_mode_2): Fix
	BAD_PC_ADDRESSING condition.

	testsuite/
	* gas/arm/ldst-pc.d: New test.
	* gas/arm/ldst-pc.s: New test.
	* gas/arm/sp-pc-validations-bad.s: `str r0,[pc,#4]' is valid
	except that the use of PC is deprecated.
	* gas/arm/sp-pc-validations-bad.l: Adjust accordingly.

Index: 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
--- config/tc-arm.c	8 Jul 2010 22:40:26 -0000	1.452
+++ config/tc-arm.c	18 Aug 2010 03:29:45 -0000
@@ -6819,11 +6819,15 @@ encode_arm_addr_mode_2 (int i, bfd_boole
       if (is_pc && !inst.reloc.pc_rel)
 	{
 	  const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
-	  /* BAD_PC_ADDRESSING Condition =
-	       is_load => is_t
-	     which becomes !is_load || is_t.  */
-	  constraint ((!is_load || is_t),
+
+	  /* If is_t is TRUE, it's called from do_ldstt.  ldrt/strt
+	     cannot use PC in addressing.
+	     PC cannot be used in writeback addressing, either.  */
+	  constraint ((is_t || inst.operands[i].writeback),
 		      BAD_PC_ADDRESSING);
+
+	  if (!is_load)
+	    as_warn (_("use of PC in this instruction is deprecated"));
 	}
 
       if (inst.reloc.type == BFD_RELOC_UNUSED)
Index: testsuite/gas/arm/ldst-pc.d
===================================================================
RCS file: testsuite/gas/arm/ldst-pc.d
diff -N testsuite/gas/arm/ldst-pc.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/arm/ldst-pc.d	18 Aug 2010 03:29:45 -0000
@@ -0,0 +1,15 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: ARM load/store with pc base register
+#as:
+
+# Test the standard ARM instructions:
+
+.*: +file format .*arm.*
+
+Disassembly of section .text:
+0+000 <[^>]*> e51f1008 	ldr	r1, \[pc, #-8\]	; 0+000 <[^>]*>
+0+004 <[^>]*> e79f1002 	ldr	r1, \[pc, r2\]
+0+008 <[^>]*> f55ff008 	pld	\[pc, #-8\]	; 0+008 <[^>]*>
+0+00c <[^>]*> f7dff001 	pld	\[pc, r1\]
+0+010 <[^>]*> f45ff008 	pli	\[pc, #-8\]	; 0+010 <[^>]*>
+0+014 <[^>]*> f6dff001 	pli	\[pc, r1\]
Index: testsuite/gas/arm/ldst-pc.s
===================================================================
RCS file: testsuite/gas/arm/ldst-pc.s
diff -N testsuite/gas/arm/ldst-pc.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/arm/ldst-pc.s	18 Aug 2010 03:29:45 -0000
@@ -0,0 +1,13 @@
+@	Test file for ARM load/store instructions with pc as the base register
+
+	.text
+	.syntax unified
+	.align 2
+	ldr r1, [pc, #-8]
+	ldr r1, [pc, r2]
+
+	pld [pc, #-8]
+	pld [pc, r1]
+
+	pli [pc, #-8]
+	pli [pc, r1]
Index: testsuite/gas/arm/sp-pc-validations-bad.l
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/arm/sp-pc-validations-bad.l,v
retrieving revision 1.1
diff -u -p -r1.1 sp-pc-validations-bad.l
--- testsuite/gas/arm/sp-pc-validations-bad.l	12 Feb 2010 20:15:13 -0000	1.1
+++ testsuite/gas/arm/sp-pc-validations-bad.l	18 Aug 2010 03:29:45 -0000
@@ -101,7 +101,7 @@
 [^:]*:158: Error: r15 not allowed here -- `ldrt pc,\[r0\],r1,LSL#4'
 [^:]*:159: Error: cannot use register index with PC-relative addressing -- `ldrt r0,\[pc\],r1,LSL#4'
 [^:]*:160: Error: cannot use register index with PC-relative addressing -- `ldrt r0,\[r1\],pc,LSL#4'
-[^:]*:165: Error: cannot use register index with PC-relative addressing -- `str r0,\[pc,#4\]'
+[^:]*:165: Warning: use of PC in this instruction is deprecated
 [^:]*:166: Error: cannot use register index with PC-relative addressing -- `str r0,\[pc\],#4'
 [^:]*:167: Error: cannot use register index with PC-relative addressing -- `str r0,\[pc,#4\]!'
 [^:]*:170: Error: cannot use register index with PC-relative addressing -- `str r0,\[r1,pc,LSL#4\]'
Index: testsuite/gas/arm/sp-pc-validations-bad.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/arm/sp-pc-validations-bad.s,v
retrieving revision 1.1
diff -u -p -r1.1 sp-pc-validations-bad.s
--- testsuite/gas/arm/sp-pc-validations-bad.s	12 Feb 2010 20:15:13 -0000	1.1
+++ testsuite/gas/arm/sp-pc-validations-bad.s	18 Aug 2010 03:29:45 -0000
@@ -162,8 +162,8 @@ ldrt r0,[r1],pc, LSL #4			@ ditto
 @ Stores, ARM ================================================================
 
 @ STR (immediate, ARM)
-str r0,[pc,#4]				@ Unpredictable
-str r0,[pc],#4				@ ditto
+str r0,[pc,#4]				@ Deprecated
+str r0,[pc],#4				@ Unpredictable
 str r0,[pc,#4]!				@ ditto
 
 @ STR (register)

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