[llvm] b5f8959 - [MC] Generate .debug_aranges in the 64-bit DWARF format [4/7]

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


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

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

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

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index b4b2b76af967..a9820f844f33 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -875,9 +875,13 @@ static void EmitGenDwarfAranges(MCStreamer *MCOS,
 
   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 @@ static void EmitGenDwarfAranges(MCStreamer *MCOS,
   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.

diff  --git a/llvm/test/MC/ELF/gen-dwarf64.s b/llvm/test/MC/ELF/gen-dwarf64.s
index 8a0edd898248..3fd27c36d9b0 100644
--- a/llvm/test/MC/ELF/gen-dwarf64.s
+++ b/llvm/test/MC/ELF/gen-dwarf64.s
@@ -1,13 +1,15 @@
 ## This checks that llvm-mc is able to produce 64-bit debug info.
 
 # RUN: llvm-mc -g -dwarf-version 5 -dwarf64 -triple x86_64 %s -filetype=obj -o %t5.o
-# RUN: llvm-readobj -r %t5.o | FileCheck --check-prefixes=REL,REL5 %s
+# RUN: llvm-readobj -r %t5.o | FileCheck --check-prefixes=REL,REL5 %s --implicit-check-not="R_{{.*}} .debug_"
 # 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
+# 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,11 @@
 # DUMP:       DW_TAG_label [2]
 # DUMP-NEXT:    DW_AT_name [DW_FORM_string] ("foo")
 
+# DUMP:       .debug_aranges contents:
+# DUMP-NEXT:  Address Range Header: length = 0x0000000000000034, format = DWARF64, version = 0x0002, cu_offset = 0x0000000000000000, addr_size = 0x08, seg_size = 0x00
+# DUMP-NEXT:  [0x0000000000000000,  0x0000000000000001)
+# DUMP-EMPTY:
+
 # DUMP:       .debug_line contents:
 # DUMP-NEXT:  debug_line[0x00000000]
 # DUMP-NEXT:  Line table prologue:

diff  --git a/llvm/test/MC/MachO/gen-dwarf64.s b/llvm/test/MC/MachO/gen-dwarf64.s
index 466948eefb69..e7dedac2f075 100644
--- a/llvm/test/MC/MachO/gen-dwarf64.s
+++ b/llvm/test/MC/MachO/gen-dwarf64.s
@@ -10,5 +10,10 @@
 // CHECK:      DW_TAG_label [2]
 // CHECK-NEXT:   DW_AT_name [DW_FORM_string] ("foo")
 
+// CHECK:      .debug_aranges contents:
+// CHECK-NEXT: Address Range Header: length = 0x0000000000000034, format = DWARF64, version = 0x0002, cu_offset = 0x0000000000000000, addr_size = 0x08, seg_size = 0x00
+// CHECK-NEXT: [0x0000000000000000,  0x0000000000000001)
+// CHECK-EMPTY:
+
 _foo:
     nop


        


More information about the llvm-commits mailing list