[clang] [llvm] [win][x64] Unwind v2 3/n: Add support for emitting unwind v2 information (equivalent to MSVC /d2epilogunwind) (PR #129142)

Daniel Paoliello via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 11:39:08 PDT 2025


================
@@ -163,20 +206,90 @@ static void EmitRuntimeFunction(MCStreamer &streamer,
                                              context), 4);
 }
 
+static std::optional<int64_t>
+GetOptionalAbsDifference(const MCAssembler &Assembler, const MCSymbol *LHS,
+                         const MCSymbol *RHS) {
+  MCContext &Context = Assembler.getContext();
+  const MCExpr *Diff =
+      MCBinaryExpr::createSub(MCSymbolRefExpr::create(LHS, Context),
+                              MCSymbolRefExpr::create(RHS, Context), Context);
+  // It should normally be possible to calculate the length of a function
+  // at this point, but it might not be possible in the presence of certain
+  // unusual constructs, like an inline asm with an alignment directive.
----------------
dpaoliello wrote:

This is actually pre-existing code that I moved earlier since I needed to call it in a different function.

It's definitely caused issues for me: you'll note that I only use this to measure the size of an epilog, so it's always measuring within the same block across a known set of instructions.

For the distance between an epilog and the end of the function I had to create a custom fixup for exactly the reason that you mention.

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


More information about the llvm-commits mailing list