From: Jonathan Wakely <jwakely@redhat.com>
To: Ville Voutilainen <ville.voutilainen@gmail.com>
Cc: Christophe Lyon <christophe.lyon@linaro.org>,
libstdc++ <libstdc++@gcc.gnu.org>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [v3 PATCH] PR libstdc++/77288 and the newest proposed resolution for LWG 2756
Date: Thu, 22 Sep 2016 11:38:00 -0000 [thread overview]
Message-ID: <20160922111506.GE17376@redhat.com> (raw)
In-Reply-To: <20160922101602.GY17376@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 593 bytes --]
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).
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 9380 bytes --]
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 <jwakely@redhat.com>
+ 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 <jwakely@redhat.com>
+
* 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 <bits/c++config.h>
#include <bits/atomic_lockfree_defines.h>
-#if ATOMIC_INT_LOCK_FREE > 1
-
#define _GLIBCXX_EH_PTR_COMPAT
#include <exception>
#include <bits/exception_ptr.h>
#include "unwind-cxx.h"
+#if ATOMIC_INT_LOCK_FREE < 2
+# include <ext/concurrence.h>
+# 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 <typeinfo>
#include <new>
-#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 <exception>
#include <testsuite_hooks.h>
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 <sebastian.redl@getdesigned.at>
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 <sebastian.redl@getdesigned.at>
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 <sebastian.redl@getdesigned.at>
next prev parent reply other threads:[~2016-09-22 11:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-23 14:17 Ville Voutilainen
2016-09-06 7:05 ` Ville Voutilainen
2016-09-21 9:43 ` Jonathan Wakely
2016-09-21 19:51 ` Ville Voutilainen
2016-09-22 9:01 ` Christophe Lyon
2016-09-22 9:21 ` Ville Voutilainen
2016-09-22 9:43 ` Christophe Lyon
2016-09-22 10:03 ` Ville Voutilainen
2016-09-22 10:36 ` Jonathan Wakely
2016-09-22 11:38 ` Jonathan Wakely [this message]
2016-09-22 13:32 ` Jonathan Wakely
2016-09-22 19:10 ` Christophe Lyon
2016-09-23 10:48 ` Jonathan Wakely
2016-09-27 0:22 ` Christophe Lyon
2016-09-22 20:32 ` Christophe Lyon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160922111506.GE17376@redhat.com \
--to=jwakely@redhat.com \
--cc=christophe.lyon@linaro.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=ville.voutilainen@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).