llvm.org GIT mirror llvm / c098708
DIEHash: Use DW_FORM_sdata for integers, per spec. This allows us to produce the same hash as GCC for at least some simple examples. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192855 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 7 years ago
4 changed file(s) with 47 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
6767 } while (Value != 0);
6868 }
6969
70 void DIEHash::addSLEB128(int64_t Value) {
71 DEBUG(dbgs() << "Adding ULEB128 " << Value << " to hash.\n");
72 bool More;
73 do {
74 uint8_t Byte = Value & 0x7f;
75 Value >>= 7;
76 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
77 ((Value == -1) && ((Byte & 0x40) != 0))));
78 if (More)
79 Byte |= 0x80; // Mark this byte to show that more bytes will follow.
80 Hash.update(Byte);
81 } while (More);
82 }
83
7084 /// \brief Including \p Parent adds the context of Parent to the hash..
7185 void DIEHash::addParentContext(DIE *Parent) {
7286
276290 // Add the letter A to the hash.
277291 addULEB128('A');
278292
279 // Then the attribute code and form.
293 // Then the attribute code.
280294 addULEB128(Desc->getAttribute());
281 addULEB128(Desc->getForm());
295
296 // To ensure reproducibility of the signature, the set of forms used in the
297 // signature computation is limited to the following: DW_FORM_sdata,
298 // DW_FORM_flag, DW_FORM_string, and DW_FORM_block.
282299
283300 // TODO: Add support for additional forms.
284301 switch (Desc->getForm()) {
285 // TODO: We'll want to add DW_FORM_string here if we start emitting them
286 // again.
302 case dwarf::DW_FORM_string:
303 llvm_unreachable(
304 "Add support for DW_FORM_string if we ever start emitting them again");
287305 case dwarf::DW_FORM_strp:
306 addULEB128(dwarf::DW_FORM_string);
288307 addString(cast(Value)->getString());
289308 break;
290309 case dwarf::DW_FORM_data1:
292311 case dwarf::DW_FORM_data4:
293312 case dwarf::DW_FORM_data8:
294313 case dwarf::DW_FORM_udata:
295 addULEB128(cast(Value)->getValue());
314 addULEB128(dwarf::DW_FORM_sdata);
315 addSLEB128((int64_t)cast(Value)->getValue());
296316 break;
297317 }
298318 }
105105 /// \brief Encodes and adds \param Value to the hash as a ULEB128.
106106 void addULEB128(uint64_t Value);
107107
108 /// \brief Encodes and adds \param Value to the hash as a SLEB128.
109 void addSLEB128(int64_t Value);
110
108111 /// \brief Adds \param Str to the hash and includes a NULL byte.
109112 void addString(StringRef Str);
110113
22
33 ; The source is an empty file.
44
5 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x2410f0bbc44241ed)
6 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x2410f0bbc44241ed)
5 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x63fc20b98dd69e2d)
6 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x63fc20b98dd69e2d)
77
88 !llvm.dbg.cu = !{!0}
99 !llvm.module.flags = !{!3}
2222 DIEInteger Size(4);
2323 Die.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Size);
2424 uint64_t MD5Res = Hash.computeTypeSignature(&Die);
25 ASSERT_EQ(0x4F68EF1039F8D2BULL, MD5Res);
25 ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
26 }
27
28 TEST(DIEHashTrivialTypeTest, DIEHash) {
29 // A complete, but simple, type containing no members and defined on the first
30 // line of a file.
31 DIE FooType(dwarf::DW_TAG_structure_type);
32 DIEInteger One(1);
33 FooType.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
34
35 // Line and file number are ignored.
36 FooType.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
37 FooType.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
38 uint64_t MD5Res = DIEHash().computeTypeSignature(&FooType);
39
40 // The exact same hash GCC produces for this DIE.
41 ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
2642 }
2743 }