From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 2 03:21:13 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 0353716A41A for ; Wed, 2 Jan 2008 03:21:13 +0000 (UTC) (envelope-from xistence@0x58.com) Received: from mailexchange.osnn.net (1e.66.5646.static.theplanet.com [70.86.102.30]) by mx1.freebsd.org (Postfix) with SMTP id C9D0E13C448 for ; Wed, 2 Jan 2008 03:21:12 +0000 (UTC) (envelope-from xistence@0x58.com) Received: (qmail 20711 invoked by uid 0); 2 Jan 2008 03:17:24 -0000 Received: from unknown (HELO WideLoad.lan) (xistence@0x58.com@86.87.237.117) by mailexchange.osnn.net with SMTP; 2 Jan 2008 03:17:24 -0000 Message-Id: From: Bert JW Regeer In-Reply-To: <477A896F.4050509@freebsd.org> Content-Type: multipart/signed; boundary=Apple-Mail-2--253954344; micalg=sha1; protocol="application/pkcs7-signature" Mime-Version: 1.0 (Apple Message framework v915) Date: Wed, 2 Jan 2008 04:21:01 +0100 References: <18297.6718.750894.937199@yeti.mininet> <20071231142620.39f2fbd2@kan.dnsalias.net> <18297.20596.564077.568365@yeti.mininet> <4779AD03.1060505@freebsd.org> <20080101104018.0fe51d67@kan.dnsalias.net> <477A896F.4050509@freebsd.org> X-Mailer: Apple Mail (2.915) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: FreeBSD Hackers , 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: Wed, 02 Jan 2008 03:21:13 -0000 --Apple-Mail-2--253954344 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Jan 1, 2008, at 19:41 , Tim Kientzle wrote: >>>> 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 ... on Linux to see whether it calls the >>> registered exit function at dlclose time or never. >> Linux pulls hidden atexit symbol into every binary that uses it ... >> Linux calls atexit entries at object unload time. >> Solaris implements a libc callback from ld.so.1 ... >> Solaris calls atexit callback when removing it too. > > Interesting. So the consensus here (at least for Linux > and Solaris, anyone know about Mac OS?) seems to be that > atexit() can be called from a dynamically loaded library > and that functions registered this way will be called > at library unload time. > > And FreeBSD doesn't implement this behavior. > > Tim Kientzle Mac OS X (10.5.1) $ gcc -dynamiclib -o atexitmod.so atexitmod.c $ gcc -o datest datatest.c $ ./datest hello driver now exiting $ uname -a Darwin WideLoad.lan 9.1.0 Darwin Kernel Version 9.1.0: Wed Oct 31 17:46:22 PDT 2007; root:xnu-1228.0.2~1/RELEASE_I386 i386 $ gcc --version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465) I guess Mac OS X calls atexit() somehow. I don't know the internals of Mac OS X, just wanted to post that the example given in this thread works as one would semi-expect, and thus possibly against the spec. Bert JW Regeer --Apple-Mail-2--253954344--