Bug 22493 - push {sp} fails on mcpu=cortex-a7
Summary: push {sp} fails on mcpu=cortex-a7
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-25 13:58 UTC by bugzilla
Modified: 2017-12-18 09:40 UTC (History)
1 user (show)

See Also:
Host:
Target: cortex-a7
Build:
Last reconfirmed: 2017-12-08 00:00:00


Attachments
Proposed patch (355 bytes, patch)
2017-12-08 17:06 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description bugzilla 2017-11-25 13:58:53 UTC
The arm-none-eabi-as translates "push {sp}" wrong.
Instead of "stmfd sp!, {sp}" im getting "str sp, [sp, #-4]!".
This str is UNPREDICTABLE says ARMv7-A Refmanual (the cortex a7 throws an undefined).
Because it uses writeback and Rn == Rt.
Im referencing to this doc: http://liris.cnrs.fr/~mmrissa/lib/exe/fetch.php?media=armv7-a-r-manual.pdf (ARM DDI 0406C.b (ID072512))
Chapter A8.8.205, page 676.

And im not getting a warning!
If im typing "str sp, [sp, #-4]!" manually I get a warning.
Comment 1 Nick Clifton 2017-12-05 15:07:55 UTC
Hi Reporter,

  Please could you give me more details of how you generated this bug ?

  I tried the following test:

  % cat pr22493.s
	.text
	push {sp}

  % arm-none-eabi-as -march=armv7-a pr22493.s -o pr22493.o
  % arm-none-eabi-objdump -d pr22493.o
  Disassembly of section .text:

  00000000 <.text>:
     0:	e52dd004 	push	{sp}		; (str sp, [sp, #-4]!)

  So, the correct STMDB encoding is being used, although the disassembler does 
  have an incorrect comment describing the instruction.

Cheers
  Nick
Comment 2 bugzilla 2017-12-05 17:03:23 UTC
Hello,
of course I will give you more details.

At first "y52dxxxx" ist not stm it is str ;)
stm is "y92dxxxx".

Therefore I repeated your test but with two more instructions.
Now you can see the difference.

$ cat pr22493.s 
.text
label:
	stmfd sp!, {sp}
	push {sp}
	str sp, [sp, #-4]! //this line(5) is the warning!


$ arm-none-eabi-as -march=armv7-a pr22493.s -o pr22493.o
pr22493.s: Assembler messages:
pr22493.s:5: Warning: source register same as write-back base


$ ./arm-none-eabi-objdump -d pr22493.o
pr22493.o:     file format elf32-littlearm
Disassembly of section .text:

00000000 <label>:
   0:	e92d2000 	stmfd	sp!, {sp}
   4:	e52dd004 	push	{sp}		; (str sp, [sp, #-4]!)
   8:	e52dd004 	push	{sp}		; (str sp, [sp, #-4]!)


$ arm-none-eabi-as -v
GNU assembler version 2.29.1 (arm-none-eabi) using BFD version (GNU Binutils) 2.29.1
$ arm-none-eabi-objdump -v
GNU objdump (GNU Binutils) 2.29.1

Now the details HOW the bug was generated:
In our course the students have to write some exceptionhandlers and print all registers if an exception happens.
Therefore a student used push {sp} and nothing worked because his undef handler wasnt finished and the -as didnt throw a warning. 

Greetings
Martin
Comment 3 Nick Clifton 2017-12-08 17:06:30 UTC
Created attachment 10673 [details]
Proposed patch

Hi Martin,

  Thanks for the extended description of the problem, it certainly helped.

  Please could you try out this patch for me and let me know if it does
  what you need ?

Cheers
  Nick
Comment 4 bugzilla 2017-12-15 19:45:43 UTC
Hello Nick,
I patched my binutils with your patch and now it gets translated right.

Here is the evidence (same asm Code as in Comment 2):

$ arm-none-eabi-objdump -d pr22493.o
pr22493.o:     file format elf32-littlearm
Disassembly of section .text:
00000000 <label>:
   0:	e92d2000 	stmfd	sp!, {sp}
   4:	e92d2000 	stmfd	sp!, {sp}
   8:	e52dd004 	push	{sp}		; (str sp, [sp, #-4]!)

Greetings
Martin
Comment 5 Sourceware Commits 2017-12-18 09:39:25 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4f588891ac7d4653e1bd861ca38c2a4e6d5e907c

commit 4f588891ac7d4653e1bd861ca38c2a4e6d5e907c
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Dec 18 09:37:57 2017 +0000

    Resolve PR 22493 - the encoding to be used when pushing the stack pointer onto the stack.
    
    	PR 22493
    	* config/tc-arm.c (encode_ldmstm): Do not use A2 encoding of the
    	PUSH insn when pushing the stack pointer.
Comment 6 Nick Clifton 2017-12-18 09:40:24 UTC
Great - patch applied.