我检查了 GCC 生成的汇编代码以获取以下 C++ 代码片段。
class Interface {
public:
virtual int f() = 0;
virtual int g() = 0;
};
class Concrete : public Interface {
public:
virtual int f();
virtual int g();
};
Seams 每个 vtable 中有两个 long,而汇编代码 seams 不使用它,那么这两个可行的目的是什么?
.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