Skip to content

Commit dccb4fe

Browse files
committedFeb 28, 2017
[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 llvm-svn: 296541
1 parent 7d7409e commit dccb4fe

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed
 

‎llvm/lib/MC/MCDwarf.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -674,19 +674,23 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
674674
// The 2 byte DWARF version.
675675
MCOS->EmitIntValue(context.getDwarfVersion(), 2);
676676

677+
// The DWARF v5 header has unit type, address size, abbrev offset.
678+
// Earlier versions have abbrev offset, address size.
677679
const MCAsmInfo &AsmInfo = *context.getAsmInfo();
680+
int AddrSize = AsmInfo.getPointerSize();
681+
if (context.getDwarfVersion() >= 5) {
682+
MCOS->EmitIntValue(dwarf::DW_UT_compile, 1);
683+
MCOS->EmitIntValue(AddrSize, 1);
684+
}
678685
// The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
679686
// it is at the start of that section so this is zero.
680687
if (AbbrevSectionSymbol == nullptr)
681688
MCOS->EmitIntValue(0, 4);
682689
else
683690
MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4,
684691
AsmInfo.needsDwarfSectionOffsetDirective());
685-
686-
const MCAsmInfo *asmInfo = context.getAsmInfo();
687-
int AddrSize = asmInfo->getPointerSize();
688-
// The 1 byte size of an address.
689-
MCOS->EmitIntValue(AddrSize, 1);
692+
if (context.getDwarfVersion() <= 4)
693+
MCOS->EmitIntValue(AddrSize, 1);
690694

691695
// Second part: the compile_unit DIE.
692696

‎llvm/test/MC/ARM/dwarf-asm-multiple-sections.s

+22-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 5 -fdebug-compilation-dir=/tmp
2+
// RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF45 %s
3+
// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC -check-prefix RELOC5 %s
14
// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -fdebug-compilation-dir=/tmp
2-
// RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF4 %s
3-
// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC %s
5+
// RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF45 %s
6+
// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC -check-prefix RELOC4 %s
47
// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 3 -fdebug-compilation-dir=/tmp
58
// RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF -check-prefix DWARF3 %s
69
// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 2 2>&1 | FileCheck -check-prefix VERSION %s
710
// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 1 2>&1 | FileCheck -check-prefix DWARF1 %s
8-
// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 5 2>&1 | FileCheck -check-prefix DWARF5 %s
11+
// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 6 2>&1 | FileCheck -check-prefix DWARF6 %s
912
.section .text, "ax"
1013
a:
1114
mov r0, r0
@@ -18,9 +21,9 @@ b:
1821
// DWARF: Abbrev table for offset: 0x00000000
1922
// DWARF: [1] DW_TAG_compile_unit DW_CHILDREN_yes
2023
// DWARF3: DW_AT_stmt_list DW_FORM_data4
21-
// DWARF4: DW_AT_stmt_list DW_FORM_sec_offset
24+
// DWARF45: DW_AT_stmt_list DW_FORM_sec_offset
2225
// DWARF3: DW_AT_ranges DW_FORM_data4
23-
// DWARF4: DW_AT_ranges DW_FORM_sec_offset
26+
// DWARF45: DW_AT_ranges DW_FORM_sec_offset
2427
// DWARF: DW_AT_name DW_FORM_string
2528
// DWARF: DW_AT_comp_dir DW_FORM_string
2629
// DWARF: DW_AT_producer DW_FORM_string
@@ -29,8 +32,8 @@ b:
2932
// DWARF: .debug_info contents:
3033
// DWARF: 0x{{[0-9a-f]+}}: DW_TAG_compile_unit [1]
3134
// DWARF-NOT: DW_TAG_
32-
// DWARF3: DW_AT_ranges [DW_FORM_data4] (0x00000000
33-
// DWARF4: DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
35+
// DWARF3: DW_AT_ranges [DW_FORM_data4] (0x00000000
36+
// DWARF45: DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
3437

3538
// DWARF: 0x{{[0-9a-f]+}}: DW_TAG_label [2] *
3639
// DWARF-NEXT: DW_AT_name [DW_FORM_string] ("a")
@@ -46,10 +49,10 @@ b:
4649

4750

4851
// DWARF: .debug_line contents:
49-
// DWARF: 0x0000000000000000 11 0 1 0 0 is_stmt
50-
// DWARF-NEXT: 0x0000000000000004 11 0 1 0 0 is_stmt end_sequence
51-
// DWARF-NEXT: 0x0000000000000000 15 0 1 0 0 is_stmt
52-
// DWARF-NEXT: 0x0000000000000004 15 0 1 0 0 is_stmt end_sequence
52+
// DWARF: 0x0000000000000000 14 0 1 0 0 is_stmt
53+
// DWARF-NEXT: 0x0000000000000004 14 0 1 0 0 is_stmt end_sequence
54+
// DWARF-NEXT: 0x0000000000000000 18 0 1 0 0 is_stmt
55+
// DWARF-NEXT: 0x0000000000000004 18 0 1 0 0 is_stmt end_sequence
5356

