[llvm] [llvm] Win x64 Unwind V2 1/n: Mark beginning and end of epilogs (PR #110024)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 13:32:47 PDT 2024


mstorsjo wrote:

> With the original ABI (V1) definition, when unwinding the stack, the original unwinder was forced to disassemble the instruction stream, conclude whether execution was in the epilog and, if yes, essentially emulate the instructions forward. UWOPs were only used for prolog and body. As a result of this, epilogs must follow some canonical format rules which the unwinder can detect and emulate.

Ah, I wasn't aware of this (although I haven't spent much time around the x64 unwinding formats either, I've mostly looked at the ARM and ARM64 formats). Does code generated by LLVM fulfill these criteria at the moment, and are those rules documented anywhere?

As a side note - if dealing with functions that doesn't abide by these rules (either compiler generated that doesn't know about these rules, or custom assembly); one can't expect to get correct unwinding from within the epilog of course. But I wonder if there's a risk if the heuristic for guessing whether we're in body or epilog does an incorrect guess? (And I guess that whole issue is fixed by this V2 format.)

> So, when the EpilogV2-aware unwinder encounters an EpilogV2-compiled function, it will be aware of the instruction offset of where the epilog starts. Then it will use the Prolog's UWOPs to unwind the epilog a) assuming symmetry and b) assuming that each UWOP is associated with a given instruction (length).

So, iirc for the x64 unwind format, each unwind opcode also contains an offset - so you can have a prolog that intermixed with other instructions, that don't have any opcode. (This requires NOP unwind opcodes on ARM/ARM64, but on x64, due to the offsets, isn't needed there.) How does this work for assuming the epilog is a symmetrical mirror of the prolog? Assuming that the epilog is tightly packed, given normative instruction lengths for each unwind opcode?

So, the only extra data that epilog V2 needs to be signaled, is the start offset of the epilog (or epilogs)?



https://github.com/llvm/llvm-project/pull/110024


More information about the llvm-commits mailing list