This is an archive of the discontinued LLVM Phabricator instance.

Update CFA to be in terms of $sp instead of $fp when $fp is overwritten in epilogue on AArch64
ClosedPublic

Authored by jasonmolenda on Apr 26 2022, 5:46 PM.

Details

Summary

When we can the instructions of an AArch64 to create an unwind plan, and we see an instruction to add a value to $fp and assign it to $sp, lldb recognizes this as meaning that CFA is now set in terms of $sp. e.g.

28: 0xd10043bf sub sp, x29, #0x10
32: 0xa9417bfd ldp x29, x30, [sp, #0x10]

This is a common method used in clang codegen. But clang will sometimes overwrite $fp by restoring it from the stack, to the caller's $fp value. At this point, lldb is still expressing the CFA in terms of $fp but $fp is now the caller's $fp and our CFA value changes, which can confuse the stepper algorithms.

This change recognizes the restoring of $fp to mean the CFA should switch back to $sp. e.g.

12: 0xa9417bfd ldp x29, x30, [sp, #0x10]
16: 0x910083ff add sp, sp, #0x20

Backtraces are not impacted; we get all of the register values correct, but because the CFA changes, stepping algorithms can get confused and stop in the middle of the epilogue.

Diff Detail

Event Timeline

jasonmolenda created this revision.Apr 26 2022, 5:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 5:46 PM
jasonmolenda requested review of this revision.Apr 26 2022, 5:46 PM

cleanup patch to remove an unintended diff.

JDevlieghere accepted this revision.May 4 2022, 1:11 PM

I'm far from an expert on this but the change makes sense to me and has good test coverage. LGTM.

This revision is now accepted and ready to land.May 4 2022, 1:11 PM