public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: dlopen() does not call static constructors on HP-UX
@ 2002-12-06 21:27 John David Anglin
  2002-12-12 12:07 ` Harri Pasanen
  0 siblings, 1 reply; 7+ messages in thread
From: John David Anglin @ 2002-12-06 21:27 UTC (permalink / raw)
  To: gcc; +Cc: harri

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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* dlopen() does not call static constructors on HP-UX
@ 2002-12-05 23:24 Harri Pasanen
  2002-12-06  0:44 ` H. J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Harri Pasanen @ 2002-12-05 23:24 UTC (permalink / raw)
  To: gcc

I suppose this is an old can of worms, but after multiple searches 
through the mailing list I'm still not enlightened in my specific 
problem, so here I go.

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.

Now seems like a HP-UX specific bug, and searching gnats it indeed looks 
like the same one 
as PR 8360. 
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8360

Having full control of the dlopen(), which happens in my C++ source, I'm 
looking for a way to manually circumvent this bug.  Examining my shared 
library symbols, looks like there is something called 
__static_initialization_and_destruction, which I guess arranges for the 
constructors and destructors to be called.   Is there a way I can 
arrange my code to call this function after I've done the dlopen()?

Regards,

Harri

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-12-12 21:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-06 21:27 dlopen() does not call static constructors on HP-UX John David Anglin
2002-12-12 12:07 ` Harri Pasanen
2002-12-12 12:26   ` David Edelsohn
2002-12-12 13:02   ` John David Anglin
2002-12-12 14:29   ` John David Anglin
  -- strict thread matches above, loose matches on Subject: below --
2002-12-05 23:24 Harri Pasanen
2002-12-06  0:44 ` H. J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).