This is an archive of the discontinued LLVM Phabricator instance.

[ARM SEH 5] [MC] [Win64EH] Check that the SEH unwind opcodes match the actual instructions
ClosedPublic

Authored by mstorsjo on May 15 2022, 2:37 PM.

Details

Summary

It's a fairly common issue that the generating code incorrectly marks
instructions as narrow or wide; check that the instruction lengths
add up to the expected value, and abort if it doesn't. This allows
catching code generation bugs.

Diff Detail

Event Timeline

mstorsjo created this revision.May 15 2022, 2:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 2:37 PM
mstorsjo requested review of this revision.May 15 2022, 2:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 2:37 PM
efriedma added inline comments.May 16 2022, 12:29 PM
llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp
270

I don't like changing whether we emit a label based on NDEBUG; that will affect the actual assembler text. (The actual checking is also probably cheap enough we could just leave it on, but I'll leave that up to you.)

mstorsjo added inline comments.May 16 2022, 1:13 PM
llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp
270

No, this isn't a regular label - the CFI labels are no-ops in assembly output:

MCSymbol *MCStreamer::emitCFILabel() {
  // Return a dummy non-null value so that label fields appear filled in when
  // generating textual assembly.
  return (MCSymbol *)1;
}

Yeah, the checking is cheap anyway though so it's no problem to leave it on.

mstorsjo updated this revision to Diff 430341.May 18 2022, 5:13 AM

Updated and rebased. Made the instruction length checking always enabled, outside of NDEBUG, and changed the error into a proper user level error instead of a printout and std::abort(). Added a testcase for the error message too.

mstorsjo updated this revision to Diff 431270.May 22 2022, 2:39 PM

Updated without .seh_endepilogue_nop.

mstorsjo updated this revision to Diff 431471.May 23 2022, 1:42 PM

Added checks to make sure that prologs and epilogs are properly terminated, and epilog start/end are paired correctly. This gives clearer indication if there were issues in code generation (like epilogs being mangled by tail merging).

This revision is now accepted and ready to land.May 25 2022, 12:45 PM
mstorsjo updated this revision to Diff 432235.May 26 2022, 3:36 AM

Plain rebase, no functional changePlain rebase, no functional change.

This revision was landed with ongoing or failed builds.Jun 1 2022, 1:26 AM
This revision was automatically updated to reflect the committed changes.