diff options
author | sivadeilra <ardavis@microsoft.com> | 2025-07-07 12:26:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-07 12:26:30 -0700 |
commit | 9923565fb8b9a6215e85ad1bb542c301332a502d (patch) | |
tree | c251a18bc1ccdc68b7c726fb49363fbc64ecc51e /llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | |
parent | 5110ac4113b5969315a38e0cffe7580a4ca847a1 (diff) | |
download | llvm-9923565fb8b9a6215e85ad1bb542c301332a502d.zip llvm-9923565fb8b9a6215e85ad1bb542c301332a502d.tar.gz llvm-9923565fb8b9a6215e85ad1bb542c301332a502d.tar.bz2 |
Add CodeView S_LABEL32 symbols for jump table targets (for Windows debugging) (#146121)
This PR provides more information to debuggers and analysis tools on
Windows. It adds `S_LABEL32` symbols for each target BB of each jump
table. This allows debuggers to insert symbolic labels when
disassembling code. `S_LABEL32` symbol records indicate that a location
is definitely code, and can optionally associate a string label with the
code location. BBs generated for jump tables may or may not have string
labels, so it is acceptable for the "name" field within `S_LABEL32`
symbols to be an empty string.
More importantly, this PR allows Windows analysis tools, such as those
that generate hot-patches for the Windows kernel, to use these labels to
distinguish code basic blocks from data blocks. Microsoft's analysis
tools (similar to Bolt) rely on being able to identify all code blocks,
so that the tools can traverse all instructions and verify that
important requirements for hot-patching are met.
This PR has no effect on code generation. It only affects the CodeView
symbols that are emitted into OBJ files, which the linker then
repackages into PDB files.
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index d37a22f..65a8735 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -3566,15 +3566,34 @@ 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"); |