diff --git a/lib/trace/CMakeLists.txt b/lib/trace/CMakeLists.txt index ec78c2e90..e75866bbe 100644 --- a/lib/trace/CMakeLists.txt +++ b/lib/trace/CMakeLists.txt @@ -18,7 +18,7 @@ if (NOT IMHEX_DISABLE_STACKTRACE) } " HAVE_STDCPPEXP) if (HAVE_STDCPPEXP) - target_link_libraries(tracing PRIVATE stdc++exp) + target_link_libraries(tracing PUBLIC stdc++exp) endif() if (WIN32) @@ -49,6 +49,7 @@ endif() if (IMHEX_TRACE_EXCEPTIONS) if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_link_options(tracing PUBLIC "-Wl,--wrap=__cxa_throw") + target_compile_definitions(tracing PRIVATE HEX_WRAP_CXA_THROW) elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Not supported currently endif() diff --git a/lib/trace/source/exceptions.cpp b/lib/trace/source/exceptions.cpp index a15882947..dc78e6e20 100644 --- a/lib/trace/source/exceptions.cpp +++ b/lib/trace/source/exceptions.cpp @@ -15,13 +15,16 @@ namespace hex::trace { } -extern "C" { +#if defined(HEX_WRAP_CXA_THROW) + + extern "C" { + + [[noreturn]] void __real___cxa_throw(void* thrownException, void* type, void (*destructor)(void*)); + [[noreturn]] void __wrap___cxa_throw(void* thrownException, void* type, void (*destructor)(void*)) { + hex::trace::s_lastExceptionStackTrace = hex::trace::getStackTrace(); + __real___cxa_throw(thrownException, type, destructor); + } - [[noreturn]] void __real___cxa_throw(void* thrownException, void* type, void (*destructor)(void*)); - [[noreturn]] void __wrap___cxa_throw(void* thrownException, void* type, void (*destructor)(void*)) { - hex::trace::s_lastExceptionStackTrace = hex::trace::getStackTrace(); - __real___cxa_throw(thrownException, type, destructor); } -} - +#endif \ No newline at end of file