From owner-freebsd-current@FreeBSD.ORG Sun May 20 17:24:29 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9620E1065673; Sun, 20 May 2012 17:24:29 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 316488FC17; Sun, 20 May 2012 17:24:29 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q4KHOKCP000496; Sun, 20 May 2012 20:24:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q4KHOJE8007227; Sun, 20 May 2012 20:24:19 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q4KHOJq5007226; Sun, 20 May 2012 20:24:19 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 20 May 2012 20:24:19 +0300 From: Konstantin Belousov To: Alberto Villa Message-ID: <20120520172419.GQ2358@deviant.kiev.zoral.com.ua> References: <4F9E9E06.4070004@entel.upc.edu> <4FB88925.4070008@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="C6e6/dnRACxPVebH" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: Gustau P?rez i Querol , davidxu@freebsd.org, FreeBSD current Subject: Re: RFC: jemalloc: qdbus sigsegv in malloc_init X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 May 2012 17:24:29 -0000 --C6e6/dnRACxPVebH Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, May 20, 2012 at 06:42:35PM +0200, Alberto Villa wrote: > On Sun, May 20, 2012 at 8:03 AM, David Xu wrote: > > qdbus segfaults on my machine too, I tracked it down, and found the pro= blem > > is in QT, > > it deleted current_thread_data_key, =9Abut it still uses it in some cxa= hooks, > > =9AI =9Aapplied the > > following patch, =9Aand it works fine. >=20 > Thanks for the analysis David! >=20 > > I think the bug depends on linking order in QT library ? if the > > qthread_unix.cpp is linked > > as lastest module, the key will be deleted after all cxa hooks run, the= n it > > will be fine, > > otherwise, it would crash. >=20 > Is this really possible? No, I do not think it is possible. The only possibility for something weird happen is for atexit/__cxa_atexit functions to be registered from another atexit function, and then we indeed could call the newly registered function too late. I wonder if the following hack makes any change in the observed behaviour. diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c index 511172a..bab850c 100644 --- a/lib/libc/stdlib/atexit.c +++ b/lib/libc/stdlib/atexit.c @@ -72,6 +72,7 @@ struct atexit { }; =20 static struct atexit *__atexit; /* points to head of LIFO stack */ +static int atexit_gen; =20 /* * Register the function described by 'fptr' to be called at application @@ -107,6 +108,7 @@ atexit_register(struct atexit_fn *fptr) __atexit =3D p; } p->fns[p->ind++] =3D *fptr; + atexit_gen++; _MUTEX_UNLOCK(&atexit_mutex); return 0; } @@ -162,7 +164,7 @@ __cxa_finalize(void *dso) struct dl_phdr_info phdr_info; struct atexit *p; struct atexit_fn fn; - int n, has_phdr; + int atexit_gen_prev, n, has_phdr; =20 if (dso !=3D NULL) has_phdr =3D _rtld_addr_phdr(dso, &phdr_info); @@ -170,6 +172,8 @@ __cxa_finalize(void *dso) has_phdr =3D 0; =20 _MUTEX_LOCK(&atexit_mutex); +retry: + atexit_gen_prev =3D atexit_gen; for (p =3D __atexit; p; p =3D p->next) { for (n =3D p->ind; --n >=3D 0;) { if (p->fns[n].fn_type =3D=3D ATEXIT_FN_EMPTY) @@ -196,6 +200,8 @@ __cxa_finalize(void *dso) _MUTEX_LOCK(&atexit_mutex); } } + if (atexit_gen_prev !=3D atexit_gen) + goto retry; _MUTEX_UNLOCK(&atexit_mutex); if (dso =3D=3D NULL) _MUTEX_DESTROY(&atexit_mutex); --C6e6/dnRACxPVebH Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk+5KMMACgkQC3+MBN1Mb4hhIQCggOABVLx50dsA6zR2fLhSZPP1 VjEAoNAzx3cYxtZc/EwJJPma2ENeO102 =wMAk -----END PGP SIGNATURE----- --C6e6/dnRACxPVebH--