This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
constructor attribute function call output twice in g++ 2.96
- To: gcc-bugs at gcc dot gnu dot org
- Subject: constructor attribute function call output twice in g++ 2.96
- From: "Mark E." <snowball3 at bigfoot dot com>
- Date: Wed, 19 Jul 2000 23:51:58 -0400
Hi guys,
I've been taking a look at why the constructor and destructor attributes
don't work because it's used by at least one widely used C++ DJGPP program
(see problem report #114). My fix works fine in gcc 2.95.2, but the function
calls are emitted twice in 2.96. An example with that demonstrates this with
gcc 2.96 without changes is included below. Notice that 'call _f2__Fv' and '
call _f__Fv' are output twice. Ouch.
ctor.cpp:
__attribute__((constructor)) void f(void)
{
return;
}
__attribute__((constructor)) void f2(void)
{
return;
}
__attribute__((destructor)) void g(void)
{
return;
}
class Ctor
{
public:
Ctor();
~Ctor(){}
int x;
};
Ctor::Ctor()
{
x = 5;
}
Ctor x;
using 'cc1plus -fno-exceptions -fno-rtti < ctor.cpp &> out.txt' gives me this
output:
void f () void f () .file "stdin"
gcc2_compiled.:
___gnu_compiled_cplusplus:
.section .text
.p2align 4
.globl _f__Fv
_f__Fv:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
void f2 () void f2 () .p2align 4
.globl _f2__Fv
_f2__Fv:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
void g () void g () .p2align 4
.globl _g__Fv
_g__Fv:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
Ctor::~Ctor () Ctor::Ctor () Ctor::Ctor () .p2align 4
.globl ___4Ctor
___4Ctor:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl $5, (%eax)
popl %ebp
ret
void __static_initialization_and_destruction_0 (int, int) void
__static_initialization_and_destruction_0 (int, int).globl _x
.section .bss
.p2align 2
_x:
.space 4
.section .text
.p2align 4
___static_initialization_and_destruction_0:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
cmpl $65535, 12(%ebp)
jne L11
cmpl $1, 8(%ebp)
jne L11
subl $12, %esp
pushl $_x
call ___4Ctor
addl $16, %esp
movl %eax, -4(%ebp)
L11:
cmpl $65535, 12(%ebp)
jne L13
cmpl $0, 8(%ebp)
jne L13
subl $8, %esp
pushl $2
pushl $_x
call __$_4Ctor
addl $16, %esp
L13:
movl %ebp, %esp
popl %ebp
ret
Ctor::~Ctor () .section .gnu.linkonce.t._$_4Ctor,"x"
.p2align 4
.weak __$_4Ctor
__$_4Ctor:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl 12(%ebp), %eax
andl $1, %eax
testb %al, %al
je L17
subl $12, %esp
pushl 8(%ebp)
call ___builtin_delete
addl $16, %esp
L17:
movl %ebp, %esp
popl %ebp
ret
(static initializers for stdin) (static initializers for stdin) .section
.text
.p2align 4
__GLOBAL_$I$f__Fv:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
subl $8, %esp
pushl $65535
pushl $1
call ___static_initialization_and_destruction_0
addl $16, %esp
call _f2__Fv
call _f2__Fv
call _f__Fv
call _f__Fv
movl %ebp, %esp
popl %ebp
ret
(static destructors for stdin) (static destructors for stdin) .section .ctor
.long __GLOBAL_$I$f__Fv
.section .text
.p2align 4
__GLOBAL_$D$f__Fv:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
subl $8, %esp
pushl $65535
pushl $0
call ___static_initialization_and_destruction_0
addl $16, %esp
call _g__Fv
call _g__Fv
movl %ebp, %esp
popl %ebp
ret
.section .dtor
.long __GLOBAL_$D$f__Fv
Execution times (seconds)
TOTAL : 0.05 0.00 0.05