c++ - "call"看似跳入自身的指令

标签 c++ gcc assembly g++

我有一些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指令的操作数我看不懂,为什么调用到自身,却少了一个字节?

最佳答案

调用可能是对外部函数的调用,您看到的地址 (FFFFFFFC) 只是真实地址的占位符,链接器和/或加载器稍后会处理。

关于c++ - "call"看似跳入自身的指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2550822/

相关文章:

c++ - 在 Boost::Python 中通过引用传递

c++ - 如何用 c/c++ 填充我的 md5 消息

c++ - GCC 和去虚拟化内联

c++ - 带有 C++ 程序控制台输入的 Sublime Text

assembly - 如何在 AVX/AVX2 中增加向量

c++ - 如何用 Qt 插入空值?

c++ - 将函数定义为速记

c++ - GCC 对 C++17 的支持情况如何?

assembly - GAS ASM PIE x86-64 使用 LEA 指令访问变量

assembly - ATmega128 : Adding and subtracting 16-bit numbers (assembly)