diff --git a/CMakeLists.txt b/CMakeLists.txt index a4bde74..3dc5118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,7 @@ stacktrace_check(BOOST_STACKTRACE_HAS_WINDBG has_windbg.cpp "" "dbgeng;ole32" "" stacktrace_check(BOOST_STACKTRACE_HAS_WINDBG_CACHED has_windbg_cached.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../config/include" "dbgeng;ole32" "") set(_default_from_exception ON) -if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64|i386|i686|x86" OR CMAKE_CXX_PLATFORM_ID MATCHES "Cygwin") +if (CMAKE_CXX_PLATFORM_ID MATCHES "Cygwin") set(_default_from_exception OFF) endif() diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index a7e4615..0af76b9 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -249,8 +249,7 @@ rule build-stacktrace-from-exception ( props * ) case "off" : return no ; } - local arch = [ property.select : $(props) ] ; - if ( $(arch) && ( $(arch:G=) != x86 ) ) || ( cygwin in $(props) ) + if ( cygwin in $(props) ) { configure.log-library-search-result "boost.stacktrace.from_exception" : "no" ; return no ; diff --git a/src/from_exception.cpp b/src/from_exception.cpp index 366ba28..18f3001 100644 --- a/src/from_exception.cpp +++ b/src/from_exception.cpp @@ -160,29 +160,14 @@ BOOST_SYMBOL_EXPORT void assert_no_pending_traces() noexcept { #include #include + #if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING +#include +#include #include #include -#ifndef BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK - -#ifdef BOOST_HAS_THREADS - -#error On this platform memory leaks are possible if capturing stacktrace from \ - exceptions is enabled and exceptions are thrown concurrently \ - and libc++ runtime is used. \ - \ - Define `BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK` to \ - suppress this error if the library would not be used with libc++ \ - runtime (for example, it would be only used with GCC runtime). \ - \ - Otherwise, disable the boost_stacktrace_from_exception library build \ - (for example by `./b2 boost.stacktrace.from_exception=off` option). - -#endif - -#endif - +#include #endif namespace { @@ -297,6 +282,32 @@ void* __cxa_allocate_exception(size_t thrown_size) throw() { extern "C" BOOST_SYMBOL_EXPORT void __cxa_decrement_exception_refcount(void *thrown_object) throw() { BOOST_ASSERT(is_libcpp_runtime()); + +#if !defined(BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK) && defined(BOOST_HAS_THREADS) + static const char* leaks_are_fine = std::getenv("BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK"); + if (!leaks_are_fine || leaks_are_fine[0] != '1') { + const char* const warning = + "\n\n" + "=======================================================================================\n" + "\n" + "On this platform, memory leaks may occur if capturing stacktrace from exceptions is\n" + "enabled and exceptions are thrown concurrently by libc++ runtime (libc++abi).\n" + "\n" + "A proper workaround is to use libstdc++ runtime (libgcc_s) instead.\n" + "\n" + "Alternatively, if you are willing to accept potential MEMORY LEAKS, set the environment\n" + "variable `BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK=1` to proceed. You can\n" + "also define the `BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK` macro when\n" + "building the `boost_stacktrace_from_exception` library to disable this warning and to\n" + "get the MEMORY LEAKS silently on libc++ runtime.\n" + "\n" + "=======================================================================================\n" + ; + write(STDERR_FILENO, warning, std::strlen(warning)); + std::abort(); + } +#endif + if (!thrown_object) { return; }