From owner-freebsd-ports@FreeBSD.ORG Fri Dec 6 03:21:22 2013 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B136C6A5; Fri, 6 Dec 2013 03:21:22 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 22F6A14A4; Fri, 6 Dec 2013 03:21:21 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id rB63LBh9004294; Fri, 6 Dec 2013 05:21:11 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua rB63LBh9004294 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id rB63LBvH004293; Fri, 6 Dec 2013 05:21:11 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 6 Dec 2013 05:21:11 +0200 From: Konstantin Belousov To: Michael Gmelin Subject: Re: Position independent code and global destructor order (devel/ice) Message-ID: <20131206032111.GH59496@kib.kiev.ua> References: <20130626231741.497f7a9b@bsd64.grem.de> <20130626212833.GB91021@kib.kiev.ua> <20130627015602.7a437aad@bsd64.grem.de> <51CC411C.4060105@FreeBSD.org> <20130627140428.GI91021@kib.kiev.ua> <20130827144507.385a552c@bsd64.grem.de> <20131130223427.3d95ae7c@bsd64.grem.de> <20131205170728.GF59496@kib.kiev.ua> <20131205182058.5479b1ff@bsd64.grem.de> <20131206032552.59672a5b@bsd64.grem.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5MTJTT7GctpGkbGB" Content-Disposition: inline In-Reply-To: <20131206032552.59672a5b@bsd64.grem.de> User-Agent: Mutt/1.5.22 (2013-10-16) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: David Chisnall , Brooks Davis , Dimitry Andric , Matthias Andree , "freebsd-ports@freebsd.org Ports" X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Dec 2013 03:21:22 -0000 --5MTJTT7GctpGkbGB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 06, 2013 at 03:25:52AM +0100, Michael Gmelin wrote: > I tested your patch on 10-BETA2 and 10-BETA3. I built our complete > production environment from scratch, ran a huge number of unit and > integration tests. Everything works as expected, including Ice's > "Schwarz Counter" implementation > (http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter). >=20 > So as far as I can tell this fixes the problem, while still > accomplishing the goals of r211706. Great, thank you. I think that the patch can be further simplified. From what I understand about __cxa_finalize(3) protocol, confirmed by LSB, __cxa_finalize(NULL) must only be called at the process exit, once. Than, libc can use the call as an indication of the final call to finalize, avoiding need for help from rtld. Please test the patch below. It is enough to rebuild libc only. diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c index 18c31c3..01d09fe 100644 --- a/lib/libc/stdlib/atexit.c +++ b/lib/libc/stdlib/atexit.c @@ -151,6 +151,8 @@ __cxa_atexit(void (*func)(void *), void *arg, void *dso) #pragma weak __pthread_cxa_finalize void __pthread_cxa_finalize(const struct dl_phdr_info *); =20 +static int global_exit; + /* * Call all handlers registered with __cxa_atexit for the shared * object owning 'dso'. Note: if 'dso' is NULL, then all remaining @@ -164,10 +166,12 @@ __cxa_finalize(void *dso) struct atexit_fn fn; int n, has_phdr; =20 - if (dso !=3D NULL) + if (dso !=3D NULL) { has_phdr =3D _rtld_addr_phdr(dso, &phdr_info); - else + } else { has_phdr =3D 0; + global_exit =3D 1; + } =20 _MUTEX_LOCK(&atexit_mutex); for (p =3D __atexit; p; p =3D p->next) { @@ -177,8 +181,9 @@ __cxa_finalize(void *dso) fn =3D p->fns[n]; if (dso !=3D NULL && dso !=3D fn.fn_dso) { /* wrong DSO ? */ - if (!has_phdr || !__elf_phdr_match_addr( - &phdr_info, fn.fn_ptr.cxa_func)) + if (!has_phdr || global_exit || + !__elf_phdr_match_addr(&phdr_info, + fn.fn_ptr.cxa_func)) continue; } /* @@ -200,6 +205,6 @@ __cxa_finalize(void *dso) if (dso =3D=3D NULL) _MUTEX_DESTROY(&atexit_mutex); =20 - if (has_phdr && &__pthread_cxa_finalize !=3D NULL) + if (has_phdr && !global_exit && &__pthread_cxa_finalize !=3D NULL) __pthread_cxa_finalize(&phdr_info); } --5MTJTT7GctpGkbGB Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQIcBAEBAgAGBQJSoUKmAAoJEJDCuSvBvK1BQgcP+wb7d/cD+Xkd3G9Qb+SjmkMH i0XdieA7m1gCCr0pV56gAWk8oTx/t56ZXtPsKWqNEporRylSamcYoViftpGoMjOm KnsGzenZqSSSjx2lCzwPZg155LWpfhf4KNHFne6HW9Y6Ro8fumGTRGJECQm98TXz frstB6RO9BtmO5Nx0tKkl3omxe3diOleVWS3nULy87B4WBBrGy6d8CJT/oorOjus YRcUbodNaHaTgfM/N8K+7cWcTwTJDIg7+Pnedvo658FkXLu3AD/9eC/7p0GghWHz o4zL7BV3mbBd7TazVnymEG8WFUSZfsBLIwUufaAV04jUUO5r34Dd2nrluPNvmV4p b0u7q5HYRo1mxVMWfrFU42OqxH3akXk/GvzMYTlknwgsStYNT/wC9f1xhV1v5Qpj fY6/B4e1sVQ21qpcBftOT+RHCmFeHNuhukZLGZZS/rXjEPDmx4FN+622Hrq87EYT ZfMlJi53NAwyKHlXH4iixFjNB2qx8y7SoNgYztnfxH1wT2I9+uIDF3bkEShJvKIo 0Og8c7oUOMMxmW/0AGs+ZSTtgjTNBJyzwaGksJ0lMib0Mohm/PrWcRX7rsiXiyhv 6AWmYYajCDaFjMRdQl2XWZUPdakOzJY9VNCambIRK5yQ7pi13EZ+KZu0jdkSu/JR CQ5rDzSIru2x6+rdV99x =KUP7 -----END PGP SIGNATURE----- --5MTJTT7GctpGkbGB--