[llvm] [SFrames] Add FDEs for functions with .cfi_startproc (PR #154213)

Indu Bhagat via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 25 22:16:58 PDT 2025


================
@@ -20,12 +21,62 @@ using namespace sframe;
 
 namespace {
 
+// High-level structure to track info needed to emit a sframe_func_desc_entry
+// and its associated FREs.
+struct SFrameFDE {
+  // Reference to the original dwarf frame to avoid copying.
+  const MCDwarfFrameInfo &DFrame;
+  // Label where this FDE's FREs start.
+  MCSymbol *FREStart;
+
+  SFrameFDE(const MCDwarfFrameInfo &DF, MCSymbol *FRES)
+      : DFrame(DF), FREStart(FRES) {}
+
+  void emit(MCObjectStreamer &S, const MCSymbol* FRESubSectionStart) {
+    MCContext &C = S.getContext();
+
+    // sfde_func_start_address
+    const MCExpr *V = C.getAsmInfo()->getExprForFDESymbol(
+        &(*DFrame.Begin), C.getObjectFileInfo()->getFDEEncoding(), S);
+    S.emitValue(V, sizeof(int32_t));
+
+    // sfde_func_size
+    S.emitAbsoluteSymbolDiff(DFrame.End, DFrame.Begin, sizeof(uint32_t));
+
+    // sfde_func_start_fre_off
+    auto *F = S.getCurrentFragment();
+    const MCExpr *Diff =
+        MCBinaryExpr::createSub(MCSymbolRefExpr::create(FREStart, C),
+                                MCSymbolRefExpr::create(FRESubSectionStart, C), C);
+
+    F->addFixup(MCFixup::create(F->getContents().size(), Diff,
+                                MCFixup::getDataKindForSize(4)));
+    S.emitInt32(0);
+
+    // sfde_func_start_num_fres
----------------
ibhagatgnu wrote:

Typo: sfde_func_start_num_fres  --> sfde_func_num_fres

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


More information about the llvm-commits mailing list