yacoutm
Newbie
I have an application which I compile using GCC v6.3, when I compile it with GCC v10.3 I find some functions use more stack size than what GCC v6.3 uses, for example this function uses zero stack for GCC v6.3 but uses 8 bytes for GCC v10.3
GCC v6.3 assembly:
and GCC v10.3 assembly:
In GCCv10.3, it push {r4, lr} which is not the case in GCC v6.3
so why does this happen?, it costs the application more stack area over the old compiler, so how to avoid it to get less stack size?
also, why did it stack the lr although it's a leaf function?
plus, why does it return z in all cases although the c code returns it inside the case condition?
Notes:
1. This function is a dummy one just to reproduce the issue, so don't consider rewriting it.
2. Building flags are:
arm-none-eabi-gcc -O0 -c -std=c99 -fmessage-length=0 -fomit-frame-pointer -Wno-aggressive-loop-optimizations -Werror -Werror=strict-prototypes -pedantic-errors -Wconversion -pedantic -Wall -Wextra -Wno-unused-function -Wextra -Wpointer-arith -Wsign-compare -Wswitch -Wno-maybe-uninitialized -fno-strict-aliasing -fshort-wchar -mfix-cortex-m3-ldrd -gdwarf-3 -gstrict-dwarf -mabi=aapcs -mthumb -mcpu=Cortex-M0 -g3 -Os -mthumb -ffunction-sections -fdata-sections -MMD -MP -MF"xyz.d" -MT"xyz.o"
C:
int func(int *x, int y, int z, int a)
{
switch (y) {
case 1:
*x = a;
y = z;
return y;
}
}
GCC v6.3 assembly:
Code:
int func(int *x, int y, int z, int a)
{
switch (y) {
0: 2901 cmp r1, #1
2: d101 bne.n 8 <func+0x8>
case 1:
*x = a;
4: 6003 str r3, [r0, #0]
y = z;
return y;
6: 0010 movs r0, r2
}
}
8: 4770 bx lr
and GCC v10.3 assembly:
Code:
int func(int *x, int y, int z, int a)
{
0: b510 push {r4, lr}
2: 0004 movs r4, r0
4: 0010 movs r0, r2
switch (y) {
6: 2901 cmp r1, #1
8: d100 bne.n c <func+0xc>
case 1:
*x = a;
a: 6023 str r3, [r4, #0]
y = z;
return y;
}
}
c: bd10 pop {r4, pc}
In GCCv10.3, it push {r4, lr} which is not the case in GCC v6.3
so why does this happen?, it costs the application more stack area over the old compiler, so how to avoid it to get less stack size?
also, why did it stack the lr although it's a leaf function?
plus, why does it return z in all cases although the c code returns it inside the case condition?
Notes:
1. This function is a dummy one just to reproduce the issue, so don't consider rewriting it.
2. Building flags are:
arm-none-eabi-gcc -O0 -c -std=c99 -fmessage-length=0 -fomit-frame-pointer -Wno-aggressive-loop-optimizations -Werror -Werror=strict-prototypes -pedantic-errors -Wconversion -pedantic -Wall -Wextra -Wno-unused-function -Wextra -Wpointer-arith -Wsign-compare -Wswitch -Wno-maybe-uninitialized -fno-strict-aliasing -fshort-wchar -mfix-cortex-m3-ldrd -gdwarf-3 -gstrict-dwarf -mabi=aapcs -mthumb -mcpu=Cortex-M0 -g3 -Os -mthumb -ffunction-sections -fdata-sections -MMD -MP -MF"xyz.d" -MT"xyz.o"