Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the effect of using JMP on a function address?

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?

like image 625
ILOVEPIE Avatar asked Nov 24 '12 22:11

ILOVEPIE


2 Answers

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:

  1. Same calling convention
  2. Same parameters (and in the same order)
  3. Same return type

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.

like image 103
Mysticial Avatar answered Nov 03 '22 12:11

Mysticial


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.

like image 33
Ben Jackson Avatar answered Nov 03 '22 13:11

Ben Jackson