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

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 05:24:45 PDT 2020


ikudrin created this revision.
ikudrin added reviewers: dblaikie, jhenderson, aprantl, probinson, MaskRay, echristo.
ikudrin added projects: LLVM, debug-info.
Herald added subscribers: hiraditya, emaste.
Herald added a reviewer: espindola.
ikudrin added a parent revision: D81144: [MC] Generate .debug_line in the 64-bit DWARF format [2/7].
ikudrin added a child revision: D81146: [MC] Generate .debug_aranges in the 64-bit DWARF format [4/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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81145

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


Index: llvm/test/MC/ELF/gen-dwarf64.s
===================================================================
--- llvm/test/MC/ELF/gen-dwarf64.s
+++ llvm/test/MC/ELF/gen-dwarf64.s
@@ -6,10 +6,19 @@
 
 ## The references to other debug info sections are 64-bit, as required for DWARF64.
 # REL:       Relocations [
+# 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:
+# DUMP-SAME:    format = DWARF64
+# DUMP:       DW_TAG_compile_unit [1] *
+# DUMP5-NEXT:   DW_AT_stmt_list [DW_FORM_sec_offset] (0x0000000000000000)
+
 # DUMP:       .debug_line contents:
 # DUMP-NEXT:  debug_line[0x00000000]
 # DUMP-NEXT:  Line table prologue:
@@ -23,3 +32,7 @@
 # DUMP5:      .debug_line_str contents:
 # DUMP5-NEXT: 0x00000000: "[[DIR]]"
 # DUMP5-NEXT: 0x[[FILEOFF]]: "[[FILE]]"
+
+    .section .foo, "ax", @progbits
+foo:
+    nop
Index: llvm/lib/MC/MCDwarf.cpp
===================================================================
--- llvm/lib/MC/MCDwarf.cpp
+++ llvm/lib/MC/MCDwarf.cpp
@@ -954,11 +954,19 @@
 
   // 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,12 +979,12 @@
     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.
+  // The 4 (8 for DWARF64) 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);
+    MCOS->emitIntValue(0, OffsetSize);
   else
-    MCOS->emitSymbolValue(AbbrevSectionSymbol, 4,
+    MCOS->emitSymbolValue(AbbrevSectionSymbol, OffsetSize,
                           AsmInfo.needsDwarfSectionOffsetDirective());
   if (context.getDwarfVersion() <= 4)
     MCOS->emitInt8(AddrSize);
@@ -986,13 +994,13 @@
   // 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, which is at the start of that section so this is zero.
   if (LineSectionSymbol)
-    MCOS->emitSymbolValue(LineSectionSymbol, 4,
+    MCOS->emitSymbolValue(LineSectionSymbol, OffsetSize,
                           AsmInfo.needsDwarfSectionOffsetDirective());
   else
-    MCOS->emitInt32(0);
+    MCOS->emitIntValue(0, OffsetSize);
 
   if (RangesSymbol) {
     // There are multiple sections containing code, so we must use


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81145.268427.patch
Type: text/x-patch
Size: 3787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200604/15632e79/attachment.bin>


More information about the llvm-commits mailing list