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.
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*