[llvm] [BPF] Add exception handling support with .bpf_cleanup section (PR #192164)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 10:33:08 PDT 2026
================
@@ -192,6 +193,41 @@ void BPFAsmPrinter::emitInstruction(const MachineInstr *MI) {
EmitToStreamer(*OutStreamer, TmpInst);
}
+void BPFAsmPrinter::emitFunctionBodyEnd() {
+ // Emit .bpf_cleanup section with a flat table of
+ // (call_site, landing_pad) pairs.
+ const std::vector<LandingPadInfo> &LandingPads = MF->getLandingPads();
+ if (LandingPads.empty())
+ return;
+
+ MCContext &Ctx = OutContext;
+ auto *CleanupSec =
+ Ctx.getELFSection(".bpf_cleanup", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
+ OutStreamer->switchSection(CleanupSec);
+
+ // Each landing pad has BeginLabels/EndLabels marking the invoke
+ // call sites that unwind to it.
+ for (const LandingPadInfo &LP : LandingPads) {
+ MCSymbol *LPLabel = LP.LandingPadLabel;
+ if (!LPLabel)
+ continue;
+ for (unsigned i = 0, e = LP.BeginLabels.size(); i != e; ++i) {
+ MCSymbol *Begin = LP.BeginLabels[i];
+ MCSymbol *End = LP.EndLabels[i];
+
+ // Each entry is 3 x 4 bytes: begin, end, landing_pad.
+ // The invoke region [begin, end) may include argument setup
+ // before the call. The runtime checks begin <= PC < end.
+ OutStreamer->emitSymbolValue(Begin, 4);
+ OutStreamer->emitSymbolValue(End, 4);
+ OutStreamer->emitSymbolValue(LPLabel, 4);
----------------
eddyz87 wrote:
So, this forgoes type/action table. Is that important for Rust?
https://github.com/llvm/llvm-project/pull/192164
More information about the llvm-commits
mailing list