I have the following piece of code:
extern void func1(char *array);
extern void func2(char *array);
void myfunction(void) {
if (somecondition) {
char var2[256];
func2(var2);
}
if (someothercondition) {
{
char var3[3];
func3(var3);
}
}
I cannot get my compiler (gcc) to call func3
with only 3 bytes used for var3
in the stack. It always allocates the space for the var2
used in the scope for func2
call, even though this variable is out of scope and could have been safely removed from the stack.
I have tried several options that I found in the gcc documentation:
fomit-frame-pointer
fconserve-stack
I have tried this on both x86 and ARM architectures and it behaves identically.
The rationale behind this question is to use only the stack size that is necessary.
And the related question: if it is possible to optimize the stack space, is it possible to add the stack used for each sub-function call in the .su file generated by the option -fstack-usage
.
thanks