llvm.org GIT mirror llvm / d40539f
[DWARF] Added verification check for tags in accelerator tables. This patch verifies that the atom tag is actually the same with the tag of the DIE that we retrieve from the table. Differential Revision: https://reviews.llvm.org/D35963 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309596 91177308-0d34-0410-b5e6-96231b3b80d8 Spyridoula Gravani 2 years ago
5 changed file(s) with 159 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
6060 /// performing a lookup by name.
6161 ///
6262 /// \param HashDataOffset an offset into the hash data table
63 /// \returns DIEOffset the offset into the .debug_info section for the DIE
64 /// related to the input hash data offset. Currently this function returns
65 /// only the DIEOffset but it can be modified to return more data regarding
66 /// the DIE
67 uint32_t readAtoms(uint32_t &HashDataOffset);
63 /// \returns
64 /// DieOffset is the offset into the .debug_info section for the DIE
65 /// related to the input hash data offset.
66 /// DieTag is the tag of the DIE
67 std::pair readAtoms(uint32_t &HashDataOffset);
6868 void dump(raw_ostream &OS) const;
6969 };
7070
140140 /// - The size of the section is as large as what the header describes
141141 /// - There is at least one atom
142142 /// - The form for each atom is valid
143 /// - The tag for each DIE in the table is valid
143144 /// - The buckets have a valid index, or they are empty
144145 /// - Each hashdata offset is valid
145146 /// - Each DIE is valid
146 ///
147 ///
147148 /// \param AccelSection pointer to the section containing the acceleration table
148149 /// \param StrData pointer to the string section
149150 /// \param SectionName the name of the table we're verifying
7272 DWARFFormValue FormValue(Atom.second);
7373 switch (Atom.first) {
7474 case dwarf::DW_ATOM_die_offset:
75 case dwarf::DW_ATOM_die_tag:
76 case dwarf::DW_ATOM_type_flags:
7577 if ((!FormValue.isFormClass(DWARFFormValue::FC_Constant) &&
7678 !FormValue.isFormClass(DWARFFormValue::FC_Flag)) ||
7779 FormValue.getForm() == dwarf::DW_FORM_sdata)
8385 return true;
8486 }
8587
86 uint32_t DWARFAcceleratorTable::readAtoms(uint32_t &HashDataOffset) {
88 std::pair
89 DWARFAcceleratorTable::readAtoms(uint32_t &HashDataOffset) {
8790 uint32_t DieOffset = dwarf::DW_INVALID_OFFSET;
91 dwarf::Tag DieTag = dwarf::DW_TAG_null;
8892
8993 for (auto Atom : getAtomsDesc()) {
9094 DWARFFormValue FormValue(Atom.second);
9397 case dwarf::DW_ATOM_die_offset:
9498 DieOffset = *FormValue.getAsUnsignedConstant();
9599 break;
100 case dwarf::DW_ATOM_die_tag:
101 DieTag = (dwarf::Tag)*FormValue.getAsUnsignedConstant();
102 break;
96103 default:
97104 break;
98105 }
99106 }
100 return DieOffset;
107 return {DieOffset, DieTag};
101108 }
102109
103110 LLVM_DUMP_METHOD void DWARFAcceleratorTable::dump(raw_ostream &OS) const {
524524 uint32_t StrpOffset;
525525 uint32_t StringOffset;
526526 uint32_t StringCount = 0;
527 uint32_t DieOffset = dwarf::DW_INVALID_OFFSET;
528
527 unsigned Offset;
528 unsigned Tag;
529529 while ((StrpOffset = AccelSectionData.getU32(&HashDataOffset)) != 0) {
530530 const uint32_t NumHashDataObjects =
531531 AccelSectionData.getU32(&HashDataOffset);
532532 for (uint32_t HashDataIdx = 0; HashDataIdx < NumHashDataObjects;
533533 ++HashDataIdx) {
534 DieOffset = AccelTable.readAtoms(HashDataOffset);
535 if (!DCtx.getDIEForOffset(DieOffset)) {
534 std::tie(Offset, Tag) = AccelTable.readAtoms(HashDataOffset);
535 auto Die = DCtx.getDIEForOffset(Offset);
536 if (!Die) {
536537 const uint32_t BucketIdx =
537538 NumBuckets ? (Hash % NumBuckets) : UINT32_MAX;
538539 StringOffset = StrpOffset;
545546 "Str[%u] = 0x%08x "
546547 "DIE[%d] = 0x%08x is not a valid DIE offset for \"%s\".\n",
547548 SectionName, BucketIdx, HashIdx, Hash, StringCount, StrpOffset,
548 HashDataIdx, DieOffset, Name);
549
549 HashDataIdx, Offset, Name);
550
551 ++NumErrors;
552 continue;
553 }
554 if ((Tag != dwarf::DW_TAG_null) && (Die.getTag() != Tag)) {
555 OS << "\terror: Tag " << dwarf::TagString(Tag)
556 << " in accelerator table does not match Tag "
557 << dwarf::TagString(Die.getTag()) << " of DIE[" << HashDataIdx
558 << "].\n";
550559 ++NumErrors;
551560 }
552561 }
0 # RUN: llvm-mc %s -filetype obj -triple x86_64-apple-darwin -o - \
1 # RUN: | not llvm-dwarfdump -verify - \
2 # RUN: | FileCheck %s
3
4 # CHECK: Verifying .apple_types...
5 # CHECK-NEXT: error: Tag DW_TAG_ptr_to_member_type in accelerator table does not match Tag DW_TAG_base_type of DIE[0].
6
7 # This test is meant to verify that the -verify option
8 # in llvm-dwarfdump, correctly identifies an invalid DIE tag in .apple_types.
9
10 .section __TEXT,__text,regular,pure_instructions
11 .macosx_version_min 10, 12
12 .file 1 "basic.c"
13 .comm _i,4,2 ## @i
14 .section __DWARF,__debug_str,regular,debug
15 Linfo_string:
16 .asciz "clang version 6.0.0 (trunk 309427) (llvm/trunk 309432)" ## string offset=0
17 .asciz "basic.c" ## string offset=55
18 .asciz "/Users/sgravani/Development/tests" ## string offset=63
19 .asciz "i" ## string offset=97
20 .asciz "int" ## string offset=99
21 .section __DWARF,__debug_abbrev,regular,debug
22 Lsection_abbrev:
23 .byte 1 ## Abbreviation Code
24 .byte 17 ## DW_TAG_compile_unit
25 .byte 1 ## DW_CHILDREN_yes
26 .byte 37 ## DW_AT_producer
27 .byte 14 ## DW_FORM_strp
28 .byte 19 ## DW_AT_language
29 .byte 5 ## DW_FORM_data2
30 .byte 3 ## DW_AT_name
31 .byte 14 ## DW_FORM_strp
32 .byte 16 ## DW_AT_stmt_list
33 .byte 23 ## DW_FORM_sec_offset
34 .byte 27 ## DW_AT_comp_dir
35 .byte 14 ## DW_FORM_strp
36 .byte 0 ## EOM(1)
37 .byte 0 ## EOM(2)
38 .byte 2 ## Abbreviation Code
39 .byte 52 ## DW_TAG_variable
40 .byte 0 ## DW_CHILDREN_no
41 .byte 3 ## DW_AT_name
42 .byte 14 ## DW_FORM_strp
43 .byte 73 ## DW_AT_type
44 .byte 19 ## DW_FORM_ref4
45 .byte 63 ## DW_AT_external
46 .byte 25 ## DW_FORM_flag_present
47 .byte 58 ## DW_AT_decl_file
48 .byte 11 ## DW_FORM_data1
49 .byte 59 ## DW_AT_decl_line
50 .byte 11 ## DW_FORM_data1
51 .byte 2 ## DW_AT_location
52 .byte 24 ## DW_FORM_exprloc
53 .byte 0 ## EOM(1)
54 .byte 0 ## EOM(2)
55 .byte 3 ## Abbreviation Code
56 .byte 36 ## DW_TAG_base_type
57 .byte 0 ## DW_CHILDREN_no
58 .byte 3 ## DW_AT_name
59 .byte 14 ## DW_FORM_strp
60 .byte 62 ## DW_AT_encoding
61 .byte 11 ## DW_FORM_data1
62 .byte 11 ## DW_AT_byte_size
63 .byte 11 ## DW_FORM_data1
64 .byte 0 ## EOM(1)
65 .byte 0 ## EOM(2)
66 .byte 0 ## EOM(3)
67 .section __DWARF,__debug_info,regular,debug
68 Lsection_info:
69 Lcu_begin0:
70 .long 56 ## Length of Unit
71 .short 5 ## DWARF version number
72 .byte 1 ## DWARF Unit Type
73 .byte 8 ## Address Size (in bytes)
74 Lset0 = Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
75 .long Lset0
76 .byte 1 ## Abbrev [1] 0xc:0x30 DW_TAG_compile_unit
77 .long 0 ## DW_AT_producer
78 .short 12 ## DW_AT_language
79 .long 55 ## DW_AT_name
80 Lset1 = Lline_table_start0-Lsection_line ## DW_AT_stmt_list
81 .long Lset1
82 .long 63 ## DW_AT_comp_dir
83 .byte 2 ## Abbrev [2] 0x1f:0x15 DW_TAG_variable
84 .long 97 ## DW_AT_name
85 .long 52 ## DW_AT_type
86 ## DW_AT_external
87 .byte 1 ## DW_AT_decl_file
88 .byte 1 ## DW_AT_decl_line
89 .byte 9 ## DW_AT_location
90 .byte 3
91 .quad _i
92 .byte 3 ## Abbrev [3] 0x34:0x7 DW_TAG_base_type
93 .long 99 ## DW_AT_name
94 .byte 5 ## DW_AT_encoding
95 .byte 4 ## DW_AT_byte_size
96 .byte 0 ## End Of Children Mark
97 .section __DWARF,__apple_types,regular,debug
98 Ltypes_begin:
99 .long 1212240712 ## Header Magic
100 .short 1 ## Header Version
101 .short 0 ## Header Hash Function
102 .long 1 ## Header Bucket Count
103 .long 1 ## Header Hash Count
104 .long 20 ## Header Data Length
105 .long 0 ## HeaderData Die Offset Base
106 .long 3 ## HeaderData Atom Count
107 .short 1 ## DW_ATOM_die_offset
108 .short 6 ## DW_FORM_data4
109 .short 3 ## DW_ATOM_die_tag
110 .short 5 ## DW_FORM_data2
111 .short 4 ## DW_ATOM_type_flags
112 .short 11 ## DW_FORM_data1
113 .long 0 ## Bucket 0
114 .long 193495088 ## Hash in Bucket 0
115 .long Ltypes0-Ltypes_begin ## Offset in Bucket 0
116 Ltypes0:
117 .long 99 ## int
118 .long 1 ## Num DIEs
119 .long 52
120 .short 31 ## error: Tag DW_TAG_ptr_to_member_type in accelerator table does not match Tag DW_TAG_base_type of DIE[0].
121 .byte 0
122 .long 0
123
124 .subsections_via_symbols
125 .section __DWARF,__debug_line,regular,debug
126 Lsection_line:
127 Lline_table_start0: