When I've read the gcc documentation I assumed that the inline (or inline) keyword would remove the function call overhead.
As I qoute: " One way GCC can achieve this is to integrate that function's code into the code for its callers. This makes execution faster by eliminating the function-call overhead; in addition, if any of the actual argument values are constant, their known values may permit simplifications at compile time so that not all of the inline function's code needs to be included. " Gcc Manual 6.36
Thus I assumed that the following C code:
__inline__ int sum(int a, int b)
{
return a+b;
}
int add_one(int a)
{
return sum(a, 1);
}
would translate into
add_one:
mov eax, [ebp-4]
add eax, 0x01
retn
Instead of:
add_one:
push 0x01
push [ebp-4]
call sum
retn
As this doesn't work how I expected I would like to ask a question. I have an object file with a function. It exports the symbol _my_func. I got the C code with the following code:
extern __inline__ _my_func
int main(int argc, char **argv)
{
_my_func(argv[1]);
_my_func(argv[2]);
}
How can I merge my object's code within my main function. Eg remove the call and the function overhead.
Thanks
Stolas
btw, even here ( What does __inline__ mean ? ) I noticed that it should remove the function overhead. But objdump says otherwise :S
Post Update:
Even with the following commands:
nasm -felf get42.s -o42.o
gcc O3 42.o main.c -o mybin.elf
objdump -d mybin.elf
I notice a little call like so:
<_get42>:
xor eax, eax
mov eax, 0x42
ret
<main>:
push ebp
mov ebp, esp
add esp, 0xfffffff0
call _get42
leave
ret
btw I do notice it removed the (mov ebp, esp etc) overhead in the function. But is that all it does? As I just want to remove the call with the actual code within the function.. As in eliminate the call, jmp or push, ret.