Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 07 Dec 2012 13:59:06 +0100
From:      Dimitry Andric <dim@FreeBSD.org>
To:        Mark Atkinson <atkin901@gmail.com>
Cc:        kde-freebsd@kde.org, freebsd-current@FreeBSD.org
Subject:   Re: problems with threads/destructors in -current with llvm/clang
Message-ID:  <50C1E81A.1040107@FreeBSD.org>
In-Reply-To: <k9qjml$ri7$1@ger.gmane.org>
References:  <k9qjml$ri7$1@ger.gmane.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50C1E81A.1040107>