Closed wesleywiser closed 10 months ago
Code size changes for a hello-world Rust program linked with libstd with backtrace:
On platform ubuntu-latest
:
On platform windows-latest
:
Code size changes for a hello-world Rust program linked with libstd with backtrace:
On platform ubuntu-latest
:
On platform windows-latest
:
Code size changes for a hello-world Rust program linked with libstd with backtrace:
On platform ubuntu-latest
:
On platform windows-latest
:
Code size changes for a hello-world Rust program linked with libstd with backtrace:
On platform ubuntu-latest
:
On platform windows-latest
:
This will also fix https://github.com/rust-lang/rust/issues/116403 by virtue of not using dbghelp.dll
during the initial backtrace capture.
Currently, capturing the stack backtrace is done on Windows by calling into
dbghelp!StackWalkEx
(ordbghelp!StackWalk64
if the version ofdbghelp
we loaded is too old to contain that function). This is very convenient sinceStackWalkEx
handles everything for us but there are two issues with doing so:dbghelp
is not safe to use from multiple threads at the same time so all calls into it must be serialized.StackWalkEx
returns inlined frames as if they were regular stack frames which requires loading debug info just to walk the stack. As a result, simply capturing a backtrace without resolving it is much more expensive on Windows than *nix.This change rewrites our Windows support to call
RtlVirtualUnwind
instead on platforms which support this API (x86_64
andaarch64
). This API walks the actual (ie, not inlined) stack frames so it does not require loading any debug info and is significantly faster. For platforms that do not supportRtlVirtualUnwind
(ie,i686
), we fall back to the current implementation which calls intodbghelp
.To recover the inlined frame information when we are asked to resolve symbols, we use
SymAddrIncludeInlineTrace
to load debug info and detect inlined frames and thenSymQueryInlineTrace
to get the appropriate inline context to resolve them.The result is significant performance improvements to backtrace capture and symbolizing on Windows!
Before:
After:
The changes to the symbolize step also allow us to report inlined frames when resolving from just an instruction address which was not previously possible.