JMP间接性的意义何在

What is the point of JMP indirection

本文关键字:间接性 JMP      更新时间:2023-10-16

我发现,当我在调试模式下使用VS2010编译C/C++程序时(我没有检查过其他编译器),当我查看反汇编时,所有函数调用,无论是库函数、我自己的函数、类成员函数等,都有一个两步调用。实际的函数调用被转换为call指令,地址为a。当我转到地址A时,我看到它是jmp指令的某种大列表,每个指令都指向不同的函数。它的一小部分可能看起来像这个

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) 

这些jmp指令依次进入实际的函数体。只有在"调试"模式下编译时才会出现这种情况。在Release中,函数调用被编译为对函数体的直接调用。

这个间接函数调用有什么意义?

以下是@RaptorFactor:的答案

这是由"增量链接"引起的。如果你在编译器/链接器设置中禁用了它,跳转就会消失。

http://msdn.microsoft.com/en-us/library/4khtbfyf(VS.80).aspx