- 论坛徽章:
- 1
|
本帖最后由 chenzhanyiczy 于 2010-04-14 17:58 编辑
在linux + g++下做了一下试验:
using namespace std;
class base
{
public :
virtual void test(){char a;}
};
class sbase
{
public :
virtual void test() {int b;}
};
int main()
{
base *p=new base;
p->test();
delete p;
sbase *k=new sbase;
k->test();
delete k;
}
objdump -D test
08048636 <main>:
8048636: 8d 4c 24 04 lea 0x4(%esp),%ecx
804863a: 83 e4 f0 and $0xfffffff0,%esp
804863d: ff 71 fc pushl 0xfffffffc(%ecx)
8048640: 55 push %ebp
8048641: 89 e5 mov %esp,%ebp
8048643: 53 push %ebx
8048644: 51 push %ecx
8048645: 83 ec 20 sub $0x20,%esp
8048648: c7 04 24 04 00 00 00 movl $0x4,(%esp)
804864f: e8 78 fe ff ff call 80484cc <_Znwj@plt>
8048654: 89 c3 mov %eax,%ebx
8048656: 89 1c 24 mov %ebx,(%esp)
8048659: e8 70 00 00 00 call 80486ce <_ZN4baseC1Ev>
804865e: 89 5d f0 mov %ebx,0xfffffff0(%ebp)
8048661: 8b 45 f0 mov 0xfffffff0(%ebp),%eax
8048664: 8b 00 mov (%eax),%eax
8048666: 8b 10 mov (%eax),%edx
8048668: 8b 45 f0 mov 0xfffffff0(%ebp),%eax
804866b: 89 04 24 mov %eax,(%esp)
804866e: ff d2 call *%edx
8048670: 8b 45 f0 mov 0xfffffff0(%ebp),%eax
8048673: 89 04 24 mov %eax,(%esp)
8048676: e8 11 fe ff ff call 804848c <_ZdlPv@plt>
804867b: c7 04 24 04 00 00 00 movl $0x4,(%esp)
8048682: e8 45 fe ff ff call 80484cc <_Znwj@plt>
8048687: 89 c3 mov %eax,%ebx
8048689: 89 1c 24 mov %ebx,(%esp)
804868c: e8 4d 00 00 00 call 80486de <_ZN5sbaseC1Ev>
8048691: 89 5d f4 mov %ebx,0xfffffff4(%ebp)
8048694: 8b 45 f4 mov 0xfffffff4(%ebp),%eax
8048697: 8b 00 mov (%eax),%eax
8048699: 8b 10 mov (%eax),%edx
804869b: 8b 45 f4 mov 0xfffffff4(%ebp),%eax
804869e: 89 04 24 mov %eax,(%esp)
80486a1: ff d2 call *%edx
80486a3: 8b 45 f4 mov 0xfffffff4(%ebp),%eax
80486a6: 89 04 24 mov %eax,(%esp)
80486a9: e8 de fd ff ff call 804848c <_ZdlPv@plt>
80486ae: b8 00 00 00 00 mov $0x0,%eax
80486b3: 83 c4 20 add $0x20,%esp
80486b6: 59 pop %ecx
80486b7: 5b pop %ebx
80486b8: 5d pop %ebp
80486b9: 8d 61 fc lea 0xfffffffc(%ecx),%esp
80486bc: c3 ret
80486bd: 90 nop
080486ce <_ZN4baseC1Ev>:
80486ce: 55 push %ebp
80486cf: 89 e5 mov %esp,%ebp
80486d1: ba d0 87 04 08 mov $0x80487d0,%edx
80486d6: 8b 45 08 mov 0x8(%ebp),%eax
80486d9: 89 10 mov %edx,(%eax)
80486db: 5d pop %ebp
80486dc: c3 ret
80486dd: 90 nop
080486de <_ZN5sbaseC1Ev>:
80486de: 55 push %ebp
80486df: 89 e5 mov %esp,%ebp
80486e1: ba f0 87 04 08 mov $0x80487f0,%edx
80486e6: 8b 45 08 mov 0x8(%ebp),%eax
80486e9: 89 10 mov %edx,(%eax)
80486eb: 5d pop %ebp
80486ec: c3 ret
80486ed: 90 nop
80486ee: 90 nop
80486ef: 90 nop
可以看到粗体的部分,编译器已经直接找到了要调用的函数,并call 它了,并没有去找vtable表
看来每个编译器实现还真不一样 |
|