Repository navigation
Do not require the patched libc++ to compile Common/Exception.cpp - #112865
Conversation
`Exception.cpp` opens with `static_assert(STD_EXCEPTION_HAS_STACK_TRACE == 1)`, and that macro comes from ClickHouse's patched libc++ in `contrib/libcxx-cmake`. A build linking any other C++ standard library cannot compile the file at all - and it is not only the assert: six places call `std::exception::get_stack_trace_frames`, which only the patched libc++ has. `utils/wasm-parser` works around this by leaving `Exception.cpp` out of its build entirely and substituting stubs. Move the two operations - reading the throw-site trace, and adopting one exception's trace as another's - behind `getStackTraceOfThrow` and `copyStackTraceOfThrow` in `Common/StackTrace.h`, so exactly one place has to know whether the standard library records a trace at all. `base/defines.h` defaults `STD_EXCEPTION_HAS_STACK_TRACE` to 0 when it is absent. This stays fail-closed. Every currently supported platform builds `contrib/libcxx-cmake` - `cmake/cxx.cmake` is included by every `cmake/*/default_libs.cmake` - so `Exception.cpp` still hard-asserts the macro is 1 on Linux, Darwin, FreeBSD and SunOS. Losing the definition there would silently strip the stack trace from every exception, and it still cannot happen. As a side effect this removes six copies of the same `get_stack_trace_frames`/`get_stack_trace_size`/`__msan_unpoison` incantation. No behaviour change: the refactored build produces byte-identical symbolized stack traces, and `system.errors.last_error_trace` is populated exactly as before. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [18a7708] Summary: ✅
AI ReviewSummaryThis PR centralizes the optional embedded-exception stack-trace handling behind Findings
Final VerdictStatus:
|
| __msan_unpoison(stack_trace_frames, stack_trace_size * sizeof(stack_trace_frames[0])); | ||
| return StackTrace::toString(stack_trace_frames, 0, stack_trace_size); | ||
| const auto trace = getStackTraceOfThrow(e); | ||
| return StackTrace::toString(trace.data(), 0, trace.size()); |
There was a problem hiding this comment.
On the new STD_EXCEPTION_HAS_STACK_TRACE=0 path, getStackTraceOfThrow returns an empty span here, but StackTrace::toString(nullptr, 0, 0) does not return an empty string: it formats <Empty trace> in StackTrace.cpp. That leaks into every caller that uses this helper, so the fallback build now emits a fake "Stack trace" section instead of behaving like "no throw-site stack trace", and log fields that expect an absent trace get the literal placeholder text instead. Please special-case trace.empty() here (and in Exception::getStackTraceString) so the new build mode degrades cleanly instead of producing misleading diagnostics.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 27/35 (77.14%) · Uncovered code |
Exception.cppopens withstatic_assert(STD_EXCEPTION_HAS_STACK_TRACE == 1), and that macro comes from ClickHouse's patched libc++ incontrib/libcxx-cmake. A build linking any other C++ standard library cannot compile the file at all - and it is not only the assert: six places callstd::exception::get_stack_trace_frames, which only the patched libc++ has.utils/wasm-parserworks around this today by leavingException.cppout of its build entirely and substituting stubs.This moves the two operations - reading the throw-site trace, and adopting one exception's trace as another's - behind
getStackTraceOfThrowandcopyStackTraceOfThrowinCommon/StackTrace.h, so exactly one place has to know whether the standard library records a trace at all.base/defines.hdefaultsSTD_EXCEPTION_HAS_STACK_TRACEto 0 when it is absent.It stays fail-closed. Every currently supported platform builds
contrib/libcxx-cmake-cmake/cxx.cmakeis included by everycmake/*/default_libs.cmake- soException.cppstill hard-asserts the macro is 1 on Linux, Darwin, FreeBSD and SunOS. Losing the definition there would silently strip the stack trace from every exception, and it still cannot happen.As a side effect this removes six copies of the same
get_stack_trace_frames/get_stack_trace_size/__msan_unpoisonincantation.No behaviour change. Checked against a build of the same commit without the change: identical symbolized stack traces for a thrown
DB::Exception, for thePoco::Exceptionconversion path and for thestd::exceptionconversion path, andsystem.errors.last_error_tracepopulated the same way.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Common/Exception.cppno longer requires ClickHouse's patched libc++ to compile, so a build linking a different C++ standard library gets exceptions without a throw-site stack trace rather than not compiling.Documentation entry for user-facing changes