From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 1 03:01:28 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A0DED16A41A for ; Tue, 1 Jan 2008 03:01:28 +0000 (UTC) (envelope-from kientzle@freebsd.org) Received: from kientzle.com (h-66-166-149-50.snvacaid.covad.net [66.166.149.50]) by mx1.freebsd.org (Postfix) with ESMTP id 4A17013C467 for ; Tue, 1 Jan 2008 03:01:28 +0000 (UTC) (envelope-from kientzle@freebsd.org) Received: (from root@localhost) by kientzle.com (8.12.9/8.12.9) id m0131NZh070549; Mon, 31 Dec 2007 19:01:23 -0800 (PST) (envelope-from kientzle@freebsd.org) Received: from [10.0.0.209] (p54.kientzle.com [66.166.149.54]) by kientzle.com with SMTP; Mon, 31 Dec 2007 19:01:23 -0800 (PST) (envelope-from kientzle@freebsd.org) Message-ID: <4779AD03.1060505@freebsd.org> Date: Mon, 31 Dec 2007 19:01:23 -0800 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.12) Gecko/20060422 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Markus Hoenicka References: <18297.6718.750894.937199@yeti.mininet> <20071231142620.39f2fbd2@kan.dnsalias.net> <18297.20596.564077.568365@yeti.mininet> In-Reply-To: <18297.20596.564077.568365@yeti.mininet> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: dlopen(), atexit() crash on FreeBSD (testcase included) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jan 2008 03:01:28 -0000 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