[libunwind] [libunwind] Detect cycles of length 1 (PR #103476)
Michael Kolupaev via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 19 01:52:39 PDT 2024
al13n321 wrote:
The `clone` syscall, in newly created thread, adjusts stack pointer and stack contents, and there's logically no "caller" stack frame and no return address on the stack. `tools/add-cfi.x86_64.awk` doesn't know about any of that and autogenerates cfi as if it's just normal linear code and the syscall does nothing special. Below the syscall the cfi is just all incorrect, at least from child thread's point of view. It just happens to have the property that ip and sp are left unchanged by the unwind step. (I don't remember the details, but it's something like: the `clone` syscall puts the entry function pointer somewhere near the top of the stack, and the cfi happens to point to that offset from sp despite having incorrect cfa.)
A principled fix would be to add manual cfi annotations in `musl/src/thread/x86_64/clone.s`. But I figured that since (1) gdb does cycle detection, and (2) it's still not fixed in musl; then this is considered acceptable, and maybe even intentional. (And, IIUC, musl people generally don't want programs to be able to unwind their own stack for debugging purposes. If I send a fix to musl, I imagine the answer may be "gdb already works, libunwind already doesn't work, and that's exactly how we want it", but may be worth a try.)
https://github.com/llvm/llvm-project/pull/103476
More information about the cfe-commits
mailing list