我正在研究c ++如何通过汇编语言调用正确的成员函数.我带来的简单程序如下:
class A
{
public:
virtual void show() {}
};
class B : public A
{
public:
void show() {}
};
int main()
{
A* pA = new B;
pA->show();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其装配如下:
main:
.LFB2:
.cfi_startproc
.cfi_personality 0x3,__gxx_personality_v0
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
pushq %rbx
subq $24, %rsp
movl $8, %edi
.cfi_offset 3, -24
call _Znwm <<<================ 1
movq %rax, %rbx
movq %rbx, %rax
movq %rax, %rdi
call _ZN1BC1Ev
.L11:
movq %rbx, %rax
movq %rax, -24(%rbp)
movq -24(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdx
movq -24(%rbp), %rax
movq %rax, %rdi
call *%rdx <<<=== 2
movl $0, %eax
addq $24, %rsp
popq %rbx
leave
ret
.cfi_endproc
Run Code Online (Sandbox Code Playgroud)
我的问题是: