This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Enable CFIInstrInserter
AbandonedPublic

Authored by MaskRay on Sep 3 2021, 12:35 PM.

Details

Summary

A basic block following an exit basic block (with ret) generally has
incorrect CFI.
CFIInstrInserter introduced by Correct dwarf unwind information in function epilogue can fix the problem.
I have skepticism whether the fix-up approach is the best, but currently appears
to be the only realistic approach to fix a basic block with epilogue and a basic
block following an epilogue, before we come up with a better scheme.

Diff Detail

Event Timeline

MaskRay created this revision.Sep 3 2021, 12:35 PM
MaskRay requested review of this revision.Sep 3 2021, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 3 2021, 12:35 PM
SjoerdMeijer added a subscriber: SjoerdMeijer.

Just wanted to double check because it is not mentioned in the description, this is addressing https://bugs.llvm.org/show_bug.cgi?id=47142 ?

If this is how X86 works around this issue, then this patch seems trivial and not controversial, but perhaps someone else can comment.

chill added a comment.Nov 17 2021, 9:06 AM

I would request to not enable CFIInstrInserter for AArch64. I have a patch (that I was planning to submit tomorrow, 2021-11-08), that is
IMHO, for a lack of better word, better.

Until I get aroun d to submit it, here's the commit message, describing it:

[CodeGen] Async unwind (7/7) - add a pass to fix CFI information
 
 This pass inserts the necessary `.cfi_remember_state` and
 `.cfi_restore_state` CFI instructions to adjust for the inconsistency
 of the call-frame information caused by final machine basic block
 layout.
 
 Unlike the `CFIInstrInserer` pass, this one uses emits only
 `.cfi_remember_state`/`.cfi_restore_state`, which results in smaller
 unwind tables and also transparently handles custom unwind info
 extensions, CFA offset adjustement and save locations of SVE
 registers.
 
 The pass takes advantage on the contraints LLVM imposes on the
 placement of save/restore points (cf. `ShrinkWrap.cpp`):
 
 * there is a single basic block, containing the function prologue
 
 * possibly multiple epilogue blocks, where each epilogue block is
   complete and self-contained, i.e. CSR restore instructions (and the
   corresponding CFI instructions are not split across two or more
   blocks.
 
 * prologue and epilogue blocks are outside of any loops
 
 Thus at the beginning and at the end of each basic block we can be in
 one of two states - "has frame" or "does not have frame", which can be
 computed by a single RPO traversal.
 
 Then, for each epilogue block (one that transitions from "has frame"
 to "does not have frame"), which is physically followed by a block
 with a "has frame", we insert a `.cfi_remember_state`.
 
 Similarly, for each block thas "has frame", but is preceded an
 epilogue block, we insert a `.cfi_restore_state".
 
 A block may need to have both instructions, in which case the restore
 one has to precede the remember one.
Matt added a subscriber: Matt.Nov 17 2021, 12:05 PM
xgupta added a subscriber: xgupta.Nov 17 2021, 7:32 PM

(@chill, I am also waiting for your patch as these two CFI directives are needed to fix the stack unwinding issue with shrink wrapping in RISCV)

chill added a comment.Nov 23 2021, 2:48 AM

(@chill, I am also waiting for your patch as these two CFI directives are needed to fix the stack unwinding issue with shrink wrapping in RISCV)

Noted. Unfortunately, the initial algorithm (as described above) was wrong. I've come up with another one I'm working on it right now.

(@chill, I am also waiting for your patch as these two CFI directives are needed to fix the stack unwinding issue with shrink wrapping in RISCV)

Noted. Unfortunately, the initial algorithm (as described above) was wrong. I've come up with another one I'm working on it right now.

Sure no hurry, Happy to help in reviewing if I can.

MaskRay abandoned this revision.Mar 25 2022, 11:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 11:21 PM
Herald added a subscriber: StephenFan. · View Herald Transcript