From 2488f26d15e7e12aef9ead3fcb2d1b6da51812fb Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Mon, 16 Jun 2025 15:06:41 -0700 Subject: [win][x64] Unwind v2 3/n: Add support for requiring unwind v2 to be used (equivalent to MSVC's /d2epilogunwindrequirev2) (#143577) #129142 added support for emitting Windows x64 unwind v2 information, but it was "best effort". If any function didn't follow the requirements for v2 it was silently downgraded to v1. There are some parts of Windows (specifically kernel-mode code running on Xbox) that require v2, hence we need the ability to fail the compilation if v2 can't be used. This change also adds a heuristic to check if there might be too many unwind codes, it's currently conservative (i.e., assumes that certain prolog instructions will use the maximum number of unwind codes). Future work: attempting to chain unwind info across multiple tables if there are too many unwind codes due to epilogs and adding a heuristic to detect if an epilog will be too far from the end of the function. --- llvm/lib/IR/Module.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'llvm/lib/IR/Module.cpp') diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 37f4a72..2d31481 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -917,3 +917,10 @@ StringRef Module::getTargetABIFromMD() { TargetABI = TargetABIMD->getString(); return TargetABI; } + +WinX64EHUnwindV2Mode Module::getWinX64EHUnwindV2Mode() const { + Metadata *MD = getModuleFlag("winx64-eh-unwindv2"); + if (auto *CI = mdconst::dyn_extract_or_null(MD)) + return static_cast(CI->getZExtValue()); + return WinX64EHUnwindV2Mode::Disabled; +} -- cgit v1.1