



Different calling prolog of C between gcc-3.4.4 and gcc-4.9.2
by Kuoping on Apr 23, 2015 |
Kuoping
Posts: 41 Joined: Mar 27, 2009 Last seen: May 25, 2021 |
||
I use the FreeRTOS as my SOC embedded RTOS. When I use the different gcc compiler to build the sources, I get following code.
compiled by gcc-4.9.2
00002000 :
2000: d7 e1 17 f8 l.sw -8(r1),r2
2004: d7 e1 4f fc l.sw -4(r1),r9
2008: d7 e1 0f f4 l.sw -12(r1),r1
200c: 9c 21 ff f4 l.addi r1, r1, -12
2010: 07 ff ff 90 l.jal xxx
compiled by gcc-3.4.4
00002000 :
2000: 9c 21 ff f4 l.addi r1, r1, -12
2004: d4 01 10 04 l.sw 0x4(r1),r2
2008: 9c 41 00 0c l.addi r2,r1,0xc
200c: d4 01 48 00 l.sw 0x0(r1),r9
2010: d4 01 50 08 l.sw 0x8(r1),r10
2014: 07 ff ff 98 l.jal xxx
I have some question about the calling prolog by these two versions of compiler.
On gcc-4.9.2, it uses the stack before it allocates the stack space.
On gcc-3.4.4, it allocates stack space then uses it.
For gcc-4.9.2, if the interrupt exception happens on address 0x2000~0x2008, the ISR may overwrite the contain of stack. Does it make sense?
On the official porting of FreeRTOS on OpenRISC, it allocate extra stack space 'REDZONE_SIZE' to prevent overwrite the stack. The code is at,
freerots-6.1.1/Source/portable/GCC/OpenRISC/portmacro.h
#define REDZONE_SIZE (128)
#define CONTEXT_SIZE (128)
#define STACKFRAME_SIZE (CONTEXT_SIZE + REDZONE_SIZE)
Does it have any of reason to design as it?
|
RE: Different calling prolog of C between gcc-3.4.4 and gcc-4.9.2
by Kuoping on Apr 23, 2015 |
Kuoping
Posts: 41 Joined: Mar 27, 2009 Last seen: May 25, 2021 |
||
I use the FreeRTOS as my SOC embedded RTOS. When I use the different gcc compiler to build the sources, I get following code.
compiled by gcc-4.9.2 00002000: 2000: d7 e1 17 f8 l.sw -8(r1),r2 2004: d7 e1 4f fc l.sw -4(r1),r9 2008: d7 e1 0f f4 l.sw -12(r1),r1 200c: 9c 21 ff f4 l.addi r1, r1, -12 2010: 07 ff ff 90 l.jal xxx compiled by gcc-3.4.4 00002000: 2000: 9c 21 ff f4 l.addi r1, r1, -12 2004: d4 01 10 04 l.sw 0x4(r1),r2 2008: 9c 41 00 0c l.addi r2,r1,0xc 200c: d4 01 48 00 l.sw 0x0(r1),r9 2010: d4 01 50 08 l.sw 0x8(r1),r10 2014: 07 ff ff 98 l.jal xxx I have some question about the calling prolog by these two versions of compiler. On gcc-4.9.2, it uses the stack before it allocates the stack space. On gcc-3.4.4, it allocates stack space then uses it. For gcc-4.9.2, if the interrupt exception happens on address 0x2000~0x2008, the ISR may overwrite the contain of stack. Does it make sense? On the official porting of FreeRTOS on OpenRISC, it allocate extra stack space 'REDZONE_SIZE' to prevent overwrite the stack. The code is at, freerots-6.1.1/Source/portable/GCC/OpenRISC/portmacro.h #define REDZONE_SIZE (128) #define CONTEXT_SIZE (128) #define STACKFRAME_SIZE (CONTEXT_SIZE + REDZONE_SIZE) Does it have any of reason to design as it? |
RE: Different calling prolog of C between gcc-3.4.4 and gcc-4.9.2
by jeremybennett on May 14, 2015 |
jeremybennett
Posts: 815 Joined: May 29, 2008 Last seen: Jun 13, 2019 |
||
Hi Kuoping,
GCC 3.4.4 is ancient - don't trust it. The earliest fully reliable GCC for OpenRISC is 4.5.1 (we fixed it as a commercial project, so it could we used by NASA for TechEdSat). GCC 4.9 is based on the 4.5.1 work. Red zones are an optimization. If there is a place where it is getting it wrong, then please file a bug on GitHub, with a test case. HTH, Jeremy |



