[PATCH] D81146: [MC] Generate .debug_aranges in the 64-bit DWARF format [4/7]

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 05:24:46 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: D81145: [MC] Generate a compilation unit in the 64-bit DWARF format [3/7].
ikudrin added a child revision: D81147: [MC] Generate .debug_rnglists in the 64-bit DWARF format [5/7].

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81146

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
@@ -9,6 +9,8 @@
 # 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
+# REL:         Section ({{[0-9]+}}) .rela.debug_aranges {
+# REL-NEXT:      R_X86_64_64 .debug_info 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
@@ -19,6 +21,12 @@
 # DUMP:       DW_TAG_compile_unit [1] *
 # DUMP5-NEXT:   DW_AT_stmt_list [DW_FORM_sec_offset] (0x0000000000000000)
 
+# DUMP:       .debug_aranges contents:
+# DUMP-NEXT:  Address Range Header: 
+# DUMP-SAME:    format = DWARF64
+# DUMP-NEXT:  [0x0000000000000000,  0x0000000000000001)
+# DUMP-EMPTY:
+
 # DUMP:       .debug_line contents:
 # DUMP-NEXT:  debug_line[0x00000000]
 # DUMP-NEXT:  Line table prologue:
Index: llvm/lib/MC/MCDwarf.cpp
===================================================================
--- llvm/lib/MC/MCDwarf.cpp
+++ llvm/lib/MC/MCDwarf.cpp
@@ -875,9 +875,13 @@
 
   MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
 
+  unsigned UnitLengthBytes =
+      dwarf::getUnitLengthFieldByteSize(context.getDwarfFormat());
+  unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
+
   // This will be the length of the .debug_aranges section, first account for
   // the size of each item in the header (see below where we emit these items).
-  int Length = 4 + 2 + 4 + 1 + 1;
+  int Length = UnitLengthBytes + 2 + OffsetSize + 1 + 1;
 
   // Figure the padding after the header before the table of address and size
   // pairs who's values are PointerSize'ed.
@@ -895,17 +899,21 @@
   Length += 2 * AddrSize;
 
   // Emit the header for this section.
-  // The 4 byte length not including the 4 byte value for the length.
-  MCOS->emitInt32(Length - 4);
+  if (context.getDwarfFormat() == dwarf::DWARF64)
+    // The DWARF64 mark.
+    MCOS->emitInt32(dwarf::DW_LENGTH_DWARF64);
+  // The 4 (8 for DWARF64) byte length not including the length of the unit
+  // length field itself.
+  MCOS->emitIntValue(Length - UnitLengthBytes, OffsetSize);
   // The 2 byte version, which is 2.
   MCOS->emitInt16(2);
-  // The 4 byte offset to the compile unit in the .debug_info from the start
-  // of the .debug_info.
+  // The 4 (8 for DWARF64) byte offset to the compile unit in the .debug_info
+  // from the start of the .debug_info.
   if (InfoSectionSymbol)
-    MCOS->emitSymbolValue(InfoSectionSymbol, 4,
+    MCOS->emitSymbolValue(InfoSectionSymbol, OffsetSize,
                           asmInfo->needsDwarfSectionOffsetDirective());
   else
-    MCOS->emitInt32(0);
+    MCOS->emitIntValue(0, OffsetSize);
   // The 1 byte size of an address.
   MCOS->emitInt8(AddrSize);
   // The 1 byte size of a segment descriptor, we use a value of zero.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81146.268429.patch
Type: text/x-patch
Size: 3041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200604/8fca83c0/attachment.bin>


More information about the llvm-commits mailing list