I was looking at a program in IDA as i was trying to figure out how a certain function worked, when I came across something like this:
; C_TestClass::Foo(void)
__text:00000000 __ZN14C_TestClass7FooEv proc near
__text:00000000 jmp __ZN14C_TestClass20Barr ; C_TestClass::Barr(void)
__text:00000000 __ZN14C_TestClass7FooEv endp
__text:00000000
Can anyone explain to me what exactly jumping to a function would do in a case like this? I am guessing that it acts as a wrapper for the other function?
You are correct that jumping is often a way to efficiently handle wrapper functions that aren't inlined.
Normally, you'd have to read all the function parameters and push them back onto the stack before you can call the sub-function.
But when the wrapper function has the exact same prototype:
there's no need for all the usual function calling overhead. You can just jump directly to the target. (These categories may not be entirely necessary, as it may still be possible in some other cases.)
All the parameters (either on the stack or register) that were setup when calling the wrapper function will already be in place (and compatible) for the sub-function.
This is what's known as a tail-call. The compiler is able to invoke the function directly and let it return to the original caller without causing any problems. For example:
int f(int x)
{
...
return g(y);
}
The compiler can simply jmp g
at the end because there is room for the arguments in the same place as f
's arguments and the return value is not modified before returning to f
's caller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With