From owner-freebsd-hackers Wed Dec 19 16: 2:35 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from k6.locore.ca (k6.locore.ca [198.96.117.170]) by hub.freebsd.org (Postfix) with ESMTP id 4A19E37B4CF for ; Wed, 19 Dec 2001 16:02:17 -0800 (PST) Received: (from jake@localhost) by k6.locore.ca (8.11.6/8.11.6) id fBK05bR58734; Wed, 19 Dec 2001 19:05:37 -0500 (EST) (envelope-from jake) Date: Wed, 19 Dec 2001 19:05:37 -0500 From: Jake Burkholder To: Bernd Walter Cc: Maxime Henrion , freebsd-hackers@FreeBSD.ORG Subject: Re: init code in dynamic libraries Message-ID: <20011219190537.N39205@locore.ca> References: <20011219184930.GA66211@cicely9.cicely.de> <20011219200620.A281@nebula.noos.fr> <20011219204645.GB66211@cicely9.cicely.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20011219204645.GB66211@cicely9.cicely.de>; from ticso@cicely9.cicely.de on Wed, Dec 19, 2001 at 09:46:46PM +0100 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Apparently, On Wed, Dec 19, 2001 at 09:46:46PM +0100, Bernd Walter said words to the effect of; > On Wed, Dec 19, 2001 at 08:06:20PM +0100, Maxime Henrion wrote: > > Bernd Walter wrote: > > > How can I add initalisation code to a library without needing to > > > call a function in the using application? > > > What I saw is that libc does something like this but havn't found > > > the starting point of this. > > > > There are two special functions for that : _init() which will be called > > when the object is loaded, and _fini() which will be called when it is > > released. > > I can see that symbol defined in libc.so.5 but no reference in the libc > source code. > All I see are several *_init functions. > Are they all called from within an autocreated _init function? > If yes in which order? The _init and _fini functions call global constructors and destructors (in c++). There's a gcc extension for making a constructor in C, put __attribute__((constructor)) in the prototype. The dynamic linker will call them when it loads the library. I don't know if the order that they're called in is defined or not. > > -- > B.Walter COSMO-Project http://www.cosmo-project.de > ticso@cicely.de Usergroup info@cosmo-project.de > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message