Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions build/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ rule build-stacktrace-from-exception ( props * )
case "off" : return <build>no ;
}

local arch = [ property.select <architecture> : $(props) ] ;
if ( $(arch) && ( $(arch:G=) != x86 ) ) || ( <target-os>cygwin in $(props) )
if ( <target-os>cygwin in $(props) )
{
configure.log-library-search-result "boost.stacktrace.from_exception" : "no" ;
return <build>no ;
Expand Down
49 changes: 30 additions & 19 deletions src/from_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,14 @@ BOOST_SYMBOL_EXPORT void assert_no_pending_traces() noexcept {
#include <exception>
#include <dlfcn.h>


#if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING
#include <cstdlib>
#include <cstring>
#include <mutex>
#include <unordered_map>

#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 <unistd.h>
#endif

namespace {
Expand Down Expand Up @@ -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;
}
Expand Down