This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: Constructor called twice on global objects
- To: bhaddow at orbism dot com
- Subject: Re: Constructor called twice on global objects
- From: hjl at lucon dot org (H.J. Lu)
- Date: Mon, 27 Sep 1999 08:08:17 -0700 (PDT)
- Cc: binutils at sourceware dot cygnus dot com
>
> Hi
>
> I have the same global object in two different source files. One source
> file is compiled and linked into a shared
> object and the other is compiled and linked into the executable, the
> executable being linked with the
> shared object. I find that only one instance of the global object is
> created, but its constructor and destructor are called twice.
> Surely this can't be correct? - I don't observer this behaviour on other
> UNIX platforms.
>
FWIW, I got the same result on Solaris/x86 and Solaris/Sparc. I
believe its constructor and destructor will be called twice on all
ELF-based systems. Although there is only one instance of the global
object, its constructor and destructor are called from the .init and
.fini sections in both executable and shared library. I don't know if
there is an easy fix on it. I will see what I can do in the future.
You can find more about ELF in
ftp://ftp.valinux.com/pub/support/hjl/doc/elf.ps.gz
The C library related stuff may be out of date. But the ELF part is
still relevant.
H.J.