This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: dlopen() does not call static constructors on HP-UX
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- To: harri at nerim dot net (Harri Pasanen)
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 12 Dec 2002 16:59:05 -0500 (EST)
- Subject: Re: dlopen() does not call static constructors on HP-UX
> So if I have a C++ built shared library called foo.sl, the function
> resposible called the constructors is called _GLOBAL__FI_foo_sl.
> By passing -Wl,+I -Wl,_GLOBAL__FI_foo_sl to the linker when linking the
> shared lib, the loader will call _GLOBAL__FI_foo_sl and all the
> constructors are called. This works also when dlopen/shl_load is used,
> and appears to do no harm if it is linked with directly.
This is what the LD_INIT_SWITCH and LD_FINI_SWITCH defines do for you.
In looking at HPUX 10, I see that only the "+I" option is available
for running initializers. There isn't an option for finalizers.
HPUX 11 ld has +init/+fini as well.
Thus, I can see using LD_INIT_SWITCH/LD_FINI_SWITCH for the HPUX 11
32-bit port but I am not sure there is a good argument to do this
for HPUX 10 as it seems to lack a switch to automatically call
destructors.
You might also be able to explicitly call the initializer and finalizer
routines when using dlopen/shl_load.
> I have not bothered about calling the destructors, as I'm not unloading
> any libs.
>
> It is possible to make the above process fully automatic, but it
> requires first building the shared lib, looking if the _GLOBAL__FI_*
> symbol is present and then rebuilding it.
I believe it is collect2 that creates the _GLOBAL__FI_* initializer for
each shared library.
Dave
--
J. David Anglin dave.anglin@nrc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)