[llvm] 18f23b3 - [DebugInfo] Fix emitting DWARF64 type units (10/19).

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


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

URL: https://github.com/llvm/llvm-project/commit/18f23b3ecc6d0cec31c655b7ae9054cf0edf630e
DIFF: https://github.com/llvm/llvm-project/commit/18f23b3ecc6d0cec31c655b7ae9054cf0edf630e.diff

LOG: [DebugInfo] Fix emitting DWARF64 type units (10/19).

The patch fixes emitting the offset to the type DIE. All other fields
are already fixed in previous patches.

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

Added: 
    llvm/test/DebugInfo/X86/debug-types-dwarf64.ll

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 8f738936bd51..b469f91401f2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1739,8 +1739,7 @@ void DwarfTypeUnit::emitHeader(bool UseOffsets) {
   Asm->OutStreamer->emitIntValue(TypeSignature, sizeof(TypeSignature));
   Asm->OutStreamer->AddComment("Type DIE Offset");
   // In a skeleton type unit there is no type DIE so emit a zero offset.
-  Asm->OutStreamer->emitIntValue(Ty ? Ty->getOffset() : 0,
-                                 sizeof(Ty->getOffset()));
+  Asm->emitDwarfLengthOrOffset(Ty ? Ty->getOffset() : 0);
 }
 
 DIE::value_iterator

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index cc91aec68b8a..918e5045828d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -356,7 +356,7 @@ class DwarfTypeUnit final : public DwarfUnit {
   void emitHeader(bool UseOffsets) override;
   unsigned getHeaderSize() const override {
     return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
-           sizeof(uint32_t);                               // Type DIE Offset
+           Asm->getDwarfOffsetByteSize();                  // Type DIE Offset
   }
   void addGlobalName(StringRef Name, const DIE &Die,
                      const DIScope *Context) override;

diff  --git a/llvm/test/DebugInfo/X86/debug-types-dwarf64.ll b/llvm/test/DebugInfo/X86/debug-types-dwarf64.ll
new file mode 100644
index 000000000000..7e88d7ef6a3b
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/debug-types-dwarf64.ll
@@ -0,0 +1,55 @@
+; This checks that .debug_types can be generated in the DWARF64 format.
+
+; RUN: llc -mtriple=x86_64 -dwarf-version=4 -dwarf64 -generate-type-units -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-types -v %t | FileCheck %s
+
+; CHECK:      .debug_types contents:
+; CHECK-NEXT: Type Unit: {{.+}}, format = DWARF64, {{.+}}, type_offset = 0x[[OFF:.+]] (next unit at
+
+; CHECK:      0x00000027:     DW_TAG_type_unit
+
+; CHECK:      0x0000[[OFF]]:    DW_TAG_structure_type
+; CHECK-NEXT:                     DW_AT_calling_convention
+; CHECK-NEXT:                     DW_AT_name [DW_FORM_strp] ({{.+}} = "Foo")
+
+; CHECK:      0x{{.+}}:           DW_TAG_member
+; CHECK-NEXT:                       DW_AT_name [DW_FORM_strp] ({{.+}} = "bar")
+; CHECK-NEXT:                       DW_AT_type [DW_FORM_ref4] (cu + 0x[[BTOFF:.+]] => {0x0000[[BTOFF]]} "int")
+
+; CHECK:      0x{{.+}}:           NULL
+
+; CHECK:      0x0000[[BTOFF]]:  DW_TAG_base_type [4]  
+; CHECK-NEXT:                     DW_AT_name [DW_FORM_strp] ({{.+}} = "int")
+
+; CHECK:      0x{{.+}}:         NULL
+
+; IR generated and reduced from:
+; $ cat foo.cc
+; struct Foo { int bar; };
+; Foo foo;
+; $ clang -g -S -emit-llvm foo.cc -o foo.ll
+
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.Foo = type { i32 }
+
+ at foo = dso_local global %struct.Foo zeroinitializer, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!10, !11, !12}
+!llvm.ident = !{!13}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, 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.cc", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !3, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTS3Foo")
+!7 = !{!8}
+!8 = !DIDerivedType(tag: DW_TAG_member, name: "bar", scope: !6, file: !3, line: 1, baseType: !9, size: 32)
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !{i32 7, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"wchar_size", i32 4}
+!13 = !{!"clang version 12.0.0"}


        


More information about the llvm-commits mailing list