RFC: New C++ Attribute: final
Cheng, Cheuk
cheng@powertv.com
Mon Mar 1 19:03:00 GMT 2004
Hi, I am using sparc-elf-gcc 2.9.5.3. Does the virtual destructor in
the 00000000 <__._1B>: portion below actually call the destructor for
the parent class A? Or is it calling ___builtin_delete() when it says
something like this?
00000004 <.LM10>:
4: 11 00 00 00 sethi %hi(0), %o0
4: R_SPARC_HI22 ___vt_1A
8: 90 12 20 00 mov %o0, %o0 ! 0 <__._1B>
8: R_SPARC_LO10 ___vt_1A
c: d0 26 20 08 st %o0, [ %i0 + 8 ]
10: 40 00 00 00 call 10 <.LM10+0xc>
10: R_SPARC_WDISP30 ___builtin_delete
...............
<full version follows source code below>
When I compile the same source code without any optimizations (-O1, -O2,
etc.) , then I can see a call to A::~A instead of ___builtin_delete().
Since I do not know sparc assembly language, I do not know whether the
object code generated is right or not.
Thanks.
class A
{
public:
A() { X = 0; Z = new(char); }
A(int temp) : X(temp) { Z = new(char); }
virtual ~A() { delete Z; }
private:
int X;
char *Z;
};
class B: public A
{
public:
B() : A(1), Y(2) {}
~B() {}
private:
int Y;
};
int main(int argc, char **argv)
{
B *obj = new B();
delete obj;
return 0;
}
====================================================
dstr.o: file format elf32-sparc
SYMBOL TABLE:
00000000 l df *ABS* 00000000 dstr.cpp
00000000 l d .text 00000000
00000000 l d .data 00000000
00000000 l d .bss 00000000
00000000 l d .gnu.linkonce.d.__vt_1B 00000000
00000000 l d .gnu.linkonce.d.__vt_1A 00000000
00000000 l d .gnu.linkonce.t._._1B 00000000
00000000 l .gnu.linkonce.t._._1B 00000000 .LM9
00000004 l .gnu.linkonce.t._._1B 00000000 .LM10
0000002c l .gnu.linkonce.t._._1B 00000000 .LM11
00000000 l d .gnu.linkonce.t._._1A 00000000
00000000 l .gnu.linkonce.t._._1A 00000000 .LM12
00000000 l *ABS* 00000000 *ABS*
00000000 l d .stab 00000000
00000000 l d .stabstr 00000000
00000000 l d .comment 00000000
00000000 g F .text 00000064 _main
00000000 *UND* 00000000 ___builtin_new
00000000 w O .gnu.linkonce.d.__vt_1A 0000000c ___vt_1A
00000000 w O .gnu.linkonce.d.__vt_1B 0000000c ___vt_1B
00000000 w F .gnu.linkonce.t._._1B 00000034 __._1B
00000000 w F .gnu.linkonce.t._._1A 00000034 __._1A
00000000 *UND* 00000000 ___builtin_delete
Disassembly of section .text:
00000000 <_main>:
0: 9d e3 bf 98 save %sp, -104, %sp
4: 40 00 00 00 call 4 <_main+0x4>
4: R_SPARC_WDISP30 ___builtin_new
8: 90 10 20 10 mov 0x10, %o0
c: b0 10 00 08 mov %o0, %i0
10: 92 10 20 01 mov 1, %o1
14: 11 00 00 00 sethi %hi(0), %o0
14: R_SPARC_HI22 ___vt_1A
18: 90 12 20 00 mov %o0, %o0 ! 0 <_main>
18: R_SPARC_LO10 ___vt_1A
1c: d0 26 20 08 st %o0, [ %i0 + 8 ]
20: d2 26 00 00 st %o1, [ %i0 ]
24: 40 00 00 00 call 24 <_main+0x24>
24: R_SPARC_WDISP30 ___builtin_new
28: 90 10 20 01 mov 1, %o0
2c: d0 26 20 04 st %o0, [ %i0 + 4 ]
30: 11 00 00 00 sethi %hi(0), %o0
30: R_SPARC_HI22 ___vt_1B
34: 92 12 20 00 mov %o0, %o1 ! 0 <_main>
34: R_SPARC_LO10 ___vt_1B
38: d2 26 20 08 st %o1, [ %i0 + 8 ]
3c: 90 10 20 02 mov 2, %o0
40: 80 a6 20 00 cmp %i0, 0
44: 02 80 00 06 be 5c <_main+0x5c>
48: d0 26 20 0c st %o0, [ %i0 + 0xc ]
4c: d4 02 60 08 ld [ %o1 + 8 ], %o2
50: 90 10 00 18 mov %i0, %o0
54: 9f c2 80 00 call %o2
58: 92 10 20 03 mov 3, %o1
5c: 81 c7 e0 08 ret
60: 91 e8 20 00 restore %g0, 0, %o0
Disassembly of section .data:
Disassembly of section .gnu.linkonce.d.__vt_1B:
00000000 <___vt_1B>:
...
8: R_SPARC_32 __._1B
Disassembly of section .gnu.linkonce.d.__vt_1A:
00000000 <___vt_1A>:
...
8: R_SPARC_32 __._1A
Disassembly of section .gnu.linkonce.t._._1B:
00000000 <__._1B>:
0: 9d e3 bf 98 save %sp, -104, %sp
00000004 <.LM10>:
4: 11 00 00 00 sethi %hi(0), %o0
4: R_SPARC_HI22 ___vt_1A
8: 90 12 20 00 mov %o0, %o0 ! 0 <__._1B>
8: R_SPARC_LO10 ___vt_1A
c: d0 26 20 08 st %o0, [ %i0 + 8 ]
10: 40 00 00 00 call 10 <.LM10+0xc>
10: R_SPARC_WDISP30 ___builtin_delete
14: d0 06 20 04 ld [ %i0 + 4 ], %o0
18: 80 8e 60 01 btst 1, %i1
1c: 02 80 00 04 be 2c <.LM11>
20: 01 00 00 00 nop
24: 40 00 00 00 call 24 <.LM10+0x20>
24: R_SPARC_WDISP30 ___builtin_delete
28: 90 10 00 18 mov %i0, %o0
0000002c <.LM11>:
2c: 81 c7 e0 08 ret
30: 81 e8 00 00 restore
Disassembly of section .gnu.linkonce.t._._1A:
00000000 <__._1A>:
0: 9d e3 bf 98 save %sp, -104, %sp
4: 11 00 00 00 sethi %hi(0), %o0
4: R_SPARC_HI22 ___vt_1A
8: 90 12 20 00 mov %o0, %o0 ! 0 <__._1A>
8: R_SPARC_LO10 ___vt_1A
c: d0 26 20 08 st %o0, [ %i0 + 8 ]
10: 40 00 00 00 call 10 <__._1A+0x10>
10: R_SPARC_WDISP30 ___builtin_delete
14: d0 06 20 04 ld [ %i0 + 4 ], %o0
18: 80 8e 60 01 btst 1, %i1
1c: 02 80 00 04 be 2c <__._1A+0x2c>
20: 01 00 00 00 nop
24: 40 00 00 00 call 24 <__._1A+0x24>
24: R_SPARC_WDISP30 ___builtin_delete
28: 90 10 00 18 mov %i0, %o0
2c: 81 c7 e0 08 ret
30: 81 e8 00 00 restore
- - - - - - - Appended by PowerTV, Inc. - - - - - - -
This e-mail and any attachments may contain information that is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.
More information about the Gcc
mailing list