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

2

6

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?

Loveliesbleeding answered 24/11, 2012 at 22:27 Comment(0)
P
4

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.

Pelmas answered 24/11, 2012 at 22:33 Comment(0)
D
2

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.

Disulfiram answered 24/11, 2012 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.