From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32124 invoked by alias); 12 Dec 2002 21:59:13 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 32114 invoked from network); 12 Dec 2002 21:59:08 -0000 Received: from unknown (HELO hiauly1.hia.nrc.ca) (132.246.100.193) by sources.redhat.com with SMTP; 12 Dec 2002 21:59:08 -0000 Received: from hiauly1.hia.nrc.ca (localhost [127.0.0.1]) by hiauly1.hia.nrc.ca (8.12.0.Beta16/8.12.0.Beta16) with ESMTP id gBCLx6ot024640; Thu, 12 Dec 2002 16:59:06 -0500 (EST) Received: (from dave@localhost) by hiauly1.hia.nrc.ca (8.12.0.Beta16/8.12.0.Beta16) id gBCLx5us024639; Thu, 12 Dec 2002 16:59:05 -0500 (EST) Message-Id: <200212122159.gBCLx5us024639@hiauly1.hia.nrc.ca> Subject: Re: dlopen() does not call static constructors on HP-UX To: harri@nerim.net (Harri Pasanen) Date: Thu, 12 Dec 2002 14:29:00 -0000 From: "John David Anglin" Cc: gcc@gcc.gnu.org In-Reply-To: <200212122102.47535.harri@nerim.net> from "Harri Pasanen" at Dec 12, 2002 09:02:47 pm MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SW-Source: 2002-12/txt/msg00674.txt.bz2 > 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)