This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Constructor called twice on global objects


> 
> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]