[llvm] 924dc58 - [DebugInfo] Fix emitting DWARF64 DWO compilation units and string offset tables (9/19).

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 22:24:33 PDT 2020


Author: Igor Kudrin
Date: 2020-09-15T11:31:00+07:00
New Revision: 924dc5807690f9ee0a84e407e8cb943511845bf5

URL: https://github.com/llvm/llvm-project/commit/924dc5807690f9ee0a84e407e8cb943511845bf5
DIFF: https://github.com/llvm/llvm-project/commit/924dc5807690f9ee0a84e407e8cb943511845bf5.diff

LOG: [DebugInfo] Fix emitting DWARF64 DWO compilation units and string offset tables (9/19).

These two fixes are better to go together because llvm-dwarfdump is
unable to dump a table when another one is malformed.

Differential Revision: https://reviews.llvm.org/D87018

Added: 
    llvm/test/DebugInfo/X86/debug-info-dwo-dwarf64.ll
    llvm/test/DebugInfo/X86/debug-str-offsets-dwo-dwarf64.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
index 731d7c19c47b..a4cb497ec502 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
@@ -120,7 +120,7 @@ void DwarfStringPool::emit(AsmPrinter &Asm, MCSection *StrSection,
     }
 
     Asm.OutStreamer->SwitchSection(OffsetSection);
-    unsigned size = 4; // FIXME: DWARF64 is 8.
+    unsigned size = Asm.getDwarfOffsetByteSize();
     for (const auto &Entry : Entries)
       if (UseRelativeOffsets)
         Asm.emitDwarfStringOffset(Entry->getValue());

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 0173a8ea2fac..8f738936bd51 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1720,7 +1720,7 @@ void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) {
   Asm->OutStreamer->AddComment("Offset Into Abbrev. Section");
   const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
   if (UseOffsets)
-    Asm->emitInt32(0);
+    Asm->emitDwarfLengthOrOffset(0);
   else
     Asm->emitDwarfSymbolReference(
         TLOF.getDwarfAbbrevSection()->getBeginSymbol(), false);

diff  --git a/llvm/test/DebugInfo/X86/debug-info-dwo-dwarf64.ll b/llvm/test/DebugInfo/X86/debug-info-dwo-dwarf64.ll
new file mode 100644
index 000000000000..acc2fded6912
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/debug-info-dwo-dwarf64.ll
@@ -0,0 +1,32 @@
+; This checks that .debug_info.dwo can be generated in the DWARF64 format.
+
+; RUN: llc -mtriple=x86_64 -dwarf-version=5 -dwarf64 -split-dwarf-file=foo.dwo -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+
+; CHECK:      .debug_info.dwo contents:
+; CHECK-NEXT: Compile Unit: {{.+}}, format = DWARF64, version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset = 0x0000,
+
+; IR generated and reduced from:
+; $ cat foo.c
+; int foo;
+; $ clang -g -S -emit-llvm foo.c -o foo.ll
+
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = dso_local global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9}
+!llvm.ident = !{!10}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "foo.c", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{i32 7, !"Dwarf Version", i32 4}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 4}
+!10 = !{!"clang version 12.0.0"}

diff  --git a/llvm/test/DebugInfo/X86/debug-str-offsets-dwo-dwarf64.ll b/llvm/test/DebugInfo/X86/debug-str-offsets-dwo-dwarf64.ll
new file mode 100644
index 000000000000..1366c195f60b
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/debug-str-offsets-dwo-dwarf64.ll
@@ -0,0 +1,56 @@
+; This checks that .debug_str_offsets.dwo can be generated in the DWARF64 format.
+
+; RUN: llc -mtriple=x86_64 -dwarf-version=5 -dwarf64 -split-dwarf-file=foo.dwo -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-info -debug-str -debug-str-offsets -v %t | \
+; RUN:   FileCheck %s
+
+; CHECK:      .debug_info.dwo contents:
+; CHECK-NEXT: Compile Unit: {{.*}}, format = DWARF64,
+; CHECK:      DW_TAG_compile_unit [1] *
+; CHECK:        DW_AT_producer [DW_FORM_strx1] (indexed (00000002) string = "clang version 12.0.0")
+; CHECK:        DW_AT_name [DW_FORM_strx1] (indexed (00000003) string = "foo.c")
+; CHECK:        DW_AT_dwo_name [DW_FORM_strx1] (indexed (00000004) string = "foo.dwo")
+; CHECK:      DW_TAG_variable [2]
+; CHECK:        DW_AT_name [DW_FORM_strx1] (indexed (00000000) string = "foo")
+; CHECK:      DW_TAG_base_type [3]
+; CHECK:        DW_AT_name [DW_FORM_strx1] (indexed (00000001) string = "int")
+
+; CHECK:      .debug_str.dwo contents:
+; CHECK-NEXT: 0x00000000: "foo"
+; CHECK-NEXT: 0x00000004: "int"
+; CHECK-NEXT: 0x00000008: "clang version 12.0.0"
+; CHECK-NEXT: 0x0000001d: "foo.c"
+; CHECK-NEXT: 0x00000023: "foo.dwo"
+
+; CHECK:      .debug_str_offsets.dwo contents:
+; CHECK-NEXT: 0x00000000: Contribution size = 44, Format = DWARF64, Version = 5
+; CHECK-NEXT: 0x00000010: 0000000000000000 "foo"
+; CHECK-NEXT: 0x00000018: 0000000000000004 "int"
+; CHECK-NEXT: 0x00000020: 0000000000000008 "clang version 12.0.0"
+; CHECK-NEXT: 0x00000028: 000000000000001d "foo.c"
+; CHECK-NEXT: 0x00000030: 0000000000000023 "foo.dwo"
+
+; IR generated and reduced from:
+; $ cat foo.c
+; int foo;
+; $ clang -g -S -emit-llvm foo.c -o foo.ll
+
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = dso_local global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9}
+!llvm.ident = !{!10}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "foo.c", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{i32 7, !"Dwarf Version", i32 4}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 4}
+!10 = !{!"clang version 12.0.0"}


        


More information about the llvm-commits mailing list