This fixes the issue of wrong CFA calculation in the following case:
0x08048400 <+0>: push %ebx 0x08048401 <+1>: sub $0x8,%esp 0x08048404 <+4>: **call 0x8048409 <test+9>** 0x08048409 <+9>: **pop %eax** 0x0804840a <+10>: add $0x1bf7,%eax 0x08048410 <+16>: mov %eax,%ebx 0x08048412 <+18>: call 0x80483f0 <bar> 0x08048417 <+23>: add $0x8,%esp 0x0804841a <+26>: pop %ebx 0x0804841b <+27>: ret
The highlighted instructions are a product of movpc instruction. The call instruction changes the stack pointer, and pop instruction restores its value. However, the rule for computing CFA is not updated and is wrong on the pop instruction. So, e.g. backtrace in gdb doesn't work when on the pop instruction. This solution adds cfi instructions for both call and pop instructions.
- cfi_adjust_cfa_offset** instruction is used with the appropriate offset for setting the rules to calculate CFA correctly.
You really only need these CFA adjust directives when precise instruction-level stack unwinding support is needed. That's certainly the case when the CFI is being used to generate debug info. But it isn't the case when the CFI is being used to generate the unwind tables for synchronous EH. For synchronous EH, these extra CFA adjust directives just waste space in the .eh_frame section.
For D13767, Michael is planning to add a usePreciseUnwindInfo function. It would be nice sync with him and add "&& usePreciseUnwindInfo" to this condition. Also at line 1162.