Arm Community
Site
Search
User
Site
Search
User
Support forums
Arm Development Studio forum
ARM Compiler creates a bug in code - how to fix?
Jump...
Cancel
Locked
Locked
Replies
10 replies
Subscribers
119 subscribers
Views
7563 views
Users
0 members are here
Options
Share
More actions
Cancel
Related
How was your experience today?
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion
ARM Compiler creates a bug in code - how to fix?
AlexRast
over 12 years ago
Note: This was originally posted on 17th September 2009 at
http://forums.arm.com
I wouldn't have thought ARMCC could create an explicit bug, but it seems here it is.
In this case, what it's doing is placing an item on the stack in a position which will certainly corrupt the stack.
Looking through the disassembly for the offending function, I can see that the first line (as expected) is
PUSH {r2-r4,r6-r11,lr}
But then later in the code, and with NO other stack operations in the meanwhile (nor any function calls or other branches out of the current function context) it has
ADD r2,r0,r4,LSL #2
LDR r0,|L1.3728|
STR r2,[sp,#4]
As I understand it, since the stack is full-descending, this means that the value of r2 currently in the stack will get corrupted, because the STR instruction will store the (changed) current r2 value in the position occupied by the original r2. The function in concern is declared
void receivePacket(void)
so it's not expecting to return values in r2 or take arguments in r2.
Why would armcc do something so glaringly illegal? Is there something I can do to fix this?
As an aside, I'll mention that this bad stacking is actually occuring in the setup for a subroutine call, that happens a few lines lower down. The routine in concern uses r1, r2 and r3 for its arguments and returns in r0 and r1. As it happens, the value that it's stacking from r2 is actually the address that will take the return value in r0 - really, what the compiler *should* do, I think, is place the address in some register rx (x > 3) then do an STR r0, [rx, #0] on return.
Parents
Simon Craske
over 12 years ago
Note: This was originally posted on 18th September 2009 at
http://forums.arm.com
Paraphrasing Isogen,
Your function is using a shed load of registers, plus two words of stack;
the PUSH provides the space for the two words of stack space without
the need for an addition "SUB SP"; presumably your code is optimised
to reduce code size, rather than execution time.
hth
s.
Cancel
Vote up
0
Vote down
Cancel
Reply
Simon Craske
over 12 years ago
Note: This was originally posted on 18th September 2009 at
http://forums.arm.com
Paraphrasing Isogen,
Your function is using a shed load of registers, plus two words of stack;
the PUSH provides the space for the two words of stack space without
the need for an addition "SUB SP"; presumably your code is optimised
to reduce code size, rather than execution time.
hth
s.
Cancel
Vote up
0
Vote down
Cancel
Children
No data