llvm.org GIT mirror llvm / 47f66d5
DIEHash: Support for simple (non-recursive, non-reused) type references git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192924 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 7 years ago
3 changed file(s) with 62 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
273273 case dwarf::DW_AT_vtable_elem_location:
274274 COLLECT_ATTR(DW_AT_vtable_elem_location)
275275 break;
276 case dwarf::DW_AT_type:
277 COLLECT_ATTR(DW_AT_type)
278 break;
276279 default:
277280 break;
278281 }
285288 const DIEValue *Value = Attr.Val;
286289 const DIEAbbrevData *Desc = Attr.Desc;
287290
288 // TODO: Add support for types.
289
290 // Add the letter A to the hash.
291 // 7.27s3
292 // ... An attribute that refers to another type entry T is processed as
293 // follows:
294 // a) If T is in the list of [previously hashed types], use the letter 'R' as
295 // the marker and use the unsigned LEB128 encoding of [the index of T in the
296 // list] as the attribute value; otherwise,
297
298 // [TODO: implement clause (a)]
299
300 if (const DIEEntry *EntryAttr = dyn_cast(Value)) {
301 DIE *Entry = EntryAttr->getEntry();
302
303 // b) use the letter 'T' as a the marker, ...
304 addULEB128('T');
305
306 addULEB128(Desc->getAttribute());
307
308 // ... process the type T recursively by performing Steps 2 through 7, and
309 // use the result as the attribute value.
310 computeHash(Entry);
311 return;
312 }
313
314 // Other attribute values use the letter 'A' as the marker, ...
291315 addULEB128('A');
292316
293 // Then the attribute code.
294317 addULEB128(Desc->getAttribute());
295318
296 // To ensure reproducibility of the signature, the set of forms used in the
319 // ... and the value consists of the form code (encoded as an unsigned LEB128
320 // value) followed by the encoding of the value according to the form code. To
321 // ensure reproducibility of the signature, the set of forms used in the
297322 // signature computation is limited to the following: DW_FORM_sdata,
298323 // DW_FORM_flag, DW_FORM_string, and DW_FORM_block.
299
300 // TODO: Add support for additional forms.
301324 switch (Desc->getForm()) {
302325 case dwarf::DW_FORM_string:
303326 llvm_unreachable(
314337 addULEB128(dwarf::DW_FORM_sdata);
315338 addSLEB128((int64_t)cast(Value)->getValue());
316339 break;
340 // TODO: Add support for additional forms.
317341 }
318342 }
319343
374398 ADD_ATTR(Attrs.DW_AT_virtuality);
375399 ADD_ATTR(Attrs.DW_AT_visibility);
376400 ADD_ATTR(Attrs.DW_AT_vtable_elem_location);
401 ADD_ATTR(Attrs.DW_AT_type);
377402
378403 // FIXME: Add the extended attributes.
379404 }
7575 AttrEntry DW_AT_virtuality;
7676 AttrEntry DW_AT_visibility;
7777 AttrEntry DW_AT_vtable_elem_location;
78 AttrEntry DW_AT_type;
7879
7980 // Insert any additional ones here...
8081 };
5050 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
5151 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
5252
53 // Line and file number are ignored.
54 Foo.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
55 Foo.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
5653 uint64_t MD5Res = DIEHash().computeTypeSignature(&Foo);
5754
5855 // The exact same hash GCC produces for this DIE.
7774 Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
7875 Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
7976
80 // Line and file number are ignored.
81 Foo->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
82 Foo->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
83
8477 Space->addChild(Foo);
8578 CU.addChild(Space);
8679
8982 // The exact same hash GCC produces for this DIE.
9083 ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
9184 }
85
86 TEST(TypeWithMember, DIEHash) {
87 DIE Unnamed(dwarf::DW_TAG_structure_type);
88 DIEInteger Four(4);
89 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
90
91 DIE *Member = new DIE(dwarf::DW_TAG_member);
92 DIEString MemberStr(&Four, "member");
93 Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemberStr);
94 // type
95 DIEInteger Zero(0);
96 Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
97
98 Unnamed.addChild(Member);
99
100 DIE Int(dwarf::DW_TAG_base_type);
101 DIEString IntStr(&Four, "int");
102 Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr);
103 Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
104 DIEInteger Five(5);
105 Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five);
106
107 DIEEntry IntRef(&Int);
108 Member->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef);
109
110 uint64_t MD5Res = DIEHash().computeTypeSignature(&Unnamed);
111
112 ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res);
92113 }
114 }