[llvm] Add CodeView S_LABEL32 symbols for jump table targets (for Windows debugging) (PR #146121)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 22:29:16 PDT 2025
https://github.com/sivadeilra updated https://github.com/llvm/llvm-project/pull/146121
>From aed08033f79a49983c7a73ff2238de4de7afc134 Mon Sep 17 00:00:00 2001
From: Arlie Davis <ardavis at microsoft.com>
Date: Thu, 26 Jun 2025 17:09:51 -0700
Subject: [PATCH 1/2] working on jump table labels
---
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 33 ++++++++++++++++---
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h | 1 +
llvm/test/DebugInfo/COFF/jump-table.ll | 9 +++++
3 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 5e1b313b4d2fa..91cf7c17f7cb0 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -3566,15 +3566,38 @@ void CodeViewDebug::collectDebugInfoForJumpTables(const MachineFunction *MF,
break;
}
- CurFn->JumpTables.push_back(
- {EntrySize, Base, BaseOffset, Branch,
- MF->getJTISymbol(JumpTableIndex, MMI->getContext()),
- JTI.getJumpTables()[JumpTableIndex].MBBs.size()});
+ const MachineJumpTableEntry &JTE = JTI.getJumpTables()[JumpTableIndex];
+
+ JumpTableInfo CVJTI{EntrySize,
+ Base,
+ BaseOffset,
+ Branch,
+ MF->getJTISymbol(JumpTableIndex, MMI->getContext()),
+ JTE.MBBs.size()};
+
+ for (const auto &MBB : JTE.MBBs) {
+ CVJTI.Cases.push_back(MBB->getSymbol());
+ }
+
+ CurFn->JumpTables.push_back(std::move(CVJTI));
});
}
void CodeViewDebug::emitDebugInfoForJumpTables(const FunctionInfo &FI) {
- for (auto JumpTable : FI.JumpTables) {
+ // Emit S_LABEL32 records for each jump target
+ for (const auto &JumpTable : FI.JumpTables) {
+ for (const auto &CaseSym : JumpTable.Cases) {
+ MCSymbol *LabelEnd = beginSymbolRecord(SymbolKind::S_LABEL32);
+ OS.AddComment("Offset and segment");
+ OS.emitCOFFSecRel32(CaseSym, 0);
+ OS.AddComment("Flags");
+ OS.emitInt8(0);
+ emitNullTerminatedSymbolName(OS, CaseSym->getName());
+ endSymbolRecord(LabelEnd);
+ }
+ }
+
+ for (const auto &JumpTable : FI.JumpTables) {
MCSymbol *JumpTableEnd = beginSymbolRecord(SymbolKind::S_ARMSWITCHTABLE);
if (JumpTable.Base) {
OS.AddComment("Base offset");
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
index c862802d835d7..c2b878e52e1c3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
@@ -146,6 +146,7 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
const MCSymbol *Branch;
const MCSymbol *Table;
size_t TableSize;
+ std::vector<const MCSymbol *> Cases;
};
// For each function, store a vector of labels to its instructions, as well as
diff --git a/llvm/test/DebugInfo/COFF/jump-table.ll b/llvm/test/DebugInfo/COFF/jump-table.ll
index 3eda2438ea88a..be1de2be55788 100644
--- a/llvm/test/DebugInfo/COFF/jump-table.ll
+++ b/llvm/test/DebugInfo/COFF/jump-table.ll
@@ -118,6 +118,15 @@
; CV: GlobalProcIdSym {
; CV: DisplayName: func
; CV-NOT: GlobalProcIdSym
+; CV: LabelSym {
+; CV-NEXT: Kind: S_LABEL32 (0x1105)
+; CV-NEXT: CodeOffset: 0xC0
+; CV-NEXT: Segment: 0x0
+; CV-NEXT: Flags: 0x0
+; CV-NEXT: Flags [ (0x0)
+; CV-NEXT: ]
+; CV-NEXT: DisplayName:
+; CV-NEXT: }
; CV: JumpTableSym {
; CV-NEXT: Kind: S_ARMSWITCHTABLE (0x1159)
; CV-NEXT: BaseOffset: 0x0
>From f3881a56ebb7ae1dae71f5fc83015c1093c3b951 Mon Sep 17 00:00:00 2001
From: Arlie Davis <arlie.davis at microsoft.com>
Date: Mon, 30 Jun 2025 22:29:04 -0700
Subject: [PATCH 2/2] PR feedback, style
---
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 91cf7c17f7cb0..87bc9a8035f50 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -3567,18 +3567,14 @@ void CodeViewDebug::collectDebugInfoForJumpTables(const MachineFunction *MF,
}
const MachineJumpTableEntry &JTE = JTI.getJumpTables()[JumpTableIndex];
-
JumpTableInfo CVJTI{EntrySize,
Base,
BaseOffset,
Branch,
MF->getJTISymbol(JumpTableIndex, MMI->getContext()),
JTE.MBBs.size()};
-
- for (const auto &MBB : JTE.MBBs) {
+ for (const auto &MBB : JTE.MBBs)
CVJTI.Cases.push_back(MBB->getSymbol());
- }
-
CurFn->JumpTables.push_back(std::move(CVJTI));
});
}
More information about the llvm-commits
mailing list