diff options
author | Jacek Caban <jacek@codeweavers.com> | 2025-06-13 13:48:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-13 22:48:29 +0200 |
commit | be5c96bfac328fed548c532bbe1710fe23460a85 (patch) | |
tree | 70eaf2803d93bde06770cd2434d8d7067b04f4f0 /llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | |
parent | 60d000496b5485c89c51e64b2b339210d48263be (diff) | |
download | llvm-be5c96bfac328fed548c532bbe1710fe23460a85.zip llvm-be5c96bfac328fed548c532bbe1710fe23460a85.tar.gz llvm-be5c96bfac328fed548c532bbe1710fe23460a85.tar.bz2 |
[CodeGen][COFF] Always emit CodeView compiler info on Windows targets (#142970)
MSVC always emits minimal CodeView metadata with compiler information,
even when debug info is otherwise disabled. Other tools may rely on this
metadata being present. For example, linkers use it to determine whether
hotpatching is enabled for the object file.
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index fc43bc6..ea57a8f 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -125,6 +125,8 @@ static CPUType mapArchToCVCPUType(Triple::ArchType Type) { return CPUType::ARM64; case Triple::ArchType::mipsel: return CPUType::MIPS; + case Triple::ArchType::UnknownArch: + return CPUType::Unknown; default: report_fatal_error("target architecture doesn't map to a CodeView CPUType"); } @@ -611,21 +613,33 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) { } void CodeViewDebug::beginModule(Module *M) { - // If module doesn't have named metadata anchors or COFF debug section - // is not available, skip any debug info related stuff. - if (!Asm->hasDebugInfo() || - !Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) { + // If COFF debug section is not available, skip any debug info related stuff. + if (!Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) { Asm = nullptr; return; } + CompilerInfoAsm = Asm; TheCPU = mapArchToCVCPUType(M->getTargetTriple().getArch()); // Get the current source language. - const MDNode *Node = *M->debug_compile_units_begin(); + const MDNode *Node; + if (Asm->hasDebugInfo()) { + Node = *M->debug_compile_units_begin(); + } else { + // When emitting only compiler information, we may have only NoDebug CUs, + // which would be skipped by debug_compile_units_begin. + NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); + Node = *CUs->operands().begin(); + } const auto *CU = cast<DICompileUnit>(Node); CurrentSourceLanguage = MapDWLangToCVLang(CU->getSourceLanguage()); + if (!M->getCodeViewFlag() || + CU->getEmissionKind() == DICompileUnit::NoDebug) { + Asm = nullptr; + return; + } collectGlobalVariableInfo(); @@ -636,7 +650,7 @@ void CodeViewDebug::beginModule(Module *M) { } void CodeViewDebug::endModule() { - if (!Asm || !Asm->hasDebugInfo()) + if (!CompilerInfoAsm) return; // The COFF .debug$S section consists of several subsections, each starting @@ -652,6 +666,8 @@ void CodeViewDebug::endModule() { emitObjName(); emitCompilerInformation(); endCVSubsection(CompilerInfo); + if (!Asm) + return; emitInlineeLinesSubsection(); @@ -788,7 +804,7 @@ void CodeViewDebug::emitTypeGlobalHashes() { void CodeViewDebug::emitObjName() { MCSymbol *CompilerEnd = beginSymbolRecord(SymbolKind::S_OBJNAME); - StringRef PathRef(Asm->TM.Options.ObjectFilenameForDebug); + StringRef PathRef(CompilerInfoAsm->TM.Options.ObjectFilenameForDebug); llvm::SmallString<256> PathStore(PathRef); if (PathRef.empty() || PathRef == "-") { @@ -846,7 +862,7 @@ void CodeViewDebug::emitCompilerInformation() { } using ArchType = llvm::Triple::ArchType; ArchType Arch = MMI->getModule()->getTargetTriple().getArch(); - if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb || + if (CompilerInfoAsm->TM.Options.Hotpatch || Arch == ArchType::thumb || Arch == ArchType::aarch64) { Flags |= static_cast<uint32_t>(CompileSym3Flags::HotPatch); } @@ -1015,7 +1031,7 @@ void CodeViewDebug::switchToDebugSectionForSymbol(const MCSymbol *GVSym) { const MCSymbol *KeySym = GVSec ? GVSec->getCOMDATSymbol() : nullptr; MCSectionCOFF *DebugSec = cast<MCSectionCOFF>( - Asm->getObjFileLowering().getCOFFDebugSymbolsSection()); + CompilerInfoAsm->getObjFileLowering().getCOFFDebugSymbolsSection()); DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym); OS.switchSection(DebugSec); |