Hi folks!
Is there a way, for a given function, to tell GCC NOT to inline any code
inside this function ?
I do not care about inlining the function itself [ie. this is not
related to __attribute__((noinline)) and/or the asm("") trick.]
elsewhere or not, I just want to ensure that the function will not have
calls inlined in it, because additional inlined variables on stack will
increase the total function stack frame size.
The reason behind is for recursive functions calling other functions on
terminal recursion calls: I have a function with a huge stackframe,
causing recursion to overflow, only for "leafs" terminal calls or
intermediate calls without recursion.
Ideally, I'd like my fonction to have only the return address on the
stack for each call, and the two or three arguments really used, not the
other inlined function's variables.
I can't seem to find any relevant attribute/buitin in the GCC manual for
that though.
Really trivial sample (do not try to understand the goal of the "foo"
functiopn, it does not have any):
gcc -DSTATIC_DISP test.c -o test.S -S -O
vs.
gcc test.c -o test-not-static.S -S -O
Without inlined function:
foo:
subq $8, %rsp .
...
With inlined function:
foo:
pushq %rbx
subq $48, %rsp ; outch my stack!
...
Sample code:
#ifdef STATIC_DISP
#define STATIC static
#else
#define STATIC
#endif
STATIC int disp(int c) {
char bar[32];
sprintf(bar, "%d", c);
sscanf(bar, "%d", &c);
return c;
}
extern int foo(int bar);
int foo(int bar) {
if (bar == 0) {
return 0;
}
bar = disp(bar);
if (bar % 2) {
int c = foo(bar / 2);
if (c % 2) {
return c;
} else {
return c*2;
}
} else {
int c = foo(bar / 2 - 1);
if (c % 2) {
return c;
} else {
return c*2;
}
}
}
If anyone has any suggestion or insights, please let me know.