GCC发布的那两个长的vtable汇编代码是什么?

时间:2013-09-04 10:15:18

标签: c++ gcc assembly

我检查了GCC生成的汇编代码,以了解C ++代码片段。

class Interface {
public:
 virtual int f() = 0;
 virtual int g() = 0;
};

class Concrete : public Interface {
public:
 virtual int f();
 virtual int g();
};

每个vtable中有两个长接缝,而接合代码接缝不使用它,那么这两个接种的目的是什么?

          .globl __ZTV8Concrete
          .const_data
          .align 3
  __ZTV8Concrete:
          .long   0   <<<< THOS TWO LONG DOESN"T USED.
          .long   0 
          .long   __ZN8Concrete1gEv
          .long   __ZN8Concrete1fEv
          .globl __ZTV9Interface
          .weak_definition __ZTV9Interface
          .section __DATA,__const_coal,coalesced
          .align 3
  __ZTV9Interface:
          .long   0    <<<< THOS TWO LONG DOESN"T USED ALSO.
          .long   0 
          .long   ___cxa_pure_virtual
          .long   ___cxa_pure_virtual
          .section __TEXT,__textcoal_nt,coalesced,pure_instructions
          .weak_definition        ___x86.get_pc_thunk.cx
          .private_extern ___x86.get_pc_thunk.

构造函数:

  __ZN8ConcreteC1Ev:
  LFB8:
          pushl   %ebp
  LCFI9:
          movl    %esp, %ebp
  LCFI10:
          pushl   %ebx
          subl    $20, %esp
  LCFI11:
          call    ___x86.get_pc_thunk.bx
  L2$pb:
          movl    8(%ebp), %eax
          movl    %eax, (%esp)
          call    __ZN9InterfaceC2Ev
          movl    8(%ebp), %edx
2>        leal    __ZTV8Concrete-L2$pb(%ebx), %eax
          leal    8(%eax), %eax    <<<< SKIP THE TWO 2 LONG for VTABLE
          movl    %eax, (%edx)
          addl    $20, %esp
          popl    %ebx

1 个答案:

答案 0 :(得分:3)

两个“空格”中的一个应该用于RTTI(第二个),另一个用于多重继承(第一个)。请参阅示例http://tinydrblog.appspot.com/?p=89001,甚至更好https://stackoverflow.com/a/5712953/613130