Re: [G2R] Re: Various releases ...



On Thu, 2002-05-09 at 14:32, Sander Vesik wrote:
> 
> The problem with libraries registering atexit() functions is that if the
> library is unloaded, atexit functions from it get called (and need to get
> called, or the unload needs to be blocked - languages other than C will
> lose big if this doesn't happen) at that point and not program exit. It is
> not always obvious when the unload happens as you can dlopen it multiple
> times and it gets unloaded on the dlclose that brings the ref count to
> zero. It gets worse if libraries register atexit functions that actually
> reside in another library. It may well be broken implementations do
> something different and broken.
> 
> It is a hidden complexity problem, but in general, there is no hard rule
> that says that libraries cannot or should not install atexit functions. 
> 
>

The ELF init/fini sections do library initialisation/cleanup in a clean
way without using atexit().

You can mark a function to run on library load/unload in GCC like so:

static void initialize () __attribute__ ((constructor));

static void initialize () 
{
	/* do something */
}

static void cleanup () __attribute__ ((destructor));

static void cleanup () 
{
	/* do something */
}

You can see an example of the initialization case in the memprof
libmemintercept.so sources.

Hope that helps,
Alex.

BTW I didn't get any response to my earlier mail, apologies if you
already know about ELF init/fini




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]