From 5571f56fe0ced1805110e06ac38d4fc8105c45cc Mon Sep 17 00:00:00 2001 From: Romain Geissler Date: Mon, 8 Dec 2025 16:03:24 +0000 Subject: [PATCH] Enable stack traces from exception on ARM by default if using libstdc++. We know the implementation works on any architecture if libstdc++ is used (leaks are with libc++). So enable it by default in that case, even if not using x86. --- CMakeLists.txt | 4 +++- build/Jamfile.v2 | 10 ++++++++-- build/uses_libstdc++.cpp | 15 +++++++++++++++ src/from_exception.cpp | 8 ++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 build/uses_libstdc++.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b95379..c50804f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,8 +71,10 @@ endif() 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" "") +stacktrace_check(BOOST_STACKTRACE_USES_LIBSTDCPP uses_libstdc++.cpp "" "" "") + set(_default_from_exception ON) -if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64|i386|i686|x86") +if ((NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64|i386|i686|x86") AND (NOT BOOST_STACKTRACE_USES_LIBSTDCPP)) set(_default_from_exception OFF) endif() diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 9a294bf..42c3930 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -64,6 +64,9 @@ explicit WinDbg ; mp-run-simple has_windbg_cached.cpp : : : Dbgeng ole32 : WinDbgCached ; explicit WinDbgCached ; +mp-run-simple uses_libstdc++.cpp : : : : UsesLibStdCpp ; +explicit UsesLibStdCpp ; + rule build-stacktrace-noop ( props * ) { local enabled = [ property.select : $(props) ] ; @@ -252,8 +255,11 @@ rule build-stacktrace-from-exception ( props * ) local arch = [ property.select : $(props) ] ; if $(arch) && ( $(arch:G=) != x86 ) { - configure.log-library-search-result "boost.stacktrace.from_exception" : "no" ; - return no ; + if ! [ configure.builds UsesLibStdCpp : $(props) : "boost.stacktrace.from_exception" ] + { + configure.log-library-search-result "boost.stacktrace.from_exception" : "no" ; + return no ; + } } configure.log-library-search-result "boost.stacktrace.from_exception" : "yes" ; } diff --git a/build/uses_libstdc++.cpp b/build/uses_libstdc++.cpp new file mode 100644 index 0000000..9aae4b3 --- /dev/null +++ b/build/uses_libstdc++.cpp @@ -0,0 +1,15 @@ +// Copyright Romain Geissler, 2025. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +int main() { +#ifdef __GLIBCXX__ + return 0; +#else +#error "The C++ runtime library isn't libstdc++" +#endif +} diff --git a/src/from_exception.cpp b/src/from_exception.cpp index 366ba28..3e36def 100644 --- a/src/from_exception.cpp +++ b/src/from_exception.cpp @@ -164,6 +164,12 @@ BOOST_SYMBOL_EXPORT void assert_no_pending_traces() noexcept { #include #include +// If we use libstdc++, we know the current implementation works and doesn't leak. +// It's not the case of libc++ where we know there might be leaks and thus we try +// to ensure the user is aware about it and only build this when +// BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK is defined. +#ifndef __GLIBCXX__ + #ifndef BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK #ifdef BOOST_HAS_THREADS @@ -185,6 +191,8 @@ BOOST_SYMBOL_EXPORT void assert_no_pending_traces() noexcept { #endif +#endif + namespace { constexpr std::size_t kStacktraceDumpSize = 4096;