From owner-freebsd-current@FreeBSD.ORG Fri Dec 7 12:59:04 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 1326C366 for ; Fri, 7 Dec 2012 12:59:04 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (cl-327.ede-01.nl.sixxs.net [IPv6:2001:7b8:2ff:146::2]) by mx1.freebsd.org (Postfix) with ESMTP id C474B8FC0C for ; Fri, 7 Dec 2012 12:59:03 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7:0:7cf2:29c9:3fd9:2525] (unknown [IPv6:2001:7b8:3a7:0:7cf2:29c9:3fd9:2525]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 2B3345C37; Fri, 7 Dec 2012 13:59:02 +0100 (CET) Message-ID: <50C1E81A.1040107@FreeBSD.org> Date: Fri, 07 Dec 2012 13:59:06 +0100 From: Dimitry Andric Organization: The FreeBSD Project User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20121128 Thunderbird/18.0 MIME-Version: 1.0 To: Mark Atkinson Subject: Re: problems with threads/destructors in -current with llvm/clang References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kde-freebsd@kde.org, freebsd-current@FreeBSD.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 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: Fri, 07 Dec 2012 12:59:04 -0000 On 2012-12-06 18:12, Mark Atkinson wrote: > Short backstory, I had recently upgraded my workstation to the latest > current which included clang as default cc now. ... > qdbus under kde segfaults in malloc with a huge recursion stack: > > [...] > #44740 0x282f7bd4 in QObject::QObject () from > /usr/local/lib/qt4/libQtCore.so.4 > #44741 0x281cb649 in QAdoptedThread::QAdoptedThread () from > /usr/local/lib/qt4/libQtCore.so.4 > #44742 0x281ce146 in QThreadData::current () from > /usr/local/lib/qt4/libQtCore.so.4 > #44743 0x282f7bd4 in QObject::QObject () from > /usr/local/lib/qt4/libQtCore.so.4 > #44744 0x281cb649 in QAdoptedThread::QAdoptedThread () from > /usr/local/lib/qt4/libQtCore.so.4 > #44745 0x281ce146 in QThreadData::current () from > /usr/local/lib/qt4/libQtCore.so.4 > #44746 0x282f7bd4 in QObject::QObject () from > /usr/local/lib/qt4/libQtCore.so.4 > #44747 0x281cb649 in QAdoptedThread::QAdoptedThread () from > /usr/local/lib/qt4/libQtCore.so.4 > #44748 0x281ce146 in QThreadData::current () from > /usr/local/lib/qt4/libQtCore.so.4 > #44749 0x281cbc05 in QThread::currentThread () from > /usr/local/lib/qt4/libQtCore.so.4 > #44750 0x28095d21 in QDBusConnectionPrivate::deleteYourself () from > /usr/local/lib/qt4/libQtDBus.so.4 > #44751 0x28089634 in QDBusConnection::~QDBusConnection () from > /usr/local/lib/qt4/libQtDBus.so.4 > #44752 0x0804b800 in __dtor__ZL10connection () > #44753 0x28660417 in __cxa_finalize () from /lib/libc.so.7 > #44754 0x2860747a in exit () from /lib/libc.so.7 > #44755 0x0804c125 in main () > (gdb) This is a bug in qdbus; it uses a global static QDBusConnection object, and the order in which global destructors are called is undefined: http://qt.gitorious.org/qt/qttools/blobs/stable/src/qdbus/qdbus/qdbus.cpp#line57 In this particular case, the destructor (__dtor__ZL10connection) is called *after* all of Qt's internal stuff has already been destroyed: - QDBusConnectionPrivate::deleteYourself() tries to figure out if it is called from the current QThread, and calls QThread::currentThread() - QThread::currentThread() calls QThreadData::current() - QThreadData::current() tries to instantiate a QAdoptedThread - QAdoptedThread descends from QObject, so calls QObject::QObject() - QObject::QObject() calls QThreadData::current() - Endless loop results, until the stack is blown, and a new operator fails in malloc() The global static QDBusConnection object should be replaced by a singleton, as suggested here: http://techbase.kde.org/Policies/Library_Code_Policy#Static_Objects but I am not sure how that is normally done in Qt itself.