I found that when I compile my C/C++ programs with VS2010 (I haven't checked other compilers) in Debug mode, when I look at the disassembly, all function calls, whether to library functions, my own functions, class member functions etc. all have a 2-step call. The actual function call is translated to a call
instruction to an address, A. When I go to address A, I see it is some kind of large list of jmp
instructions, each to a different function. A (small) part of it might look like this
fooFunc:
08CB1776 jmp fooFunc (8D11F60h)
barFunc:
08CB177B jmp barFunc (8D25240h)
std::allocator<unsigned int>::max_size:
08CB1780 jmp std::allocator<unsigned int>::max_size (8CE3D00h)
std::_Copy_backward_opt<int *,int *>:
08CB1785 jmp std::_Copy_backward_opt<int *,int *> (8D325D0h)
std::_Checked_base<int *>:
08CB178A jmp std::_Checked_base<int *> (8D32360h)
@ILT+1950(_foobarFunc):
08CB17A3 jmp foobarFunc (8F31450h)
@ILT+1955(_anotherFunc):
08CB17A8 jmp anotherFunc (8E4BD20h)
std::vector<unsigned short,std::allocator<unsigned short> >::capacity:
08CB17B2 jmp std::vector<unsigned short,std::allocator<unsigned short> >::capacity (8D8AAF0h)
yetAnother:
08CB17B7 jmp yetAnother (8D18630h)
@ILT+1975(_f):
08CB17BC jmp f (8E4FC50h)
std::_Debug_range<char *>:
08CB17C6 jmp std::_Debug_range<char *> (8D32480h)
std::_Vector_const_iterator<MyClass *,std::allocator<MyClass *> >::operator+=:
08CB17CB jmp std::_Vector_const_iterator<MyClass *,std::allocator<MyClass *> >::operator+= (8D64C80h)
These jmp
instructions in turn go to the actual function bodies. This is only when compiling in Debug mode. In Release, the function calls are compiled into direct calls to the function body.
What is the point of this indirect function calling?