From patchwork Fri Dec 23 15:57:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 133090 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 797C3B71C4 for ; Sat, 24 Dec 2011 02:58:02 +1100 (EST) Received: (qmail 2111 invoked by alias); 23 Dec 2011 15:58:00 -0000 Received: (qmail 2101 invoked by uid 22791); 23 Dec 2011 15:57:56 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID X-Spam-Check-By: sourceware.org Received: from relay01ant.iops.be (HELO relay01ant.iops.be) (212.53.4.34) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 23 Dec 2011 15:57:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by relay01ant.iops.be (Postfix) with ESMTP id 3990E2090B; Fri, 23 Dec 2011 16:57:37 +0100 (CET) Received: from relay01ant.iops.be ([127.0.0.1]) by localhost (bdell034.dcn.iops.be [127.0.0.1]) (amavisd-new, port 10026) with LMTP id L-bdborOQb19; Fri, 23 Dec 2011 16:57:34 +0100 (CET) Received: from linux.localnet (cust-168-39-110-94.dyn.as47377.net [94.110.39.168]) by relay01ant.iops.be (Postfix) with ESMTP id 4287320938; Fri, 23 Dec 2011 16:57:32 +0100 (CET) From: Bart Van Assche To: gcc-patches@gcc.gnu.org Cc: Paolo Carlini , Konstantin Serebryany Subject: [PATCH] libstdc++: Make it possible to annotate the shared pointer operations in the std::thread implementation Date: Fri, 23 Dec 2011 15:57:32 +0000 Message-ID: <33987586.92vJibue4B@linux> User-Agent: KMail/4.7.2 (Linux/3.1.6+; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org As documented in the libstdc++ manual, the shared pointer operations in libstdc++ headers can be instrumented by defining the macros _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE()/AFTER() and libstdc++ has to be rebuilt in order to instrument the remaining shared pointer operations. However, rebuilding libstdc++ is inconvenient. So let's move the thread wrapper code from thread.cc into . See also: * http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html. * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51504. Signed-off-by: Bart Van Assche Index: libstdc++-v3/src/thread.cc =================================================================== --- libstdc++-v3/src/thread.cc (revision 182271) +++ libstdc++-v3/src/thread.cc (working copy) @@ -59,28 +59,6 @@ static inline int get_nprocs() namespace std _GLIBCXX_VISIBILITY(default) { - namespace - { - extern "C" void* - execute_native_thread_routine(void* __p) - { - thread::_Impl_base* __t = static_cast(__p); - thread::__shared_base_type __local; - __local.swap(__t->_M_this_ptr); - - __try - { - __t->_M_run(); - } - __catch(...) - { - std::terminate(); - } - - return 0; - } - } - _GLIBCXX_BEGIN_NAMESPACE_VERSION void @@ -114,12 +92,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void thread::_M_start_thread(__shared_base_type __b) { + _M_start_thread(__b, &_M_entry); + } + + void + thread::_M_start_thread(__shared_base_type __b, void* (*__pf)(void*)) + { if (!__gthread_active_p()) __throw_system_error(int(errc::operation_not_permitted)); __b->_M_this_ptr = __b; - int __e = __gthread_create(&_M_id._M_thread, - &execute_native_thread_routine, __b.get()); + int __e = __gthread_create(&_M_id._M_thread, __pf, __b.get()); if (__e) { __b->_M_this_ptr.reset(); Index: libstdc++-v3/include/std/thread =================================================================== --- libstdc++-v3/include/std/thread (revision 182271) +++ libstdc++-v3/include/std/thread (working copy) @@ -132,7 +132,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _M_start_thread(_M_make_routine(std::__bind_simple( std::forward<_Callable>(__f), - std::forward<_Args>(__args)...))); + std::forward<_Args>(__args)...)), + &thread::_M_entry); } ~thread() @@ -180,9 +181,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION hardware_concurrency() noexcept; private: + static void* _M_entry(void* __p) + { + thread::_Impl_base* __t = static_cast(__p); + thread::__shared_base_type __local; + __local.swap(__t->_M_this_ptr); + + __try + { + __t->_M_run(); + } + __catch(...) + { + std::terminate(); + } + + return 0; + } + void _M_start_thread(__shared_base_type); + void + _M_start_thread(__shared_base_type, void* (*)(void*)); + template shared_ptr<_Impl<_Callable>> _M_make_routine(_Callable&& __f) Index: libstdc++-v3/config/abi/post/s390-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/s390-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/s390-linux-gnu/baseline_symbols.txt (working copy) @@ -2145,6 +2145,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/x86_64-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/x86_64-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/x86_64-linux-gnu/baseline_symbols.txt (working copy) @@ -1955,6 +1955,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/ia64-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/ia64-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/ia64-linux-gnu/baseline_symbols.txt (working copy) @@ -1852,6 +1852,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/sparc-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/sparc-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/sparc-linux-gnu/baseline_symbols.txt (working copy) @@ -2145,6 +2145,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structj@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/powerpc-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/powerpc-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/powerpc-linux-gnu/baseline_symbols.txt (working copy) @@ -2145,6 +2145,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structj@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/mips64-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/mips64-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/mips64-linux-gnu/baseline_symbols.txt (working copy) @@ -1852,6 +1852,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structj@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/alpha-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/alpha-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/alpha-linux-gnu/baseline_symbols.txt (working copy) @@ -2145,6 +2145,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/s390x-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/s390x-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/s390x-linux-gnu/baseline_symbols.txt (working copy) @@ -2145,6 +2145,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/i386-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/i386-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/i386-linux-gnu/baseline_symbols.txt (working copy) @@ -1955,6 +1955,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structj@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt (working copy) @@ -2145,6 +2145,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/solaris2.10/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/solaris2.10/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/solaris2.10/baseline_symbols.txt (working copy) @@ -1920,6 +1920,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EPij@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/post/i486-linux-gnu/baseline_symbols.txt =================================================================== --- libstdc++-v3/config/abi/post/i486-linux-gnu/baseline_symbols.txt (revision 182271) +++ libstdc++-v3/config/abi/post/i486-linux-gnu/baseline_symbols.txt (working copy) @@ -1955,6 +1955,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4 FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4 FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11 +FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17 FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11 FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11 FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structj@@GLIBCXX_3.4 Index: libstdc++-v3/config/abi/pre/gnu.ver =================================================================== --- libstdc++-v3/config/abi/pre/gnu.ver (revision 182271) +++ libstdc++-v3/config/abi/pre/gnu.ver (working copy) @@ -1307,6 +1307,9 @@ GLIBCXX_3.4.17 { # std::wstring::pop_back() _ZNSbIwSt11char_traitsIwESaIwEE8pop_backEv; + # std::thread + _ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E; + } GLIBCXX_3.4.16; # Symbols in the support library (libsupc++) have their own tag.