[llvm] Generate an .sframe section with a skeleton header (PR #151223)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 13:44:29 PDT 2025
https://github.com/Sterling-Augustine updated https://github.com/llvm/llvm-project/pull/151223
>From 6b764e23770b6a40d83a01dad9be594d179e1af9 Mon Sep 17 00:00:00 2001
From: Sterling Augustine <saugustine at google.com>
Date: Tue, 29 Jul 2025 13:10:04 -0700
Subject: [PATCH 1/4] Generate an .sframe section with a skeleton header
This continues the sframe implementation discussed previously.
Of note, this also adds some target dependent functions to the object
file. Additional fields will be needed later. It would be possible to
do all of this inside the sframe implementation itself if it feels
a little messy and specialized, but generally I think that target info
goes with target info.
---
.../llvm/BinaryFormat/SFrameConstants.def | 1 +
llvm/include/llvm/MC/MCObjectFileInfo.h | 9 ++
llvm/include/llvm/MC/MCSFrame.h | 36 +++++++
llvm/lib/MC/CMakeLists.txt | 1 +
llvm/lib/MC/MCObjectFileInfo.cpp | 19 ++++
llvm/lib/MC/MCObjectStreamer.cpp | 7 +-
llvm/lib/MC/MCSFrame.cpp | 95 +++++++++++++++++++
llvm/test/MC/ELF/cfi-sframe.s | 26 +++++
8 files changed, 193 insertions(+), 1 deletion(-)
create mode 100644 llvm/include/llvm/MC/MCSFrame.h
create mode 100644 llvm/lib/MC/MCSFrame.cpp
create mode 100644 llvm/test/MC/ELF/cfi-sframe.s
diff --git a/llvm/include/llvm/BinaryFormat/SFrameConstants.def b/llvm/include/llvm/BinaryFormat/SFrameConstants.def
index 643b15f438c86..2bd25eb46fd3e 100644
--- a/llvm/include/llvm/BinaryFormat/SFrameConstants.def
+++ b/llvm/include/llvm/BinaryFormat/SFrameConstants.def
@@ -30,6 +30,7 @@ HANDLE_SFRAME_FLAG(0x01, FDESorted)
HANDLE_SFRAME_FLAG(0x02, FramePointer)
HANDLE_SFRAME_FLAG(0x04, FDEFuncStartPCRel)
+HANDLE_SFRAME_ABI(0x00, Undefined)
HANDLE_SFRAME_ABI(0x01, AArch64EndianBig)
HANDLE_SFRAME_ABI(0x02, AArch64EndianLittle)
HANDLE_SFRAME_ABI(0x03, AMD64EndianLittle)
diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h
index 5ce58ae0a836f..cb5da89342532 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -13,6 +13,7 @@
#ifndef LLVM_MC_MCOBJECTFILEINFO_H
#define LLVM_MC_MCOBJECTFILEINFO_H
+#include "llvm/BinaryFormat/SFrame.h"
#include "llvm/BinaryFormat/Swift.h"
#include "llvm/MC/MCSection.h"
#include "llvm/Support/Compiler.h"
@@ -50,6 +51,9 @@ class LLVM_ABI MCObjectFileInfo {
/// Compact unwind encoding indicating that we should emit only an EH frame.
unsigned CompactUnwindDwarfEHFrameOnly = 0;
+ /// SFrame ABI architecture byte
+ sframe::ABI SFrameABIArch = sframe::ABI::Undefined;
+
/// Section directive for standard text.
MCSection *TextSection = nullptr;
@@ -174,6 +178,9 @@ class LLVM_ABI MCObjectFileInfo {
/// It is initialized on demand so it can be overwritten (with uniquing).
MCSection *EHFrameSection = nullptr;
+ /// SFrame section.
+ MCSection *SFrameSection = nullptr;
+
/// Section containing metadata on function stack sizes.
MCSection *StackSizesSection = nullptr;
@@ -266,6 +273,7 @@ class LLVM_ABI MCObjectFileInfo {
return CompactUnwindDwarfEHFrameOnly;
}
+ sframe::ABI getSFrameABIArch() const { return SFrameABIArch; }
virtual unsigned getTextSectionAlignment() const { return 4; }
MCSection *getTextSection() const { return TextSection; }
MCSection *getDataSection() const { return DataSection; }
@@ -445,6 +453,7 @@ class LLVM_ABI MCObjectFileInfo {
MCSection *getTOCBaseSection() const { return TOCBaseSection; }
MCSection *getEHFrameSection() const { return EHFrameSection; }
+ MCSection *getSFrameSection() const { return SFrameSection; }
bool isPositionIndependent() const { return PositionIndependent; }
diff --git a/llvm/include/llvm/MC/MCSFrame.h b/llvm/include/llvm/MC/MCSFrame.h
new file mode 100644
index 0000000000000..9ae84d6045c74
--- /dev/null
+++ b/llvm/include/llvm/MC/MCSFrame.h
@@ -0,0 +1,36 @@
+//===- MCSFrame.h - Machine Code SFrame support -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the declaration of MCSFrameEmitter to support emitting
+// sframe unwinding info from .cfi_* directives. It relies on FDEs and CIEs
+// created for Dwarf frame info, but emits that info in a different format.
+//
+// See https://sourceware.org/binutils/docs-2.41/sframe-spec.html
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MC_MCSFRAME_H
+#define LLVM_MC_MCSFRAME_H
+
+#include <cstdint>
+
+#include "llvm/ADT/SmallVector.h"
+
+namespace llvm {
+
+class MCObjectStreamer;
+
+class MCSFrameEmitter {
+public:
+ //
+ // Emits the sframe section.
+ //
+ static void Emit(MCObjectStreamer &streamer);
+};
+
+} // end namespace llvm
+#endif // LLVM_MC_MCSFRAME_H
diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt
index 18a85b3fed08c..1e1d0a6d00601 100644
--- a/llvm/lib/MC/CMakeLists.txt
+++ b/llvm/lib/MC/CMakeLists.txt
@@ -45,6 +45,7 @@ add_llvm_component_library(LLVMMC
MCSection.cpp
MCSectionMachO.cpp
MCStreamer.cpp
+ MCSFrame.cpp
MCSPIRVStreamer.cpp
MCSubtargetInfo.cpp
MCSymbol.cpp
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 0069d12dce396..464431b45646a 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -10,6 +10,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/BinaryFormat/SFrame.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
@@ -380,6 +381,20 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
unsigned EHSectionType = T.getArch() == Triple::x86_64
? ELF::SHT_X86_64_UNWIND
: ELF::SHT_PROGBITS;
+ switch (T.getArch()) {
+ case Triple::x86_64:
+ SFrameABIArch = sframe::ABI::AMD64EndianLittle;
+ break;
+ case Triple::aarch64:
+ SFrameABIArch = sframe::ABI::AArch64EndianLittle;
+ break;
+ case Triple::aarch64_be:
+ SFrameABIArch = sframe::ABI::AArch64EndianBig;
+ break;
+ default:
+ SFrameABIArch = sframe::ABI::Undefined;
+ break;
+ }
// Solaris requires different flags for .eh_frame to seemingly every other
// platform.
@@ -537,6 +552,9 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
EHFrameSection =
Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
+ SFrameSection =
+ Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);
+
StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);
@@ -1062,6 +1080,7 @@ void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
CompactUnwindDwarfEHFrameOnly = 0;
EHFrameSection = nullptr; // Created on demand.
+ SFrameSection = nullptr; // Created on demand.
CompactUnwindSection = nullptr; // Used only by selected targets.
DwarfAccelNamesSection = nullptr; // Used only by selected targets.
DwarfAccelObjCSection = nullptr; // Used only by selected targets.
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index e82393a8477ea..666841ebffdb5 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -19,6 +19,7 @@
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSFrame.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SourceMgr.h"
using namespace llvm;
@@ -30,7 +31,7 @@ MCObjectStreamer::MCObjectStreamer(MCContext &Context,
: MCStreamer(Context),
Assembler(std::make_unique<MCAssembler>(
Context, std::move(TAB), std::move(Emitter), std::move(OW))),
- EmitEHFrame(true), EmitDebugFrame(false) {
+ EmitEHFrame(true), EmitDebugFrame(false), EmitSFrame(false) {
assert(Assembler->getBackendPtr() && Assembler->getEmitterPtr());
IsObj = true;
setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
@@ -185,6 +186,10 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
if (EmitDebugFrame)
MCDwarfFrameEmitter::Emit(*this, MAB, false);
+
+ if (EmitSFrame || (getContext().getTargetOptions() &&
+ getContext().getTargetOptions()->EmitSFrameUnwind))
+ MCSFrameEmitter::Emit(*this);
}
void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
diff --git a/llvm/lib/MC/MCSFrame.cpp b/llvm/lib/MC/MCSFrame.cpp
new file mode 100644
index 0000000000000..eae49ccd31eb0
--- /dev/null
+++ b/llvm/lib/MC/MCSFrame.cpp
@@ -0,0 +1,95 @@
+//===- lib/MC/MCSFrame.cpp - MCSFrame implementation ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/MC/MCSFrame.h"
+#include "llvm/BinaryFormat/SFrame.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCObjectFileInfo.h"
+#include "llvm/MC/MCObjectStreamer.h"
+#include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/Support/EndianStream.h"
+
+using namespace llvm;
+using namespace sframe;
+
+namespace {
+
+// Emitting these field-by-field, instead of constructing the actual structures
+// lets Streamer do target endian-fixups for free.
+
+class SFrameEmitterImpl {
+ MCObjectStreamer &Streamer;
+ ABI SFrameABI;
+ MCSymbol *FDESubSectionStart;
+ MCSymbol *FRESubSectionStart;
+ MCSymbol *FRESubSectionEnd;
+
+
+public:
+ SFrameEmitterImpl(MCObjectStreamer &Streamer) : Streamer(Streamer) {
+ SFrameABI = Streamer.getContext().getObjectFileInfo()->getSFrameABIArch();
+ FDESubSectionStart = Streamer.getContext().createTempSymbol();
+ FRESubSectionStart = Streamer.getContext().createTempSymbol();
+ FRESubSectionEnd = Streamer.getContext().createTempSymbol();
+ }
+
+ void EmitPreamble() {
+ Streamer.emitInt16(Magic);
+ Streamer.emitInt8(static_cast<uint64_t>(Version::V2));
+ Streamer.emitInt8(0);
+ }
+
+ void EmitHeader() {
+ EmitPreamble();
+ // sfh_abi_arch
+ Streamer.emitInt8(static_cast<uint64_t>(SFrameABI));
+ // sfh_cfa_fixed_fp_offset
+ Streamer.emitInt8(0);
+ // sfh_cfa_fixed_ra_offset
+ Streamer.emitInt8(0);
+ // sfh_auxhdr_len
+ Streamer.emitInt8(0);
+ // shf_num_fdes
+ Streamer.emitInt32(0);
+ // shf_num_fres
+ Streamer.emitInt32(0);
+ // shf_fre_len
+ Streamer.emitAbsoluteSymbolDiff(FRESubSectionEnd, FRESubSectionStart,
+ sizeof(int32_t));
+ // shf_fdeoff. With no sfh_auxhdr, these immediately follow this header.
+ Streamer.emitInt32(0);
+ // shf_freoff
+ Streamer.emitAbsoluteSymbolDiff(FRESubSectionStart, FDESubSectionStart,
+ sizeof(uint32_t));
+ }
+
+ void EmitFDEs() { Streamer.emitLabel(FDESubSectionStart); }
+
+ void EmitFREs() {
+ Streamer.emitLabel(FRESubSectionStart);
+ Streamer.emitLabel(FRESubSectionEnd);
+ }
+};
+
+} // end anonymous namespace
+
+void MCSFrameEmitter::Emit(MCObjectStreamer &Streamer) {
+ MCContext &Context = Streamer.getContext();
+ SFrameEmitterImpl Emitter(Streamer);
+
+ MCSection *Section = Context.getObjectFileInfo()->getSFrameSection();
+ // Not strictly necessary, but gas always aligns to 8, so match that.
+ Section->ensureMinAlignment(Align(8));
+ Streamer.switchSection(Section);
+ MCSymbol *SectionStart = Context.createTempSymbol();
+ Streamer.emitLabel(SectionStart);
+ Emitter.EmitHeader();
+ Emitter.EmitFDEs();
+ Emitter.EmitFREs();
+}
diff --git a/llvm/test/MC/ELF/cfi-sframe.s b/llvm/test/MC/ELF/cfi-sframe.s
new file mode 100644
index 0000000000000..6aae37bc370e0
--- /dev/null
+++ b/llvm/test/MC/ELF/cfi-sframe.s
@@ -0,0 +1,26 @@
+// TODO: Add other architectures as they gain sframe support
+// REQUIRES: x86-registered-target
+// RUN: llvm-mc --assemble --filetype=obj --gsframe -triple x86_64 %s -o %t.o
+// RUN: llvm-readelf --sframe %t.o | FileCheck %s
+
+.cfi_sections .sframe
+
+f1:
+ .cfi_startproc
+ nop
+ .cfi_endproc
+
+// CHECK: SFrame section '.sframe' {
+// CHECK-NEXT: Header {
+// CHECK-NEXT: Magic: 0xDEE2
+// CHECK-NEXT: Version: V2 (0x2)
+// CHECK-NEXT: Flags [ (0x0)
+// CHECK: ABI: AMD64EndianLittle (0x3)
+// CHECK-NEXT: CFA fixed FP offset (unused): 0
+// CHECK-NEXT: CFA fixed RA offset: 0
+// CHECK-NEXT: Auxiliary header length: 0
+// CHECK-NEXT: Num FDEs: 0
+// CHECK-NEXT: Num FREs: 0
+// CHECK-NEXT: FRE subsection length: 0
+// CHECK-NEXT: FDE subsection offset: 0
+// CHECK-NEXT: FRE subsection offset: 0
>From 0d6691c58549df2a9f6b622c343e763eb9b91400 Mon Sep 17 00:00:00 2001
From: Sterling Augustine <saugustine at google.com>
Date: Tue, 29 Jul 2025 14:09:21 -0700
Subject: [PATCH 2/4] Fix formatting
---
llvm/lib/MC/MCObjectFileInfo.cpp | 24 ++++++++++++------------
llvm/lib/MC/MCObjectStreamer.cpp | 2 +-
llvm/lib/MC/MCSFrame.cpp | 1 -
3 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 464431b45646a..009fe2647cc25 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -382,18 +382,18 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
? ELF::SHT_X86_64_UNWIND
: ELF::SHT_PROGBITS;
switch (T.getArch()) {
- case Triple::x86_64:
- SFrameABIArch = sframe::ABI::AMD64EndianLittle;
- break;
- case Triple::aarch64:
- SFrameABIArch = sframe::ABI::AArch64EndianLittle;
- break;
- case Triple::aarch64_be:
- SFrameABIArch = sframe::ABI::AArch64EndianBig;
- break;
- default:
- SFrameABIArch = sframe::ABI::Undefined;
- break;
+ case Triple::x86_64:
+ SFrameABIArch = sframe::ABI::AMD64EndianLittle;
+ break;
+ case Triple::aarch64:
+ SFrameABIArch = sframe::ABI::AArch64EndianLittle;
+ break;
+ case Triple::aarch64_be:
+ SFrameABIArch = sframe::ABI::AArch64EndianBig;
+ break;
+ default:
+ SFrameABIArch = sframe::ABI::Undefined;
+ break;
}
// Solaris requires different flags for .eh_frame to seemingly every other
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 666841ebffdb5..8059582301f1c 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -17,9 +17,9 @@
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCSFrame.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCSFrame.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SourceMgr.h"
using namespace llvm;
diff --git a/llvm/lib/MC/MCSFrame.cpp b/llvm/lib/MC/MCSFrame.cpp
index eae49ccd31eb0..bbd004a4c7cbc 100644
--- a/llvm/lib/MC/MCSFrame.cpp
+++ b/llvm/lib/MC/MCSFrame.cpp
@@ -30,7 +30,6 @@ class SFrameEmitterImpl {
MCSymbol *FRESubSectionStart;
MCSymbol *FRESubSectionEnd;
-
public:
SFrameEmitterImpl(MCObjectStreamer &Streamer) : Streamer(Streamer) {
SFrameABI = Streamer.getContext().getObjectFileInfo()->getSFrameABIArch();
>From 8053032976d5f0ea0f740e80349d14d435df7678 Mon Sep 17 00:00:00 2001
From: Sterling Augustine <saugustine at google.com>
Date: Wed, 30 Jul 2025 10:42:42 -0700
Subject: [PATCH 3/4] Address comments:
Switch to std::optional for SFrameABI
Use uint8_t for casting to MCObjectStreamer
---
llvm/include/llvm/BinaryFormat/SFrameConstants.def | 1 -
llvm/include/llvm/MC/MCObjectFileInfo.h | 4 ++--
llvm/lib/MC/MCObjectFileInfo.cpp | 1 -
llvm/lib/MC/MCSFrame.cpp | 10 +++++++---
4 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/SFrameConstants.def b/llvm/include/llvm/BinaryFormat/SFrameConstants.def
index 2bd25eb46fd3e..643b15f438c86 100644
--- a/llvm/include/llvm/BinaryFormat/SFrameConstants.def
+++ b/llvm/include/llvm/BinaryFormat/SFrameConstants.def
@@ -30,7 +30,6 @@ HANDLE_SFRAME_FLAG(0x01, FDESorted)
HANDLE_SFRAME_FLAG(0x02, FramePointer)
HANDLE_SFRAME_FLAG(0x04, FDEFuncStartPCRel)
-HANDLE_SFRAME_ABI(0x00, Undefined)
HANDLE_SFRAME_ABI(0x01, AArch64EndianBig)
HANDLE_SFRAME_ABI(0x02, AArch64EndianLittle)
HANDLE_SFRAME_ABI(0x03, AMD64EndianLittle)
diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h
index cb5da89342532..313c7980e07b0 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -52,7 +52,7 @@ class LLVM_ABI MCObjectFileInfo {
unsigned CompactUnwindDwarfEHFrameOnly = 0;
/// SFrame ABI architecture byte
- sframe::ABI SFrameABIArch = sframe::ABI::Undefined;
+ std::optional<sframe::ABI> SFrameABIArch = {};
/// Section directive for standard text.
MCSection *TextSection = nullptr;
@@ -273,7 +273,7 @@ class LLVM_ABI MCObjectFileInfo {
return CompactUnwindDwarfEHFrameOnly;
}
- sframe::ABI getSFrameABIArch() const { return SFrameABIArch; }
+ std::optional<sframe::ABI> getSFrameABIArch() const { return SFrameABIArch; }
virtual unsigned getTextSectionAlignment() const { return 4; }
MCSection *getTextSection() const { return TextSection; }
MCSection *getDataSection() const { return DataSection; }
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 009fe2647cc25..2280e060861be 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -392,7 +392,6 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
SFrameABIArch = sframe::ABI::AArch64EndianBig;
break;
default:
- SFrameABIArch = sframe::ABI::Undefined;
break;
}
diff --git a/llvm/lib/MC/MCSFrame.cpp b/llvm/lib/MC/MCSFrame.cpp
index bbd004a4c7cbc..d2c89c0e9f53b 100644
--- a/llvm/lib/MC/MCSFrame.cpp
+++ b/llvm/lib/MC/MCSFrame.cpp
@@ -32,7 +32,11 @@ class SFrameEmitterImpl {
public:
SFrameEmitterImpl(MCObjectStreamer &Streamer) : Streamer(Streamer) {
- SFrameABI = Streamer.getContext().getObjectFileInfo()->getSFrameABIArch();
+ assert(Streamer.getContext()
+ .getObjectFileInfo()
+ ->getSFrameABIArch()
+ .has_value());
+ SFrameABI = *Streamer.getContext().getObjectFileInfo()->getSFrameABIArch();
FDESubSectionStart = Streamer.getContext().createTempSymbol();
FRESubSectionStart = Streamer.getContext().createTempSymbol();
FRESubSectionEnd = Streamer.getContext().createTempSymbol();
@@ -40,14 +44,14 @@ class SFrameEmitterImpl {
void EmitPreamble() {
Streamer.emitInt16(Magic);
- Streamer.emitInt8(static_cast<uint64_t>(Version::V2));
+ Streamer.emitInt8(static_cast<uint8_t>(Version::V2));
Streamer.emitInt8(0);
}
void EmitHeader() {
EmitPreamble();
// sfh_abi_arch
- Streamer.emitInt8(static_cast<uint64_t>(SFrameABI));
+ Streamer.emitInt8(static_cast<uint8_t>(SFrameABI));
// sfh_cfa_fixed_fp_offset
Streamer.emitInt8(0);
// sfh_cfa_fixed_ra_offset
>From bd26100d92c6746f55526e75d1f0ec4149f2bf0f Mon Sep 17 00:00:00 2001
From: Sterling Augustine <saugustine at google.com>
Date: Mon, 4 Aug 2025 13:21:52 -0700
Subject: [PATCH 4/4] Address comments.
Fix formatting
---
llvm/include/llvm/MC/MCObjectFileInfo.h | 2 +-
llvm/include/llvm/MC/MCSFrame.h | 11 +++++------
llvm/test/MC/ELF/cfi-sframe.s | 6 +++---
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h
index 313c7980e07b0..fa385c3124c62 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -51,7 +51,7 @@ class LLVM_ABI MCObjectFileInfo {
/// Compact unwind encoding indicating that we should emit only an EH frame.
unsigned CompactUnwindDwarfEHFrameOnly = 0;
- /// SFrame ABI architecture byte
+ /// SFrame ABI architecture byte.
std::optional<sframe::ABI> SFrameABIArch = {};
/// Section directive for standard text.
diff --git a/llvm/include/llvm/MC/MCSFrame.h b/llvm/include/llvm/MC/MCSFrame.h
index 9ae84d6045c74..0853806e10f59 100644
--- a/llvm/include/llvm/MC/MCSFrame.h
+++ b/llvm/include/llvm/MC/MCSFrame.h
@@ -1,4 +1,4 @@
-//===- MCSFrame.h - Machine Code SFrame support -----------------*- C++ -*-===//
+//===- MCSFrame.h - Machine Code SFrame support ---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -16,9 +16,8 @@
#ifndef LLVM_MC_MCSFRAME_H
#define LLVM_MC_MCSFRAME_H
-#include <cstdint>
-
#include "llvm/ADT/SmallVector.h"
+#include <cstdint>
namespace llvm {
@@ -26,10 +25,10 @@ class MCObjectStreamer;
class MCSFrameEmitter {
public:
+ // Emit the sframe section.
//
- // Emits the sframe section.
- //
- static void Emit(MCObjectStreamer &streamer);
+ // \param Streamer - Emit into this stream.
+ static void Emit(MCObjectStreamer &Streamer);
};
} // end namespace llvm
diff --git a/llvm/test/MC/ELF/cfi-sframe.s b/llvm/test/MC/ELF/cfi-sframe.s
index 6aae37bc370e0..45fce241c8764 100644
--- a/llvm/test/MC/ELF/cfi-sframe.s
+++ b/llvm/test/MC/ELF/cfi-sframe.s
@@ -3,11 +3,11 @@
// RUN: llvm-mc --assemble --filetype=obj --gsframe -triple x86_64 %s -o %t.o
// RUN: llvm-readelf --sframe %t.o | FileCheck %s
-.cfi_sections .sframe
+ .cfi_sections .sframe
f1:
- .cfi_startproc
- nop
+ .cfi_startproc
+ nop
.cfi_endproc
// CHECK: SFrame section '.sframe' {
More information about the llvm-commits
mailing list