dlopen(), atexit() crash on FreeBSD (testcase included)

Tim Kientzle kientzle at freebsd.org
Mon Dec 31 19:01:28 PST 2007


Markus Hoenicka wrote:
> Alexander Kabaev writes:
>  > As designed. atexit should not be used by shared objects that do not
>  > expect themselves to live until actual exit() happens. ELF provides
>  > proper _init/_fini sections to support shared object
>  > initialization/destruction.
>  > 
> 
> That is, the only real solution to this problem is to convince the
> Firebird folks to remove their atexit() calls from the client
> libraries?

I suspect they never considered that their dynamic library
might be used via dlopen()/dlclose().  The real question is
whether they're interesting in supporting this model.
If the Firebird folks aren't interested in having their
library be accessible in that fashion, then you have
little choice but to simply forgo unloading this particular
library.

It's a bit unfortunate that there is no standard way
to remove an atexit() registration.  It would probably
be easier to convince the Firebird folks to remove the
registration as part of their cleanup routines (and
you could then invoke those cleanup routines manually
for that case).

> Also, I'm wondering how other OSes handle this. I don't see this
> code crash on Linux, contrary to its design as you say.

I would be curious to see the results of running your
sample program (with lots of extra fprint(stderr...)
calls, of course) on Linux to see whether it calls the
registered exit function at dlclose time or never.

I suspect the answer is "never."  If I'm right, the
Firebird folks might be easier to convince (since it
means that their atexit() registration isn't really
reliable anywhere).

Tim Kientzle


More information about the freebsd-hackers mailing list