llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libunwind

Author: Raúl Marín (Algunenano)

<details>
<summary>Changes</summary>

With `_LIBUNWIND_REMEMBER_STACK_ALLOC` (the default on Linux, Apple, Android, 
MinGW and bare metal), `DW_CFA_remember_state` allocates a 
`PrologInfoStackEntry` with `alloca` and `DW_CFA_restore_state` cannot free it. 
So interpreting an FDE takes stack proportional to the total number of 
remember/restore pairs before the target PC, rather than to their nesting depth.

Compilers emit a pair around each epilogue in the middle of a function, and 
each entry holds a whole `PrologInfo`: about 570 bytes on x86-64 and about 1.6 
KB on AArch64. We hit this in ClickHouse on AArch64. Its query profiler samples 
threads with a signal handler that captures a stack trace with libunwind, on 
whatever stack the thread is running. ClickHouse establishes connections to 
remote servers in Boost fibers, whose stacks are 320 KiB. Unwinding through a 
function with 191 remember/restore pairs, a single `parseFDEInstructions` call 
used about 300 KB and ran the fiber's stack into its guard page.

This patch keeps the entries popped by `DW_CFA_restore_state` on a free list 
and reuses them for the next `DW_CFA_remember_state`, so the stack used is 
bounded by the nesting depth. With the heap allocator, the destructor frees 
both lists.

Testing: the new `libunwind/test/remember_state_stack.pass.cpp` unwinds through 
a frame with 5000 pairs after lowering the soft `RLIMIT_STACK` to 256 KiB. On 
x86-64 Linux it crashes with `SIGSEGV` without the change and passes with it. 
`check-unwind` (shared and static configs) and `check-cxxabi` pass.

This PR was prepared with the help of Claude Code; I reviewed the change and 
the test.


---
Full diff: https://github.com/llvm/llvm-project/pull/226964.diff


2 Files Affected:

- (modified) libunwind/src/DwarfParser.hpp (+24-10) 
- (added) libunwind/test/remember_state_stack.pass.cpp (+52) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you 
try again.
``````````

</details>


https://github.com/llvm/llvm-project/pull/226964
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to