Re: [G2R] Re: Various releases ...
- From: Alex Hornby <alex anvil co uk>
- To: Sander Vesik <Sander Vesik Sun COM>
- Cc: Michael Meeks <michael ximian com>,Havoc Pennington <hp redhat com>,bonobo <gnome-components-list gnome org>,orbit <orbit-list gnome org>
- Subject: Re: [G2R] Re: Various releases ...
- Date: 09 May 2002 17:04:15 +0100
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]