This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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)


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