Skip to content

Commit

Permalink
[DWARF5] Added support for emission of .debug_macro.dwo section
Browse files Browse the repository at this point in the history
This patch adds support for emission of following DWARFv5 macro
forms in .debug_macro.dwo section:

- DW_MACRO_start_file
- DW_MACRO_end_file
- DW_MACRO_define_strx
- DW_MACRO_undef_strx

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D78866
  • Loading branch information
SouraVX committed May 30, 2020
1 parent 0800529 commit 20c9bb4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
2 changes: 2 additions & 0 deletions llvm/include/llvm/MC/MCObjectFileInfo.h
Expand Up @@ -113,6 +113,7 @@ class MCObjectFileInfo {
MCSection *DwarfLocDWOSection = nullptr;
MCSection *DwarfStrOffDWOSection = nullptr;
MCSection *DwarfMacinfoDWOSection = nullptr;
MCSection *DwarfMacroDWOSection = nullptr;

/// The DWARF v5 string offset and address table sections.
MCSection *DwarfStrOffSection = nullptr;
Expand Down Expand Up @@ -309,6 +310,7 @@ class MCObjectFileInfo {
MCSection *getDwarfLoclistsDWOSection() const {
return DwarfLoclistsDWOSection;
}
MCSection *getDwarfMacroDWOSection() const { return DwarfMacroDWOSection; }
MCSection *getDwarfMacinfoDWOSection() const {
return DwarfMacinfoDWOSection;
}
Expand Down
16 changes: 9 additions & 7 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Expand Up @@ -1291,9 +1291,11 @@ void DwarfDebug::finalizeModuleInfo() {
// attribute.
if (CUNode->getMacros()) {
if (getDwarfVersion() >= 5) {
// FIXME: Add support for DWARFv5 DW_AT_macros attribute for split
// case.
if (!useSplitDwarf())
if (useSplitDwarf())
TheCU.addSectionDelta(
TheCU.getUnitDie(), dwarf::DW_AT_macros, U.getMacroLabelBegin(),
TLOF.getDwarfMacroDWOSection()->getBeginSymbol());
else
U.addSectionLabel(U.getUnitDie(), dwarf::DW_AT_macros,
U.getMacroLabelBegin(),
TLOF.getDwarfMacroSection()->getBeginSymbol());
Expand Down Expand Up @@ -3014,10 +3016,10 @@ void DwarfDebug::emitDebugMacinfo() {
}

void DwarfDebug::emitDebugMacinfoDWO() {
// FIXME: Add support for macro.dwo section.
if (getDwarfVersion() >= 5)
return;
emitDebugMacinfoImpl(Asm->getObjFileLowering().getDwarfMacinfoDWOSection());
auto &ObjLower = Asm->getObjFileLowering();
emitDebugMacinfoImpl(getDwarfVersion() >= 5
? ObjLower.getDwarfMacroDWOSection()
: ObjLower.getDwarfMacinfoDWOSection());
}

// DWARF5 Experimental Separate Dwarf emitters.
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/MC/MCObjectFileInfo.cpp
Expand Up @@ -473,6 +473,8 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
DwarfMacinfoDWOSection =
Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
DwarfMacroDWOSection =
Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);

DwarfLoclistsDWOSection =
Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Expand Down Expand Up @@ -649,6 +651,11 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "debug_macinfo.dwo");
DwarfMacroDWOSection = Ctx->getCOFFSection(
".debug_macro.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "debug_macro.dwo");
DwarfInfoDWOSection = Ctx->getCOFFSection(
".debug_info.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Expand Down
49 changes: 49 additions & 0 deletions llvm/test/DebugInfo/X86/debug-macro-dwo.ll
@@ -0,0 +1,49 @@
; This test checks emission of .debug_macro.dwo section when
; -gdwarf-5 -gsplit-dwarf -fdebug-macro is specified.

; RUN: %llc_dwarf -dwarf-version=5 -O0 -filetype=obj \
; RUN: -split-dwarf-file=foo.dwo < %s | llvm-dwarfdump -v - | FileCheck %s

; CHECK-LABEL: .debug_info contents:
; CHECK: DW_AT_macros [DW_FORM_sec_offset] (0x00000000)

; CHECK-LABEL: .debug_macro.dwo contents:
; CHECK-NEXT: 0x00000000:
; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02
; CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
; CHECK-NEXT: DW_MACRO_start_file - lineno: 1 filenum: 1
; CHECK-NEXT: DW_MACRO_define_strx - lineno: 1 macro: FOO 5
; CHECK-NEXT: DW_MACRO_end_file
; CHECK-NEXT: DW_MACRO_start_file - lineno: 2 filenum: 2
; CHECK-NEXT: DW_MACRO_undef_strx - lineno: 14 macro: YEA
; CHECK-NEXT: DW_MACRO_end_file
; CHECK-NEXT: DW_MACRO_undef_strx - lineno: 14 macro: YEA
; CHECK-NEXT: DW_MACRO_end_file

; ModuleID = 'test.c'
source_filename = "test.c"
target datalayout = "e-m:e-p200:32:32-p201:32:32-p202:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!14, !15, !16}
!llvm.ident = !{!17}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "test.dwo", emissionKind: FullDebug, enums: !2, macros: !3, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/home/", checksumkind: CSK_MD5, checksum: "ef6a7032e0c7ceeef614583f2c00dc80")
!2 = !{}
!3 = !{!4}
!4 = !DIMacroFile(file: !1, nodes: !5)
!5 = !{!6, !10, !13}
!6 = !DIMacroFile(line: 1, file: !7, nodes: !8)
!7 = !DIFile(filename: "./foo.h", directory: "/home/", checksumkind: CSK_MD5, checksum: "0f0cd0e15b44f49d3944992c8dc28661")
!8 = !{!9}
!9 = !DIMacro(type: DW_MACINFO_define, line: 1, name: "FOO", value: "5")
!10 = !DIMacroFile(line: 2, file: !11, nodes: !12)
!11 = !DIFile(filename: "./bar.h", directory: "/home/", checksumkind: CSK_MD5, checksum: "bf4b34c263eaaa1d7085c18243b8d100")
!12 = !{!13}
!13 = !DIMacro(type: DW_MACINFO_undef, line: 14, name: "YEA")
!14 = !{i32 7, !"Dwarf Version", i32 5}
!15 = !{i32 2, !"Debug Info Version", i32 3}
!16 = !{i32 1, !"wchar_size", i32 4}
!17 = !{!"clang version 11.0.0"}

0 comments on commit 20c9bb4

Please sign in to comment.