5457

5558
// DWARF: .debug_ranges contents:
@@ -61,10 +64,14 @@ b:
6164

6265

6366

67+
// Offsets are different in DWARF v5 due to different header layout.
6468
// RELOC: RELOCATION RECORDS FOR [.rel.debug_info]:
65-
// RELOC-NEXT: 00000006 R_ARM_ABS32 .debug_abbrev
66-
// RELOC-NEXT: 0000000c R_ARM_ABS32 .debug_line
67-
// RELOC-NEXT: 00000010 R_ARM_ABS32 .debug_ranges
69+
// RELOC4-NEXT: 00000006 R_ARM_ABS32 .debug_abbrev
70+
// RELOC4-NEXT: 0000000c R_ARM_ABS32 .debug_line
71+
// RELOC4-NEXT: 00000010 R_ARM_ABS32 .debug_ranges
72+
// RELOC5-NEXT: 00000008 R_ARM_ABS32 .debug_abbrev
73+
// RELOC5-NEXT: 0000000d R_ARM_ABS32 .debug_line
74+
// RELOC5-NEXT: 00000011 R_ARM_ABS32 .debug_ranges
6875
// RELOC-NEXT: R_ARM_ABS32 .text
6976
// RELOC-NEXT: R_ARM_ABS32 foo
7077

@@ -81,4 +88,4 @@ b:
8188
// VERSION: {{.*}} warning: DWARF2 only supports one section per compilation unit
8289

8390
// DWARF1: Dwarf version 1 is not supported.
84-
// DWARF5: Dwarf version 5 is not supported.
91+
// DWARF6: Dwarf version 6 is not supported.

‎llvm/test/MC/ELF/gen-dwarf.s

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// RUN: llvm-mc -g -dwarf-version 2 -triple i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF2 %s
44
// RUN: llvm-mc -g -dwarf-version 3 -triple i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF3 %s
55
// RUN: llvm-mc -g -triple i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF4 %s
6-
// RUN: not llvm-mc -g -dwarf-version 5 -triple i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF5 %s
6+
// RUN: llvm-mc -g -dwarf-version 5 -triple i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF5 %s
7+
// RUN: not llvm-mc -g -dwarf-version 6 -triple i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF6 %s
78

89

910
// Test that on ELF:
@@ -35,6 +36,8 @@ foo:
3536

3637
// ASM: .section .debug_abbrev
3738
// ASM-NEXT: [[ABBREV_LABEL:.Ltmp[0-9]+]]
39+
// DWARF5: .section .debug_abbrev
40+
// DWARF5-NEXT: [[ABBREV_LABEL:.Ltmp[0-9]+]]
3841

3942
// Second instance of the section has the CU
4043
// ASM: .section .debug_info
@@ -43,6 +46,11 @@ foo:
4346
// DWARF3: .short 3
4447
// DWARF4: .short 4
4548
// ASM-NEXT: .long [[ABBREV_LABEL]]
49+
// DWARF5: .short 5
50+
// DWARF5-NEXT: .byte 1
51+
// DWARF5-NEXT: .byte 4
52+
// DWARF5-NEXT: .long [[ABBREV_LABEL]]
53+
4654
// First .byte 1 is the abbreviation number for the compile_unit abbrev
4755
// ASM: .byte 1
4856
// ASM-NEXT: .long [[LINE_LABEL:.L[a-z0-9]+]]
@@ -51,4 +59,4 @@ foo:
5159
// ASM-NEXT: [[LINE_LABEL]]
5260

5361
// DWARF1: Dwarf version 1 is not supported.
54-
// DWARF5: Dwarf version 5 is not supported.
62+
// DWARF6: Dwarf version 6 is not supported.

‎llvm/tools/llvm-mc/llvm-mc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ int main(int argc, char **argv) {
516516
Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
517517
// Default to 4 for dwarf version.
518518
unsigned DwarfVersion = MCOptions.DwarfVersion ? MCOptions.DwarfVersion : 4;
519-
if (DwarfVersion < 2 || DwarfVersion > 4) {
519+
if (DwarfVersion < 2 || DwarfVersion > 5) {
520520
errs() << ProgName << ": Dwarf version " << DwarfVersion
521521
<< " is not supported." << '\n';
522522
return 1;

0 commit comments

Comments
 (0)
Please sign in to comment.