dlopen() does not call static constructors on HP-UX

John David Anglin dave@hiauly1.hia.nrc.ca
Thu Dec 12 13:02:00 GMT 2002


> I've currently been only experimenting with 32 bit port, apparently the 
> 64 bit port seems to be broken, both 3.2 and the CVS version.

Did you try what I suggested using the HP linker and enabling the
LD_INIT_SWITCH and LD_FINI_SWITCH macros in pa64-hpux.h?  Constructors
are not being called in shared libraries currently because the technique
used in the 32-bit SOM port doesn't work.

If you are having other difficulties with the 64-bit port, please
provide specifics.

> Looking at what is happening when shared library is linked with 
> -Wl,+debug, I noticed that each shared lib appears to have just one 
> function that calls the constructors.   That function appears to be 
> smart enough, so that if it is called more than once, it will still 
> only construct the objects once.

Yes.

> So all this is done without any modifications to gcc itself.   Can you 
> see any pitfalls with my approach?   I'll let you know if I run into 
> any problems.

The LD_INIT_SWITCH is a much much simpler approach.  As I indicated, I
believe that the HP linker has supported +init/+fini switches since at
least HPUX 10.  Collect will build the init/fini global constructors
for you and the dynamic loader will arrange to call the init/fini
routines for you when the library is loaded/unloaded.

The GNU linker needs to be fixed to use this approach or init/fini
sections.  I believe that it currently sets DT_INIT/DT_FINI.  These
aren't supported by HPUX.  It needs to set DT_INIT_ARRAY/DT_FINI_ARRAY.
The LD_INIT_SWITCH/LD_FINI_SWITCH macros are not enabled because they
cause problems with the GNU linker (i.e., GCC will not build).

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)



More information about the Gcc mailing list