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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to