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


> > Looks like on HP-UX 11.00,  using g++ 3.2, when I link against a shared 
> > library containing static objects, their constructors are called.  But 
> > if I do dlopen(), or shl_load() for the shared library, the static 
> > objects are not initialized.
> 
> I have an impression that DT_INIT_ARRAY/DT_FINI_ARRAY may work with
> HP-UX if ELF is used.

The 32-bit port uses collect to collect constructors and these are all
run just after main is entered.  There is no way this will work with
a dlopened library.  As H. J. noted, you can use +init/+fini switches,
I think with both the 32 and 64-bit HP linkers.  On the 32-bit port,
you would have to manually build the constructor/destructor lists
along the lines as is done by collect.

You might have better luck with the 64-bit port and the HP linker.
Read the comment near the end of pa64-hpux.h.  Get the current cvs
source and enable the LD_INIT_SWITCH/LD_FINI_SWITCH macros.  This
still uses collect but in this case the code to run the init/fini
routines are in the libraries as well as the main executable, so
they should run when a library is dlopened.

I believe that DT_INIT/DT_FINI are not supported by the HP dynamic
64-bit loader and that's why using -init/-fini doesn't work with
the GNU linker.  It needs some work.

With some experimentation, it might be possible to use +init/+fini
on the 32-bit port on 10.X and 11.X.  You would have to remove
LDD_SUFFIX and PARSE_LDD_OUTPUT, and define LD_INIT_SWITCH/LD_FINI_SWITCH.
If that works, it would be a useful improvement.  There is only
one linker to worry about in this case and you wouldn't need any
special tricks to change switches as in the 64-bit case.  If you
try it and it works, let me know.

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]