From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 31 23:18:34 2007 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 083A816A41A for ; Mon, 31 Dec 2007 23:18:34 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outS.internet-mail-service.net (outS.internet-mail-service.net [216.240.47.242]) by mx1.freebsd.org (Postfix) with ESMTP id DDDE813C455 for ; Mon, 31 Dec 2007 23:18:33 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Mon, 31 Dec 2007 15:18:33 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id A75D4126DDD; Mon, 31 Dec 2007 15:18:32 -0800 (PST) Message-ID: <477978D5.3000200@elischer.org> Date: Mon, 31 Dec 2007 15:18:45 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Alexander Kabaev References: <18297.6718.750894.937199@yeti.mininet> <20071231142620.39f2fbd2@kan.dnsalias.net> <18297.20596.564077.568365@yeti.mininet> <47796B43.9050704@elischer.org> <20071231180605.1fb939a9@kan.dnsalias.net> In-Reply-To: <20071231180605.1fb939a9@kan.dnsalias.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org, Markus Hoenicka 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: Mon, 31 Dec 2007 23:18:34 -0000 Alexander Kabaev wrote: > On Mon, 31 Dec 2007 14:20:51 -0800 > Julian Elischer wrote: > >> 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'll try, but I'm not very confident this is going to >>> work. 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. >>> >>> Thanks anyway to you, and to Jason Evans, for your replies. >> Not sure but I'd guess that each library calls its at_exit entrypoints >> as part of its unload handling. >> > This is not possible in general case. The object that calls atexit() > is not necessarily object that contains clean-up routine, so when > atexit() is to be called: when object that contains the routine itself > is being unloaded or when the object that registered it goes away? Also, > calling atexit hooks at that time is semantically wrong for atexit() as > it is defined, dlclose(3) is NOT exit(2). C++ ABI defines a special > __cxa_atexit function that does have proper semantics to work around > atexit() deficiencies. > > We can hack rtld/libc to pull dangling atexit off the list entries when > shared objects are being unloaded or to add extra references to > libraries pointed to by atexit entries, but that will just paper over > the general issue of Firebird (and like) folks using the API improperly. > Yes.. I wasn't saying it was a good idea, just that it may be something that the linux folks might have done.