[llvm] 1dfcce5 - [MC] Generate a compilation unit in the 64-bit DWARF format [3/7]

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 16 01:51:33 PDT 2020


Author: Igor Kudrin
Date: 2020-06-16T15:50:13+07:00
New Revision: 1dfcce539501e235d78a96d13ec46ea83a2f8516

URL: https://github.com/llvm/llvm-project/commit/1dfcce539501e235d78a96d13ec46ea83a2f8516
DIFF: https://github.com/llvm/llvm-project/commit/1dfcce539501e235d78a96d13ec46ea83a2f8516.diff

LOG: [MC] Generate a compilation unit in the 64-bit DWARF format [3/7]

The patch enables producing DWARF64 compilation units and fixes
generating references to .debug_abbrev and .debug_line sections.
A similar change for .debug_ranges/.debug_rnglists will be added
in a forthcoming patch.

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

Added: 
    llvm/test/MC/MachO/gen-dwarf64.s

Modified: 
    llvm/lib/MC/MCDwarf.cpp
    llvm/test/MC/ELF/gen-dwarf64.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index c665f9a9630b..b4b2b76af967 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -954,11 +954,19 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
 
   // First part: the header.
 
-  // The 4 byte total length of the information for this compilation unit, not
-  // including these 4 bytes.
+  unsigned UnitLengthBytes =
+      dwarf::getUnitLengthFieldByteSize(context.getDwarfFormat());
+  unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
+
+  if (context.getDwarfFormat() == dwarf::DWARF64)
+    // Emit DWARF64 mark.
+    MCOS->emitInt32(dwarf::DW_LENGTH_DWARF64);
+
+  // The 4 (8 for DWARF64) byte total length of the information for this
+  // compilation unit, not including the unit length field itself.
   const MCExpr *Length =
-      MakeStartMinusEndExpr(context, *InfoStart, *InfoEnd, 4);
-  emitAbsValue(*MCOS, Length, 4);
+      MakeStartMinusEndExpr(context, *InfoStart, *InfoEnd, UnitLengthBytes);
+  emitAbsValue(*MCOS, Length, OffsetSize);
 
   // The 2 byte DWARF version.
   MCOS->emitInt16(context.getDwarfVersion());
@@ -971,13 +979,14 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
     MCOS->emitInt8(dwarf::DW_UT_compile);
     MCOS->emitInt8(AddrSize);
   }
-  // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
-  // it is at the start of that section so this is zero.
-  if (AbbrevSectionSymbol == nullptr)
-    MCOS->emitInt32(0);
-  else
-    MCOS->emitSymbolValue(AbbrevSectionSymbol, 4,
+  // The 4 (8 for DWARF64) byte offset to the debug abbrevs from the start of
+  // the .debug_abbrev.
+  if (AbbrevSectionSymbol)
+    MCOS->emitSymbolValue(AbbrevSectionSymbol, OffsetSize,
                           AsmInfo.needsDwarfSectionOffsetDirective());
+  else
+    // Since the abbrevs are at the start of the section, the offset is zero.
+    MCOS->emitIntValue(0, OffsetSize);
   if (context.getDwarfVersion() <= 4)
     MCOS->emitInt8(AddrSize);
 
@@ -986,13 +995,14 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
   // The DW_TAG_compile_unit DIE abbrev (1).
   MCOS->emitULEB128IntValue(1);
 
-  // DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section,
-  // which is at the start of that section so this is zero.
+  // DW_AT_stmt_list, a 4 (8 for DWARF64) byte offset from the start of the
+  // .debug_line section.
   if (LineSectionSymbol)
-    MCOS->emitSymbolValue(LineSectionSymbol, 4,
+    MCOS->emitSymbolValue(LineSectionSymbol, OffsetSize,
                           AsmInfo.needsDwarfSectionOffsetDirective());
   else
-    MCOS->emitInt32(0);
+    // The line table is at the start of the section, so the offset is zero.
+    MCOS->emitIntValue(0, OffsetSize);
 
   if (RangesSymbol) {
     // There are multiple sections containing code, so we must use

diff  --git a/llvm/test/MC/ELF/gen-dwarf64.s b/llvm/test/MC/ELF/gen-dwarf64.s
index 8d456849ee11..8a0edd898248 100644
--- a/llvm/test/MC/ELF/gen-dwarf64.s
+++ b/llvm/test/MC/ELF/gen-dwarf64.s
@@ -5,10 +5,20 @@
 # RUN: llvm-dwarfdump -v %t5.o | FileCheck --check-prefixes=DUMP,DUMP5 %s
 
 ## The references to other debug info sections are 64-bit, as required for DWARF64.
+# REL:         Section ({{[0-9]+}}) .rela.debug_info {
+# REL-NEXT:      R_X86_64_64 .debug_abbrev 0x0
+# REL-NEXT:      R_X86_64_64 .debug_line 0x0
 # REL5:        Section ({{[0-9]+}}) .rela.debug_line {
 # REL5-NEXT:     R_X86_64_64 .debug_line_str 0x0
 # REL5-NEXT:     R_X86_64_64 .debug_line_str 0x
 
+# DUMP:       .debug_info contents:
+# DUMP-NEXT:  0x00000000: Compile Unit: {{.*}} format = DWARF64
+# DUMP:       DW_TAG_compile_unit [1] *
+# DUMP5-NEXT:   DW_AT_stmt_list [DW_FORM_sec_offset] (0x0000000000000000)
+# DUMP:       DW_TAG_label [2]
+# DUMP-NEXT:    DW_AT_name [DW_FORM_string] ("foo")
+
 # DUMP:       .debug_line contents:
 # DUMP-NEXT:  debug_line[0x00000000]
 # DUMP-NEXT:  Line table prologue:
@@ -22,3 +32,7 @@
 # DUMP5:      .debug_line_str contents:
 # DUMP5-NEXT: 0x00000000: "[[DIR]]"
 # DUMP5-NEXT: 0x[[FILEOFF]]: "[[FILE]]"
+
+    .section .foo, "ax", @progbits
+foo:
+    nop

diff  --git a/llvm/test/MC/MachO/gen-dwarf64.s b/llvm/test/MC/MachO/gen-dwarf64.s
new file mode 100644
index 000000000000..466948eefb69
--- /dev/null
+++ b/llvm/test/MC/MachO/gen-dwarf64.s
@@ -0,0 +1,14 @@
+// This checks that llvm-mc is able to produce 64-bit debug info.
+
+// RUN: llvm-mc -g -dwarf64 -triple x86_64-apple-darwin10 %s -filetype=obj -o %t
+// RUN: llvm-dwarfdump -v %t | FileCheck %s
+
+// CHECK:      .debug_info contents:
+// CHECK-NEXT: 0x00000000: Compile Unit: {{.*}} format = DWARF64, version = {{.*}}, abbr_offset = 0x0000, addr_size = 0x08
+// CHECK:      DW_TAG_compile_unit [1] *
+// CHECK-NEXT:   DW_AT_stmt_list [DW_FORM_sec_offset] (0x0000000000000000)
+// CHECK:      DW_TAG_label [2]
+// CHECK-NEXT:   DW_AT_name [DW_FORM_string] ("foo")
+
+_foo:
+    nop


        


More information about the llvm-commits mailing list