From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 77229 invoked by alias); 22 Sep 2016 11:15:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 75614 invoked by uid 89); 22 Sep 2016 11:15:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:dgrequ, sk:dg-requ X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Sep 2016 11:15:08 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 375D0C04B95C; Thu, 22 Sep 2016 11:15:07 +0000 (UTC) Received: from localhost (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8MBF6VO019459; Thu, 22 Sep 2016 07:15:06 -0400 Date: Thu, 22 Sep 2016 11:38:00 -0000 From: Jonathan Wakely To: Ville Voutilainen Cc: Christophe Lyon , libstdc++ , "gcc-patches@gcc.gnu.org" Subject: Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756 Message-ID: <20160922111506.GE17376@redhat.com> References: <20160921093115.GI17376@redhat.com> <20160922101602.GY17376@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2WS97oupGEGbYNpW" Content-Disposition: inline In-Reply-To: <20160922101602.GY17376@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) X-SW-Source: 2016-09/txt/msg01528.txt.bz2 --2WS97oupGEGbYNpW Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 593 On 22/09/16 11:16 +0100, Jonathan Wakely wrote: >(Somebody should fix PR58938 so exception_ptr is portable). Christophe, would you be able to test this patch? It uses a single global mutex for exception_ptr objects, which doesn't scale well but that probably isn't a problem for processors without lock-free atomics for single words. This also solves the problem of mismatched -march options, where the header is compiled for a CPU that supports the atomics but libstdc++.so was built for an older CPU that doesn't support them, and linking fails (as in https://gcc.gnu.org/PR58938#c13). --2WS97oupGEGbYNpW Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 9380 diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e9bb0ce..363900a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,26 @@ 2016-09-22 Jonathan Wakely + PR libstdc++/58938 + * libsupc++/eh_ptr.cc [ATOMIC_INT_LOCK_FREE < 2] (eh_ptr_mutex) + (exception_ptr::_M_addref, exception_ptr::_M_release): Use mutex if + atomic builtins not available. + * libsupc++/exception_ptr.h [ATOMIC_INT_LOCK_FREE < 2]: Remove #error. + * testsuite/18_support/exception_ptr/40296.cc: Remove + dg-require-atomic-builtins directive. + * testsuite/18_support/exception_ptr/60612-terminate.cc: Likewise. + * testsuite/18_support/exception_ptr/60612-unexpected.cc: Likewise. + * testsuite/18_support/exception_ptr/62258.cc: Likewise. + * testsuite/18_support/exception_ptr/64241.cc: Likewise. + * testsuite/18_support/exception_ptr/current_exception.cc: Likewise. + * testsuite/18_support/exception_ptr/lifespan.cc: Likewise. + * testsuite/18_support/exception_ptr/make_exception_ptr.cc: Likewise. + * testsuite/18_support/exception_ptr/move.cc: Likewise. + * testsuite/18_support/exception_ptr/requirements.cc: Likewise. + * testsuite/18_support/exception_ptr/requirements_neg.cc: Likewise. + * testsuite/18_support/exception_ptr/rethrow_exception.cc: Likewise. + +2016-09-22 Jonathan Wakely + * python/libstdcxx/v6/printers.py (StdVariantPrinter): Adjust for recent change to _Variant_storage. * testsuite/libstdc++-prettyprinters/cxx17.cc: Test variant with diff --git a/libstdc++-v3/libsupc++/eh_ptr.cc b/libstdc++-v3/libsupc++/eh_ptr.cc index 3b8e0a01..ac4e375 100644 --- a/libstdc++-v3/libsupc++/eh_ptr.cc +++ b/libstdc++-v3/libsupc++/eh_ptr.cc @@ -25,14 +25,23 @@ #include #include -#if ATOMIC_INT_LOCK_FREE > 1 - #define _GLIBCXX_EH_PTR_COMPAT #include #include #include "unwind-cxx.h" +#if ATOMIC_INT_LOCK_FREE < 2 +# include +# define USE_EH_PTR_MUTEX +static inline __gnu_cxx::__mutex& eh_ptr_mutex() +{ + static __gnu_cxx::__mutex mx; + return mx; +} +using __gnu_cxx::__scoped_lock; +#endif + using namespace __cxxabiv1; // Verify assumptions about member layout in exception types @@ -103,7 +112,12 @@ std::__exception_ptr::exception_ptr::_M_addref() _GLIBCXX_USE_NOEXCEPT { __cxa_refcounted_exception *eh = __get_refcounted_exception_header_from_obj (_M_exception_object); +#ifdef USE_EH_PTR_MUTEX + __scoped_lock lock(eh_ptr_mutex()); + ++eh->referenceCount; +#else __atomic_add_fetch (&eh->referenceCount, 1, __ATOMIC_ACQ_REL); +#endif } } @@ -115,7 +129,12 @@ std::__exception_ptr::exception_ptr::_M_release() _GLIBCXX_USE_NOEXCEPT { __cxa_refcounted_exception *eh = __get_refcounted_exception_header_from_obj (_M_exception_object); +#ifdef USE_EH_PTR_MUTEX + auto count = (__scoped_lock(eh_ptr_mutex()), --eh->referenceCount); + if (count == 0) +#else if (__atomic_sub_fetch (&eh->referenceCount, 1, __ATOMIC_ACQ_REL) == 0) +#endif { if (eh->exc.exceptionDestructor) eh->exc.exceptionDestructor (_M_exception_object); @@ -260,5 +279,3 @@ std::rethrow_exception(std::exception_ptr ep) } #undef _GLIBCXX_EH_PTR_COMPAT - -#endif diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h index 21e4e8b..ae8fb1f5 100644 --- a/libstdc++-v3/libsupc++/exception_ptr.h +++ b/libstdc++-v3/libsupc++/exception_ptr.h @@ -39,10 +39,6 @@ #include #include -#if ATOMIC_INT_LOCK_FREE < 2 -# error This platform does not support exception propagation. -#endif - extern "C++" { namespace std diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc index 74307cc..a6659b8 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2009-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc index c00e287..d58f32d 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-terminate.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2014-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc index 2b5ec2d..cfaea5d4 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/60612-unexpected.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2014-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc index c83d5fb..5c15b48 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2015-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc index fbb01ae..b7352ed 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc @@ -17,7 +17,6 @@ // { dg-options "-fno-exceptions -O0" } // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } #include #include diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc index 2383cee..02bcd27 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // 2008-05-25 Sebastian Redl diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc index e350df3..5c8cb11 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // 2008-05-25 Sebastian Redl diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/make_exception_ptr.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/make_exception_ptr.cc index b496bb3..b9538e6 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/make_exception_ptr.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/make_exception_ptr.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2010-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/move.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/move.cc index 6318bc4..80c6e3e 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/move.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/move.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2009-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc index b3b9e0c..5f5f054 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2010-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc index b80d688..95ec8ab 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++11 } } -// { dg-require-atomic-builtins "" } // Copyright (C) 2010-2016 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc index f0b61b1..c3ce206 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc @@ -1,5 +1,4 @@ // { dg-do run { target c++11 } } -// { dg-require-atomic-builtins "" } // 2008-05-25 Sebastian Redl --2WS97oupGEGbYNpW--