【发布时间】:2013-12-02 13:22:47
【问题描述】:
发现当我在Debug模式下用VS2010编译我的C/C++程序(我没有检查其他编译器)时,反汇编的时候,所有的函数调用,是否到库函数,我自己的函数,类成员函数等都有一个两步调用。实际的函数调用被转换为指向地址A 的call 指令。当我转到地址 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 中,函数调用被编译成对函数体的直接调用。
这个间接函数调用的意义何在?
【问题讨论】:
-
也许对stackoverflow.com/questions/10859188/… 有一些见解,虽然我不确定它是否完全重复。
标签: c++ assembly compiler-construction compiler-optimization