Skip to content

Commit 15fa446

Browse files
committedMay 9, 2017
[DWARF] Fix a parsing issue with type unit headers.
Reviewers: dblaikie Differential Revision: https://reviews.llvm.org/D32987 llvm-svn: 302574
1 parent 674deed commit 15fa446

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed
 

‎llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ bool DWARFTypeUnit::extractImpl(DataExtractor debug_info,
2424
return false;
2525
TypeHash = debug_info.getU64(offset_ptr);
2626
TypeOffset = debug_info.getU32(offset_ptr);
27-
return TypeOffset < getLength();
27+
// TypeOffset is relative to the beginning of the header,
28+
// so we have to account for the leading length field.
29+
// FIXME: The size of the length field is 12 in DWARF64.
30+
unsigned SizeOfLength = 4;
31+
return TypeOffset < getLength() + SizeOfLength;
2832
}
2933

3034
void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) {
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Test object with an artifically constructed type unit header to verify
2+
# that the length field is correctly used to verify the validity of the
3+
# type_offset field.
4+
#
5+
# To generate the test object:
6+
# llvm-mc -triple x86_64-unknown-linux typeunit-header.s -filetype=obj \
7+
# -o typeunit-header.elf-x86-64
8+
#
9+
# We only have an abbreviation for the type unit die which is all we need.
10+
# Real type unit dies have quite different attributes of course, but we
11+
# just need to demonstrate an issue with validating length, so we just give it
12+
# a single visibility attribute.
13+
.section .debug_abbrev,"",@progbits
14+
.byte 0x01 # Abbrev code
15+
.byte 0x41 # DW_TAG_type_unit
16+
.byte 0x01 # DW_CHILDREN_yes
17+
.byte 0x17 # DW_AT_visibility
18+
.byte 0x0b # DW_FORM_data1
19+
.byte 0x00 # EOM(1)
20+
.byte 0x00 # EOM(2)
21+
.byte 0x02 # Abbrev code
22+
.byte 0x13 # DW_TAG_structure_type
23+
.byte 0x00 # DW_CHILDREN_no (no members)
24+
.byte 0x17 # DW_AT_visibility
25+
.byte 0x0b # DW_FORM_data1
26+
.byte 0x00 # EOM(1)
27+
.byte 0x00 # EOM(2)
28+
.byte 0x00 # EOM(3)
29+
30+
.section .debug_types,"",@progbits
31+
# DWARF v4 Type unit header - DWARF32 format.
32+
TU_4_32_start:
33+
.long TU_4_32_end-TU_4_32_version # Length of Unit
34+
TU_4_32_version:
35+
.short 4 # DWARF version number
36+
.long .debug_abbrev # Offset Into Abbrev. Section
37+
.byte 8 # Address Size (in bytes)
38+
.quad 0x0011223344556677 # Type Signature
39+
.long TU_4_32_type-TU_4_32_start # Type offset
40+
# The type-unit DIE, which has just a visibility attribute.
41+
.byte 1 # Abbreviation code
42+
.byte 1 # DW_VIS_local
43+
# The type DIE, which also just has a one-byte visibility attribute.
44+
TU_4_32_type:
45+
.byte 2 # Abbreviation code
46+
.byte 1 # DW_VIS_local
47+
.byte 0 # NULL
48+
.byte 0 # NULL
49+
TU_4_32_end:
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
RUN: llvm-dwarfdump %p/Inputs/typeunit-header.elf-x86-64 | FileCheck %s
2+
3+
This is testing a bugfix where parsing the type unit header was not
4+
taking the unit's intial length field into account when validating.
5+
6+
The input file is hand-coded assembler to generate a type unit stub,
7+
which only contains a type unit DIE with a sole visibility attribute.
8+
9+
We make sure that llvm-dwarfdump is parsing the type unit header correctly
10+
and displays it.
11+
12+
CHECK: .debug_types contents:
13+
CHECK: 0x00000000: Type Unit: length = 0x00000019 version = 0x0004 abbr_offset = 0x0000 addr_size = 0x08 name = '' type_signature = 0x0011223344556677 type_offset = 0x0019 (next unit at 0x0000001d)
14+
CHECK: 0x00000017: DW_TAG_type_unit [1] *
15+
CHECK: DW_AT_visibility [DW_FORM_data1] (DW_VIS_local)

0 commit comments

Comments
 (0)
Please sign in to comment.