[llvm] r296541 - [DWARFv5] llvm-mc support for new unit header.

Paul Robinson via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 15:40:46 PST 2017


Author: probinson
Date: Tue Feb 28 17:40:46 2017
New Revision: 296541

URL: http://llvm.org/viewvc/llvm-project?rev=296541&view=rev
Log:
[DWARFv5] llvm-mc support for new unit header.

This is for running the assembler with -g (to emit DWARF describing
the assembler source).

Differential Revision: http://reviews.llvm.org/D30475

Modified:
    llvm/trunk/lib/MC/MCDwarf.cpp
    llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s
    llvm/trunk/test/MC/ELF/gen-dwarf.s
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=296541&r1=296540&r2=296541&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Tue Feb 28 17:40:46 2017
@@ -674,7 +674,14 @@ static void EmitGenDwarfInfo(MCStreamer
   // The 2 byte DWARF version.
   MCOS->EmitIntValue(context.getDwarfVersion(), 2);
 
+  // The DWARF v5 header has unit type, address size, abbrev offset.
+  // Earlier versions have abbrev offset, address size.
   const MCAsmInfo &AsmInfo = *context.getAsmInfo();
+  int AddrSize = AsmInfo.getPointerSize();
+  if (context.getDwarfVersion() >= 5) {
+    MCOS->EmitIntValue(dwarf::DW_UT_compile, 1);
+    MCOS->EmitIntValue(AddrSize, 1);
+  }
   // 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)
@@ -682,11 +689,8 @@ static void EmitGenDwarfInfo(MCStreamer
   else
     MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4,
                           AsmInfo.needsDwarfSectionOffsetDirective());
-
-  const MCAsmInfo *asmInfo = context.getAsmInfo();
-  int AddrSize = asmInfo->getPointerSize();
-  // The 1 byte size of an address.
-  MCOS->EmitIntValue(AddrSize, 1);
+  if (context.getDwarfVersion() <= 4)
+    MCOS->EmitIntValue(AddrSize, 1);
 
   // Second part: the compile_unit DIE.
 

Modified: llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s?rev=296541&r1=296540&r2=296541&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s (original)
+++ llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s Tue Feb 28 17:40:46 2017
@@ -1,11 +1,14 @@
+// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 5 -fdebug-compilation-dir=/tmp
+// RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF45 %s
+// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC -check-prefix RELOC5 %s
 // RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -fdebug-compilation-dir=/tmp
-// RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF4 %s
-// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC %s
+// RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF45 %s
+// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC -check-prefix RELOC4 %s
 // RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 3 -fdebug-compilation-dir=/tmp
 // RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF3 %s
 // RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 2 2>&1 | FileCheck -check-prefix VERSION %s
 // RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 1 2>&1 | FileCheck -check-prefix DWARF1 %s
-// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 5 2>&1 | FileCheck -check-prefix DWARF5 %s
+// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 6 2>&1 | FileCheck -check-prefix DWARF6 %s
   .section .text, "ax"
 a:
   mov r0, r0
@@ -18,9 +21,9 @@ b:
 // DWARF: Abbrev table for offset: 0x00000000
 // DWARF: [1] DW_TAG_compile_unit DW_CHILDREN_yes
 // DWARF3:        DW_AT_stmt_list DW_FORM_data4
-// DWARF4:        DW_AT_stmt_list DW_FORM_sec_offset
+// DWARF45:       DW_AT_stmt_list DW_FORM_sec_offset
 // DWARF3:        DW_AT_ranges    DW_FORM_data4
-// DWARF4:        DW_AT_ranges    DW_FORM_sec_offset
+// DWARF45:       DW_AT_ranges    DW_FORM_sec_offset
 // DWARF:         DW_AT_name      DW_FORM_string
 // DWARF:         DW_AT_comp_dir  DW_FORM_string
 // DWARF:         DW_AT_producer  DW_FORM_string
@@ -29,8 +32,8 @@ b:
 // DWARF: .debug_info contents:
 // DWARF: 0x{{[0-9a-f]+}}: DW_TAG_compile_unit [1]
 // DWARF-NOT: DW_TAG_
-// DWARF3: DW_AT_ranges [DW_FORM_data4]           (0x00000000
-// DWARF4: DW_AT_ranges [DW_FORM_sec_offset]      (0x00000000
+// DWARF3:  DW_AT_ranges [DW_FORM_data4]           (0x00000000
+// DWARF45: DW_AT_ranges [DW_FORM_sec_offset]      (0x00000000
 
 // DWARF: 0x{{[0-9a-f]+}}:   DW_TAG_label [2] *
 // DWARF-NEXT: DW_AT_name [DW_FORM_string]     ("a")
@@ -46,10 +49,10 @@ b:
 
 
 // DWARF: .debug_line contents:
-// DWARF:      0x0000000000000000     11      0      1   0   0  is_stmt
-// DWARF-NEXT: 0x0000000000000004     11      0      1   0   0  is_stmt end_sequence
-// DWARF-NEXT: 0x0000000000000000     15      0      1   0   0  is_stmt
-// DWARF-NEXT: 0x0000000000000004     15      0      1   0   0  is_stmt end_sequence
+// DWARF:      0x0000000000000000     14      0      1   0   0  is_stmt
+// DWARF-NEXT: 0x0000000000000004     14      0      1   0   0  is_stmt end_sequence
+// DWARF-NEXT: 0x0000000000000000     18      0      1   0   0  is_stmt
+// DWARF-NEXT: 0x0000000000000004     18      0      1   0   0  is_stmt end_sequence
 
 
 // DWARF: .debug_ranges contents:
@@ -61,10 +64,14 @@ b:
 
 
 
+// Offsets are different in DWARF v5 due to different header layout.
 // RELOC: RELOCATION RECORDS FOR [.rel.debug_info]:
-// RELOC-NEXT: 00000006 R_ARM_ABS32 .debug_abbrev
-// RELOC-NEXT: 0000000c R_ARM_ABS32 .debug_line
-// RELOC-NEXT: 00000010 R_ARM_ABS32 .debug_ranges
+// RELOC4-NEXT: 00000006 R_ARM_ABS32 .debug_abbrev
+// RELOC4-NEXT: 0000000c R_ARM_ABS32 .debug_line
+// RELOC4-NEXT: 00000010 R_ARM_ABS32 .debug_ranges
+// RELOC5-NEXT: 00000008 R_ARM_ABS32 .debug_abbrev
+// RELOC5-NEXT: 0000000d R_ARM_ABS32 .debug_line
+// RELOC5-NEXT: 00000011 R_ARM_ABS32 .debug_ranges
 // RELOC-NEXT: R_ARM_ABS32 .text
 // RELOC-NEXT: R_ARM_ABS32 foo
 
@@ -81,4 +88,4 @@ b:
 // VERSION: {{.*}} warning: DWARF2 only supports one section per compilation unit
 
 // DWARF1: Dwarf version 1 is not supported.
-// DWARF5: Dwarf version 5 is not supported.
+// DWARF6: Dwarf version 6 is not supported.

Modified: llvm/trunk/test/MC/ELF/gen-dwarf.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/gen-dwarf.s?rev=296541&r1=296540&r2=296541&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/gen-dwarf.s (original)
+++ llvm/trunk/test/MC/ELF/gen-dwarf.s Tue Feb 28 17:40:46 2017
@@ -3,7 +3,8 @@
 // RUN: llvm-mc -g -dwarf-version 2 -triple  i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF2 %s
 // RUN: llvm-mc -g -dwarf-version 3 -triple  i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF3 %s
 // RUN: llvm-mc -g -triple  i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF4 %s
-// RUN: not llvm-mc -g -dwarf-version 5  -triple  i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF5 %s
+// RUN: llvm-mc -g -dwarf-version 5  -triple  i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF5 %s
+// RUN: not llvm-mc -g -dwarf-version 6  -triple  i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF6 %s
 
 
 // Test that on ELF:
@@ -35,6 +36,8 @@ foo:
 
 // ASM: .section .debug_abbrev
 // ASM-NEXT: [[ABBREV_LABEL:.Ltmp[0-9]+]]
+// DWARF5: .section .debug_abbrev
+// DWARF5-NEXT: [[ABBREV_LABEL:.Ltmp[0-9]+]]
 
 // Second instance of the section has the CU
 // ASM: .section .debug_info
@@ -43,6 +46,11 @@ foo:
 // DWARF3: .short 3
 // DWARF4: .short 4
 // ASM-NEXT: .long [[ABBREV_LABEL]]
+// DWARF5: .short 5
+// DWARF5-NEXT: .byte 1
+// DWARF5-NEXT: .byte 4
+// DWARF5-NEXT: .long [[ABBREV_LABEL]]
+
 // First .byte 1 is the abbreviation number for the compile_unit abbrev
 // ASM: .byte 1
 // ASM-NEXT: .long [[LINE_LABEL:.L[a-z0-9]+]]
@@ -51,4 +59,4 @@ foo:
 // ASM-NEXT: [[LINE_LABEL]]
 
 // DWARF1: Dwarf version 1 is not supported.
-// DWARF5: Dwarf version 5 is not supported.
+// DWARF6: Dwarf version 6 is not supported.

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=296541&r1=296540&r2=296541&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Tue Feb 28 17:40:46 2017
@@ -516,7 +516,7 @@ int main(int argc, char **argv) {
   Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
   // Default to 4 for dwarf version.
   unsigned DwarfVersion = MCOptions.DwarfVersion ? MCOptions.DwarfVersion : 4;
-  if (DwarfVersion < 2 || DwarfVersion > 4) {
+  if (DwarfVersion < 2 || DwarfVersion > 5) {
     errs() << ProgName << ": Dwarf version " << DwarfVersion
            << " is not supported." << '\n';
     return 1;




More information about the llvm-commits mailing list