[llvm] Spill/restore FP/BP around instructions in which they are clobbered (PR #81048)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 15:03:07 PST 2024
weiguozhi wrote:
> Still, the CFI info looks wrong once the frame pointer is clobbered (updates to rsp _and_ rbp should be accompanied by matching CFI directives) and I have concerns that this will break unwinding (not just asynchronous unwinding but also exceptions thrown from the called function). Could you test that unwinding through such a function call works as expected?
>
I'm very ignorant in DWARF. After some study, I think we need the following additional CFI instructions
```
foo: # @foo
.cfi_startproc
# %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
andq $-16, %rsp
subq $16, %rsp
.cfi_offset %rbx, -56
.cfi_offset %r12, -48
.cfi_offset %r13, -40
.cfi_offset %r14, -32
.cfi_offset %r15, -24
# kill: def $edi killed $edi def $rdi
pushq %rbp
pushq %rax
+ .cfi_def_cfa_expression [%rsp + 8] + 16 // %rbp is stored in memory [%rsp + 8]
movl %esi, %ebp
movq %rdi, %r13
callq external at PLT
addq $8, %rsp
popq %rbp
+ .cfi_def_cfa %rbp, 16 // %rbp is restored
leaq -40(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
.cfi_def_cfa %rsp, 8
retq
```
And the cfi_def_cfa_expression should be constructed similar to function X86FrameLowering::emitCalleeSavedFrameMoves. Is my understanding right?
> (fwiw, I'm not a maintainer and I'd personally like to see support for this use case, but I have concerns that this will break other things.)
Because the frame pointer is clobbered, so the unwinding information is already broken. The current patch doesn't make it worse.
https://github.com/llvm/llvm-project/pull/81048
More information about the llvm-commits
mailing list