2010-03-31 229 views
2

我有一些C++代码“呼叫” 指令

#include <cstdio> 
#include <boost/bind.hpp> 
#include <boost/function.hpp> 

class A { 
public: 
    void do_it() { std::printf("aaa"); } 
}; 

void 
call_it(const boost::function<void()> &f) 
{ 
    f(); 
} 

void 
func() 
{ 
    A *a = new A; 
    call_it(boost::bind(&A::do_it, a)); 
} 

其中GCC 4编译成以下组件(从objdump):

00000030 <func()>: 
    30: 55      push %ebp 
    31: 89 e5     mov %esp,%ebp 
    33: 56      push %esi 
    34: 31 f6     xor %esi,%esi 
    36: 53      push %ebx 
    37: bb 00 00 00 00   mov $0x0,%ebx 
    3c: 83 ec 40    sub $0x40,%esp 
    3f: c7 04 24 01 00 00 00 movl $0x1,(%esp) 
    46: e8 fc ff ff ff   call 47 <func()+0x17> 
    4b: 8d 55 ec    lea 0xffffffec(%ebp),%edx 
    4e: 89 14 24    mov %edx,(%esp) 
    51: 89 5c 24 04    mov %ebx,0x4(%esp) 
    55: 89 74 24 08    mov %esi,0x8(%esp) 
    59: 89 44 24 0c    mov %eax,0xc(%esp) 
    ; the rest of the function is omitted 

我无法理解这里指令call的操作数,它为什么会自己调用,但是关闭一个字节?

+2

我们可以看到C++代码吗? – 2010-03-31 06:08:45

+0

@Andreas Brinck,更新。 – 2010-03-31 06:24:18

回答

11

该调用可能是一个外部函数,并且您看到的地址(FFFFFFFC)只是实际地址的占位符,链接器和/或加载器将在稍后处理。

+0

是的,这是正确的答案。如果你objdump一个未链接的.o文件,你会看到很多这些。 – 2010-03-31 06:22:49

+0

是的,就是这样。我的确确实实在在盯住一个* .o文件。 – 2010-03-31 06:29:13