public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
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 13:32:00 -0000	[thread overview]
Message-ID: <20160922132502.GF17376@redhat.com> (raw)
In-Reply-To: <20160922111506.GE17376@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1180 bytes --]

On 22/09/16 12:15 +0100, Jonathan Wakely wrote:
>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).

We'd also need something like this extra piece, to ensure we don't
leak exceptions. Currently __gxx_exception_cleanup assumes that if
ATOMIC_INT_LOCK_FREE < 2 the referenceCount can never be greater than
1, because there are not exception_ptr objects that could increase it.

If we enable exception_ptr unconditionally then that assumption
doesn't hold. This patch uses the exception_ptr code to do the
cleanup, under the same mutex as any other increments and decrements
of the reference count.

It's a bit of a hack though.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2144 bytes --]

diff --git a/libstdc++-v3/libsupc++/Makefile.am b/libstdc++-v3/libsupc++/Makefile.am
index 2df31ff..dbfd00f 100644
--- a/libstdc++-v3/libsupc++/Makefile.am
+++ b/libstdc++-v3/libsupc++/Makefile.am
@@ -155,9 +155,9 @@ eh_terminate.o: eh_terminate.cc
 	$(CXXCOMPILE) -std=gnu++11 -c $<
 
 eh_throw.lo: eh_throw.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -c $<
+	$(LTCXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 eh_throw.o: eh_throw.cc
-	$(CXXCOMPILE) -std=gnu++11 -c $<
+	$(CXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 
 guard.lo: guard.cc
 	$(LTCXXCOMPILE) -std=gnu++11 -c $<
diff --git a/libstdc++-v3/libsupc++/Makefile.in b/libstdc++-v3/libsupc++/Makefile.in
index e828ed9..f3e2193 100644
--- a/libstdc++-v3/libsupc++/Makefile.in
+++ b/libstdc++-v3/libsupc++/Makefile.in
@@ -884,9 +884,9 @@ eh_terminate.o: eh_terminate.cc
 	$(CXXCOMPILE) -std=gnu++11 -c $<
 
 eh_throw.lo: eh_throw.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -c $<
+	$(LTCXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 eh_throw.o: eh_throw.cc
-	$(CXXCOMPILE) -std=gnu++11 -c $<
+	$(CXXCOMPILE) -std=gnu++11 -fno-access-control -c $<
 
 guard.lo: guard.cc
 	$(LTCXXCOMPILE) -std=gnu++11 -c $<
diff --git a/libstdc++-v3/libsupc++/eh_throw.cc b/libstdc++-v3/libsupc++/eh_throw.cc
index a05f4eb..0f61fbf 100644
--- a/libstdc++-v3/libsupc++/eh_throw.cc
+++ b/libstdc++-v3/libsupc++/eh_throw.cc
@@ -24,6 +24,7 @@
 
 #include <bits/c++config.h>
 #include "unwind-cxx.h"
+#include "exception_ptr.h"
 
 using namespace __cxxabiv1;
 
@@ -42,17 +43,8 @@ __gxx_exception_cleanup (_Unwind_Reason_Code code, _Unwind_Exception *exc)
   if (code != _URC_FOREIGN_EXCEPTION_CAUGHT && code != _URC_NO_REASON)
     __terminate (header->exc.terminateHandler);
 
-#if ATOMIC_INT_LOCK_FREE > 1
-  if (__atomic_sub_fetch (&header->referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
-    {
-#endif
-      if (header->exc.exceptionDestructor)
-	header->exc.exceptionDestructor (header + 1);
-
-      __cxa_free_exception (header + 1);
-#if ATOMIC_INT_LOCK_FREE > 1
-    }
-#endif
+  std::__exception_ptr::exception_ptr ptr;
+  ptr._M_exception_object = header + 1;
 }
 
 extern "C" __cxa_refcounted_exception*

  reply	other threads:[~2016-09-22 13:25 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
2016-09-22 13:32                   ` Jonathan Wakely [this message]
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=20160922132502.GF17376@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).