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.
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
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
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
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
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.
Great - patch applied.