0

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.

Community
  • 1
  • 1
Stolas
  • 279
  • 1
  • 3
  • 19
  • What optimization settings are you using? – Mat Mar 25 '13 at 12:11
  • Default. Compiling with: nasm -f my_object -o someoutputobject.o gcc -Wall someoutputobject.o some_c_code.c -o output.bin – Stolas Mar 25 '13 at 12:32
  • What about telling GCC to do some optimizations? Like, at least, `-O1`? – Mat Mar 25 '13 at 12:34
  • Even with -o3 I see a little call being made. The -o3 can be found here http://pastebin.com/wxrfUJyd – Stolas Mar 25 '13 at 12:47
  • It's `-Ox`, not `-oX`. Please update your post with the info (can't access pastebin from here). – Mat Mar 25 '13 at 12:55
  • Quickly tried it, still a `call` in there. However I need to read the entire documentation. – Stolas Mar 25 '13 at 14:38
  • Looks like http://stackoverflow.com/questions/5987020/can-the-linker-inline-functions is what I am looking for indeed. Thanks, now I need to figure out how to make the *.o with NASM and still allow lto – Stolas Mar 25 '13 at 15:10

0 Answers0