---------- sample program ----------
struct Command {
Command() {}
virtual ~Command() {}
};
void tryfunc() {
Command cmd;
for (;;) { throw 1; }
}
---------- end sample program ----------
Disassembly of tryfunc():
(notice at 58-5c, constructor is called on r1+8, but at
88-90, destructor is called on r1+0)
00000000 <tryfunc()>:
0: 94 21 ff 60 stwu r1,-160(r1)
4: 7c 08 02 a6 mflr r0
8: 3d 20 00 00 lis r9,0
a: R_PPC_ADDR16_HA __gxx_personality_sj0
c: 39 29 00 00 addi r9,r9,0
e: R_PPC_ADDR16_LO __gxx_personality_sj0
10: 7d 80 00 26 mfcr r12
14: 91 21 00 30 stw r9,48(r1)
18: 3d 20 00 00 lis r9,0
1a: R_PPC_ADDR16_HA .gcc_except_table
1c: 38 61 00 18 addi r3,r1,24
20: 90 01 00 a4 stw r0,164(r1)
24: 39 29 00 00 addi r9,r9,0
26: R_PPC_ADDR16_LO .gcc_except_table
28: 80 01 00 00 lwz r0,0(r1)
2c: 91 21 00 34 stw r9,52(r1)
30: 3d 20 00 00 lis r9,0
32: R_PPC_ADDR16_HA .text+0x84
34: 39 29 00 84 addi r9,r9,132
36: R_PPC_ADDR16_LO .text+0x84
38: 90 01 00 40 stw r0,64(r1)
3c: 38 01 00 08 addi r0,r1,8
40: 90 01 00 38 stw r0,56(r1)
44: 91 81 00 54 stw r12,84(r1)
48: 91 21 00 3c stw r9,60(r1)
4c: bd c1 00 58 stmw r14,88(r1)
50: 90 21 00 44 stw r1,68(r1)
54: 48 00 00 01 bl 54 <tryfunc()+0x54>
54: R_PPC_REL24 _Unwind_SjLj_Register
58: 38 61 00 08 addi r3,r1,8
5c: 48 00 00 01 bl 5c <tryfunc()+0x5c>
5c: R_PPC_REL24 Command::Command()
60: 38 60 00 04 li r3,4
64: 48 00 00 01 bl 64 <tryfunc()+0x64>
64: R_PPC_REL24 __cxa_allocate_exception
68: 38 00 00 01 li r0,1
6c: 3c 80 00 00 lis r4,0
6e: R_PPC_ADDR16_HA typeinfo for int
70: 90 03 00 00 stw r0,0(r3)
74: 38 84 00 00 addi r4,r4,0
76: R_PPC_ADDR16_LO typeinfo for int
78: 38 a0 00 00 li r5,0
7c: 90 01 00 1c stw r0,28(r1)
80: 48 00 00 01 bl 80 <tryfunc()+0x80>
80: R_PPC_REL24 __cxa_throw
84: 80 01 00 20 lwz r0,32(r1)
88: 7c 23 0b 78 mr r3,r1
8c: 90 01 00 4c stw r0,76(r1)
90: 48 00 00 01 bl 90 <tryfunc()+0x90>
90: R_PPC_REL24 Command::~Command()
94: 38 00 ff ff li r0,-1
98: 80 61 00 4c lwz r3,76(r1)
9c: 90 01 00 1c stw r0,28(r1)
a0: 48 00 00 01 bl a0 <tryfunc()+0xa0>
a0: R_PPC_REL24 _Unwind_SjLj_Resume
Program was compiled with the following command line options:
g++ -Os -msoft-float -fno-inline sample-program.cc -c
The -msoft-float and -Os aren't necessary to reproduce this problem,
but reduce clutter.
The optimization level doesn't matter. Looking at a disassembly at
-O0 may shed more light on the problem:
Disassembly of tryfunc() at -O0 (all other CL arguments unchanged):
00000000 <tryfunc()>:
0: 94 21 ff 50 stwu r1,-176(r1)
4: 7c 08 02 a6 mflr r0
8: 7d 80 00 26 mfcr r12
c: 91 c1 00 68 stw r14,104(r1)
10: 91 e1 00 6c stw r15,108(r1)
14: 92 01 00 70 stw r16,112(r1)
18: 92 21 00 74 stw r17,116(r1)
1c: 92 41 00 78 stw r18,120(r1)
20: 92 61 00 7c stw r19,124(r1)
24: 92 81 00 80 stw r20,128(r1)
28: 92 a1 00 84 stw r21,132(r1)
2c: 92 c1 00 88 stw r22,136(r1)
30: 92 e1 00 8c stw r23,140(r1)
34: 93 01 00 90 stw r24,144(r1)
38: 93 21 00 94 stw r25,148(r1)
3c: 93 41 00 98 stw r26,152(r1)
40: 93 61 00 9c stw r27,156(r1)
44: 93 81 00 a0 stw r28,160(r1)
48: 93 a1 00 a4 stw r29,164(r1)
4c: 93 c1 00 a8 stw r30,168(r1)
50: 93 e1 00 ac stw r31,172(r1)
54: 90 01 00 b4 stw r0,180(r1)
58: 91 81 00 64 stw r12,100(r1)
5c: 7c 3f 0b 78 mr r31,r1
60: 3d 20 00 00 lis r9,0
62: R_PPC_ADDR16_HA __gxx_personality_sj0
64: 38 09 00 00 addi r0,r9,0
66: R_PPC_ADDR16_LO __gxx_personality_sj0
68: 90 1f 00 30 stw r0,48(r31)
6c: 3d 20 00 00 lis r9,0
6e: R_PPC_ADDR16_HA .gcc_except_table
70: 38 09 00 00 addi r0,r9,0
72: R_PPC_ADDR16_LO .gcc_except_table
74: 90 1f 00 34 stw r0,52(r31)
78: 39 7f 00 38 addi r11,r31,56
7c: 38 1f 00 08 addi r0,r31,8
80: 90 0b 00 00 stw r0,0(r11)
84: 3d 20 00 00 lis r9,0
86: R_PPC_ADDR16_HA .text+0xec
88: 38 09 00 ec addi r0,r9,236
8a: R_PPC_ADDR16_LO .text+0xec
8c: 90 0b 00 04 stw r0,4(r11)
90: 80 01 00 00 lwz r0,0(r1)
94: 90 0b 00 08 stw r0,8(r11)
98: 90 2b 00 0c stw r1,12(r11)
9c: 38 1f 00 18 addi r0,r31,24
a0: 7c 03 03 78 mr r3,r0
a4: 48 00 00 01 bl a4 <tryfunc()+0xa4>
a4: R_PPC_REL24 _Unwind_SjLj_Register
a8: 38 1f 00 08 addi r0,r31,8
ac: 7c 03 03 78 mr r3,r0
b0: 48 00 00 01 bl b0 <tryfunc()+0xb0>
b0: R_PPC_REL24 Command::Command()
b4: 38 60 00 04 li r3,4
b8: 48 00 00 01 bl b8 <tryfunc()+0xb8>
b8: R_PPC_REL24 __cxa_allocate_exception
bc: 7c 60 1b 78 mr r0,r3
c0: 7c 0b 03 78 mr r11,r0
c4: 7d 69 5b 78 mr r9,r11
c8: 38 00 00 01 li r0,1
cc: 90 09 00 00 stw r0,0(r9)
d0: 7d 63 5b 78 mr r3,r11
d4: 3d 20 00 00 lis r9,0
d6: R_PPC_ADDR16_HA typeinfo for int
d8: 38 00 00 01 li r0,1
dc: 90 1f 00 1c stw r0,28(r31)
e0: 38 89 00 00 addi r4,r9,0
e2: R_PPC_ADDR16_LO typeinfo for int
e4: 38 a0 00 00 li r5,0
e8: 48 00 00 01 bl e8 <tryfunc()+0xe8>
e8: R_PPC_REL24 __cxa_throw
ec: 3b ff ff f8 addi r31,r31,-8
f0: 80 1f 00 20 lwz r0,32(r31)
f4: 90 1f 00 50 stw r0,80(r31)
f8: 80 1f 00 50 lwz r0,80(r31)
fc: 90 1f 00 4c stw r0,76(r31)
100: 38 1f 00 08 addi r0,r31,8
104: 7c 03 03 78 mr r3,r0
108: 48 00 00 01 bl 108 <tryfunc()+0x108>
108: R_PPC_REL24 Command::~Command()
10c: 80 1f 00 4c lwz r0,76(r31)
110: 90 1f 00 50 stw r0,80(r31)
114: 38 00 ff ff li r0,-1
118: 90 1f 00 1c stw r0,28(r31)
11c: 80 7f 00 50 lwz r3,80(r31)
120: 48 00 00 01 bl 120 <tryfunc()+0x120>
120: R_PPC_REL24 _Unwind_SjLj_Resume
I have not been able to reproduce this problem on compilers
targeted to x86.
--
Summary: Wrong address of stack object used for destructor call
on PPC
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: atgraham at gmail dot com
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: powerpc-wrs-vxworks
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28493