blob: 15ade3c96dfea2ae1e5927901231f394c1717659 [file] [log] [blame]
Eric Christopher45731982013-08-08 23:45:55 +00001//===-- llvm/CodeGen/DIEHash.cpp - Dwarf Hashing Framework ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains support for DWARF4 hashing of DIEs.
11//
12//===----------------------------------------------------------------------===//
13
Eric Christopher45731982013-08-08 23:45:55 +000014#include "DIEHash.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000015#include "ByteStreamer.h"
Eric Christopher4f17ee02014-03-08 00:29:41 +000016#include "DwarfDebug.h"
Eric Christopher45731982013-08-08 23:45:55 +000017#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/StringRef.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000019#include "llvm/BinaryFormat/Dwarf.h"
Eric Christopher420569b2014-02-20 02:50:45 +000020#include "llvm/CodeGen/AsmPrinter.h"
Frederic Risse541e0b2015-01-05 21:29:41 +000021#include "llvm/CodeGen/DIE.h"
Eric Christopher45731982013-08-08 23:45:55 +000022#include "llvm/Support/Debug.h"
Eric Christopher45731982013-08-08 23:45:55 +000023#include "llvm/Support/Endian.h"
24#include "llvm/Support/MD5.h"
25#include "llvm/Support/raw_ostream.h"
26
27using namespace llvm;
28
Chandler Carruth1b9dde02014-04-22 02:02:50 +000029#define DEBUG_TYPE "dwarfdebug"
30
Eric Christopher45731982013-08-08 23:45:55 +000031/// \brief Grabs the string in whichever attribute is passed in and returns
32/// a reference to it.
David Blaikieafcb9652013-10-24 17:51:43 +000033static StringRef getDIEStringAttr(const DIE &Die, uint16_t Attr) {
Eric Christopher45731982013-08-08 23:45:55 +000034 // Iterate through all the attributes until we find the one we're
35 // looking for, if we can't find it return an empty string.
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +000036 for (const auto &V : Die.values())
37 if (V.getAttribute() == Attr)
38 return V.getDIEString().getString();
39
Eric Christopher45731982013-08-08 23:45:55 +000040 return StringRef("");
41}
42
43/// \brief Adds the string in \p Str to the hash. This also hashes
44/// a trailing NULL with the string.
45void DIEHash::addString(StringRef Str) {
46 DEBUG(dbgs() << "Adding string " << Str << " to hash.\n");
47 Hash.update(Str);
48 Hash.update(makeArrayRef((uint8_t)'\0'));
49}
50
51// FIXME: The LEB128 routines are copied and only slightly modified out of
52// LEB128.h.
53
54/// \brief Adds the unsigned in \p Value to the hash encoded as a ULEB128.
55void DIEHash::addULEB128(uint64_t Value) {
56 DEBUG(dbgs() << "Adding ULEB128 " << Value << " to hash.\n");
57 do {
58 uint8_t Byte = Value & 0x7f;
59 Value >>= 7;
60 if (Value != 0)
61 Byte |= 0x80; // Mark this byte to show that more bytes will follow.
62 Hash.update(Byte);
63 } while (Value != 0);
64}
65
David Blaikie6316ca42013-10-16 23:36:20 +000066void DIEHash::addSLEB128(int64_t Value) {
67 DEBUG(dbgs() << "Adding ULEB128 " << Value << " to hash.\n");
68 bool More;
69 do {
70 uint8_t Byte = Value & 0x7f;
71 Value >>= 7;
Eric Christophera1b87fd2014-02-20 02:40:41 +000072 More = !((((Value == 0) && ((Byte & 0x40) == 0)) ||
David Blaikie6316ca42013-10-16 23:36:20 +000073 ((Value == -1) && ((Byte & 0x40) != 0))));
74 if (More)
75 Byte |= 0x80; // Mark this byte to show that more bytes will follow.
76 Hash.update(Byte);
77 } while (More);
78}
79
Eric Christopher45731982013-08-08 23:45:55 +000080/// \brief Including \p Parent adds the context of Parent to the hash..
David Blaikie2aee7be2013-10-24 18:29:03 +000081void DIEHash::addParentContext(const DIE &Parent) {
Eric Christopher45731982013-08-08 23:45:55 +000082
83 DEBUG(dbgs() << "Adding parent context to hash...\n");
84
85 // [7.27.2] For each surrounding type or namespace beginning with the
86 // outermost such construct...
David Blaikie2aee7be2013-10-24 18:29:03 +000087 SmallVector<const DIE *, 1> Parents;
88 const DIE *Cur = &Parent;
David Blaikie409dd9c2013-11-19 23:08:21 +000089 while (Cur->getParent()) {
David Blaikie2aee7be2013-10-24 18:29:03 +000090 Parents.push_back(Cur);
91 Cur = Cur->getParent();
Eric Christopher45731982013-08-08 23:45:55 +000092 }
David Blaikie409dd9c2013-11-19 23:08:21 +000093 assert(Cur->getTag() == dwarf::DW_TAG_compile_unit ||
94 Cur->getTag() == dwarf::DW_TAG_type_unit);
Eric Christopher45731982013-08-08 23:45:55 +000095
96 // Reverse iterate over our list to go from the outermost construct to the
97 // innermost.
David Blaikie2aee7be2013-10-24 18:29:03 +000098 for (SmallVectorImpl<const DIE *>::reverse_iterator I = Parents.rbegin(),
99 E = Parents.rend();
Eric Christopher45731982013-08-08 23:45:55 +0000100 I != E; ++I) {
David Blaikie2aee7be2013-10-24 18:29:03 +0000101 const DIE &Die = **I;
Eric Christopher45731982013-08-08 23:45:55 +0000102
103 // ... Append the letter "C" to the sequence...
104 addULEB128('C');
105
106 // ... Followed by the DWARF tag of the construct...
David Blaikie2aee7be2013-10-24 18:29:03 +0000107 addULEB128(Die.getTag());
Eric Christopher45731982013-08-08 23:45:55 +0000108
109 // ... Then the name, taken from the DW_AT_name attribute.
David Blaikie2aee7be2013-10-24 18:29:03 +0000110 StringRef Name = getDIEStringAttr(Die, dwarf::DW_AT_name);
Eric Christopher45731982013-08-08 23:45:55 +0000111 DEBUG(dbgs() << "... adding context: " << Name << "\n");
112 if (!Name.empty())
113 addString(Name);
114 }
115}
116
Eric Christopherd29614f2013-08-13 01:21:55 +0000117// Collect all of the attributes for a particular DIE in single structure.
David Blaikie2aee7be2013-10-24 18:29:03 +0000118void DIEHash::collectAttributes(const DIE &Die, DIEAttrs &Attrs) {
Eric Christopherd29614f2013-08-13 01:21:55 +0000119
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000120 for (const auto &V : Die.values()) {
Eric Christopherd29614f2013-08-13 01:21:55 +0000121 DEBUG(dbgs() << "Attribute: "
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000122 << dwarf::AttributeString(V.getAttribute())
Eric Christopherd29614f2013-08-13 01:21:55 +0000123 << " added.\n");
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000124 switch (V.getAttribute()) {
David Blaikie74fa8032017-05-23 18:27:09 +0000125#define HANDLE_DIE_HASH_ATTR(NAME) \
126 case dwarf::NAME: \
127 Attrs.NAME = V; \
128 break;
129#include "DIEHashAttributes.def"
Eric Christopherd29614f2013-08-13 01:21:55 +0000130 default:
131 break;
132 }
133 }
134}
135
David Blaikieafcb9652013-10-24 17:51:43 +0000136void DIEHash::hashShallowTypeReference(dwarf::Attribute Attribute,
137 const DIE &Entry, StringRef Name) {
138 // append the letter 'N'
139 addULEB128('N');
140
141 // the DWARF attribute code (DW_AT_type or DW_AT_friend),
142 addULEB128(Attribute);
143
144 // the context of the tag,
David Blaikie2aee7be2013-10-24 18:29:03 +0000145 if (const DIE *Parent = Entry.getParent())
146 addParentContext(*Parent);
David Blaikieafcb9652013-10-24 17:51:43 +0000147
148 // the letter 'E',
149 addULEB128('E');
150
151 // and the name of the type.
152 addString(Name);
153
154 // Currently DW_TAG_friends are not used by Clang, but if they do become so,
155 // here's the relevant spec text to implement:
156 //
157 // For DW_TAG_friend, if the referenced entry is the DW_TAG_subprogram,
158 // the context is omitted and the name to be used is the ABI-specific name
159 // of the subprogram (e.g., the mangled linker name).
160}
161
162void DIEHash::hashRepeatedTypeReference(dwarf::Attribute Attribute,
163 unsigned DieNumber) {
164 // a) If T is in the list of [previously hashed types], use the letter
165 // 'R' as the marker
166 addULEB128('R');
167
168 addULEB128(Attribute);
169
170 // and use the unsigned LEB128 encoding of [the index of T in the
171 // list] as the attribute value;
172 addULEB128(DieNumber);
173}
174
175void DIEHash::hashDIEEntry(dwarf::Attribute Attribute, dwarf::Tag Tag,
David Blaikie2aee7be2013-10-24 18:29:03 +0000176 const DIE &Entry) {
David Blaikieafcb9652013-10-24 17:51:43 +0000177 assert(Tag != dwarf::DW_TAG_friend && "No current LLVM clients emit friend "
178 "tags. Add support here when there's "
179 "a use case");
180 // Step 5
181 // If the tag in Step 3 is one of [the below tags]
182 if ((Tag == dwarf::DW_TAG_pointer_type ||
183 Tag == dwarf::DW_TAG_reference_type ||
184 Tag == dwarf::DW_TAG_rvalue_reference_type ||
185 Tag == dwarf::DW_TAG_ptr_to_member_type) &&
186 // and the referenced type (via the [below attributes])
187 // FIXME: This seems overly restrictive, and causes hash mismatches
188 // there's a decl/def difference in the containing type of a
189 // ptr_to_member_type, but it's what DWARF says, for some reason.
190 Attribute == dwarf::DW_AT_type) {
David Blaikie32744412013-10-24 17:53:58 +0000191 // ... has a DW_AT_name attribute,
192 StringRef Name = getDIEStringAttr(Entry, dwarf::DW_AT_name);
193 if (!Name.empty()) {
194 hashShallowTypeReference(Attribute, Entry, Name);
195 return;
196 }
David Blaikieafcb9652013-10-24 17:51:43 +0000197 }
198
199 unsigned &DieNumber = Numbering[&Entry];
200 if (DieNumber) {
201 hashRepeatedTypeReference(Attribute, DieNumber);
202 return;
203 }
204
Robin Morisset039781e2014-08-29 21:53:01 +0000205 // otherwise, b) use the letter 'T' as the marker, ...
David Blaikieafcb9652013-10-24 17:51:43 +0000206 addULEB128('T');
207
208 addULEB128(Attribute);
209
210 // ... process the type T recursively by performing Steps 2 through 7, and
211 // use the result as the attribute value.
212 DieNumber = Numbering.size();
David Blaikie2aee7be2013-10-24 18:29:03 +0000213 computeHash(Entry);
David Blaikieafcb9652013-10-24 17:51:43 +0000214}
215
Eric Christopher420569b2014-02-20 02:50:45 +0000216// Hash all of the values in a block like set of values. This assumes that
217// all of the data is going to be added as integers.
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000218void DIEHash::hashBlockData(const DIE::const_value_range &Values) {
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000219 for (const auto &V : Values)
220 Hash.update((uint64_t)V.getDIEInteger().getValue());
Eric Christopher420569b2014-02-20 02:50:45 +0000221}
222
Eric Christopher4f17ee02014-03-08 00:29:41 +0000223// Hash the contents of a loclistptr class.
224void DIEHash::hashLocList(const DIELocList &LocList) {
Eric Christopher4f17ee02014-03-08 00:29:41 +0000225 HashingByteStreamer Streamer(*this);
David Blaikie0a456de2014-04-02 01:43:18 +0000226 DwarfDebug &DD = *AP->getDwarfDebug();
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000227 const DebugLocStream &Locs = DD.getDebugLocs();
228 for (const auto &Entry : Locs.getEntries(Locs.getList(LocList.getValue())))
David Blaikie0a456de2014-04-02 01:43:18 +0000229 DD.emitDebugLocEntry(Streamer, Entry);
Eric Christopher4f17ee02014-03-08 00:29:41 +0000230}
231
Eric Christopherd29614f2013-08-13 01:21:55 +0000232// Hash an individual attribute \param Attr based on the type of attribute and
233// the form.
Benjamin Kramer1afc1de2016-06-17 20:41:14 +0000234void DIEHash::hashAttribute(const DIEValue &Value, dwarf::Tag Tag) {
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000235 dwarf::Attribute Attribute = Value.getAttribute();
Eric Christopherd29614f2013-08-13 01:21:55 +0000236
Eric Christopher4b1cf582014-01-31 20:02:58 +0000237 // Other attribute values use the letter 'A' as the marker, and the value
238 // consists of the form code (encoded as an unsigned LEB128 value) followed by
239 // the encoding of the value according to the form code. To ensure
240 // reproducibility of the signature, the set of forms used in the signature
241 // computation is limited to the following: DW_FORM_sdata, DW_FORM_flag,
242 // DW_FORM_string, and DW_FORM_block.
Eric Christopher19308492014-03-06 00:38:32 +0000243
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000244 switch (Value.getType()) {
245 case DIEValue::isNone:
246 llvm_unreachable("Expected valid DIEValue");
247
Eric Christopher2bed2572014-03-06 18:59:42 +0000248 // 7.27 Step 3
249 // ... An attribute that refers to another type entry T is processed as
250 // follows:
251 case DIEValue::isEntry:
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000252 hashDIEEntry(Attribute, Tag, Value.getDIEEntry().getEntry());
Eric Christopher2bed2572014-03-06 18:59:42 +0000253 break;
Eric Christopher19308492014-03-06 00:38:32 +0000254 case DIEValue::isInteger: {
255 addULEB128('A');
256 addULEB128(Attribute);
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000257 switch (Value.getForm()) {
Eric Christopher19308492014-03-06 00:38:32 +0000258 case dwarf::DW_FORM_data1:
259 case dwarf::DW_FORM_data2:
260 case dwarf::DW_FORM_data4:
261 case dwarf::DW_FORM_data8:
262 case dwarf::DW_FORM_udata:
263 case dwarf::DW_FORM_sdata:
264 addULEB128(dwarf::DW_FORM_sdata);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000265 addSLEB128((int64_t)Value.getDIEInteger().getValue());
Eric Christopher19308492014-03-06 00:38:32 +0000266 break;
267 // DW_FORM_flag_present is just flag with a value of one. We still give it a
268 // value so just use the value.
269 case dwarf::DW_FORM_flag_present:
270 case dwarf::DW_FORM_flag:
271 addULEB128(dwarf::DW_FORM_flag);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000272 addULEB128((int64_t)Value.getDIEInteger().getValue());
Eric Christopher19308492014-03-06 00:38:32 +0000273 break;
274 default:
275 llvm_unreachable("Unknown integer form!");
276 }
277 break;
278 }
279 case DIEValue::isString:
Eric Christopher4b1cf582014-01-31 20:02:58 +0000280 addULEB128('A');
281 addULEB128(Attribute);
David Blaikie6316ca42013-10-16 23:36:20 +0000282 addULEB128(dwarf::DW_FORM_string);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000283 addString(Value.getDIEString().getString());
Eric Christopherd29614f2013-08-13 01:21:55 +0000284 break;
Greg Clayton3462a422016-12-08 01:03:48 +0000285 case DIEValue::isInlineString:
286 addULEB128('A');
287 addULEB128(Attribute);
288 addULEB128(dwarf::DW_FORM_string);
289 addString(Value.getDIEInlineString().getString());
290 break;
Eric Christopher19308492014-03-06 00:38:32 +0000291 case DIEValue::isBlock:
292 case DIEValue::isLoc:
Eric Christopher4f17ee02014-03-08 00:29:41 +0000293 case DIEValue::isLocList:
Eric Christopher420569b2014-02-20 02:50:45 +0000294 addULEB128('A');
295 addULEB128(Attribute);
296 addULEB128(dwarf::DW_FORM_block);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000297 if (Value.getType() == DIEValue::isBlock) {
298 addULEB128(Value.getDIEBlock().ComputeSize(AP));
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000299 hashBlockData(Value.getDIEBlock().values());
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000300 } else if (Value.getType() == DIEValue::isLoc) {
301 addULEB128(Value.getDIELoc().ComputeSize(AP));
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000302 hashBlockData(Value.getDIELoc().values());
Eric Christopher4f17ee02014-03-08 00:29:41 +0000303 } else {
304 // We could add the block length, but that would take
305 // a bit of work and not add a lot of uniqueness
306 // to the hash in some way we could test.
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000307 hashLocList(Value.getDIELocList());
Eric Christopher420569b2014-02-20 02:50:45 +0000308 }
309 break;
Eric Christopher6bb07f62014-03-06 01:32:56 +0000310 // FIXME: It's uncertain whether or not we should handle this at the moment.
Eric Christopher19308492014-03-06 00:38:32 +0000311 case DIEValue::isExpr:
312 case DIEValue::isLabel:
313 case DIEValue::isDelta:
Eric Christopher19308492014-03-06 00:38:32 +0000314 llvm_unreachable("Add support for additional value types.");
Eric Christopherd29614f2013-08-13 01:21:55 +0000315 }
316}
317
318// Go through the attributes from \param Attrs in the order specified in 7.27.4
319// and hash them.
David Blaikie6cf58c82013-10-21 22:36:50 +0000320void DIEHash::hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag) {
David Blaikie74fa8032017-05-23 18:27:09 +0000321#define HANDLE_DIE_HASH_ATTR(NAME) \
Eric Christopherd29614f2013-08-13 01:21:55 +0000322 { \
David Blaikie74fa8032017-05-23 18:27:09 +0000323 if (Attrs.NAME) \
324 hashAttribute(Attrs.NAME, Tag); \
Eric Christopherd29614f2013-08-13 01:21:55 +0000325 }
David Blaikie74fa8032017-05-23 18:27:09 +0000326#include "DIEHashAttributes.def"
Eric Christophere020fa72013-09-03 20:00:20 +0000327 // FIXME: Add the extended attributes.
Eric Christopherd29614f2013-08-13 01:21:55 +0000328}
329
330// Add all of the attributes for \param Die to the hash.
David Blaikie2aee7be2013-10-24 18:29:03 +0000331void DIEHash::addAttributes(const DIE &Die) {
David Blaikie94ded5f2013-10-16 00:47:21 +0000332 DIEAttrs Attrs = {};
David Blaikied0d6fcc2013-08-14 22:23:05 +0000333 collectAttributes(Die, Attrs);
David Blaikie2aee7be2013-10-24 18:29:03 +0000334 hashAttributes(Attrs, Die.getTag());
Eric Christopherd29614f2013-08-13 01:21:55 +0000335}
336
David Blaikie65cc9692013-10-25 18:38:43 +0000337void DIEHash::hashNestedType(const DIE &Die, StringRef Name) {
338 // 7.27 Step 7
339 // ... append the letter 'S',
340 addULEB128('S');
341
342 // the tag of C,
343 addULEB128(Die.getTag());
344
345 // and the name.
346 addString(Name);
347}
348
Eric Christopherd29614f2013-08-13 01:21:55 +0000349// Compute the hash of a DIE. This is based on the type signature computation
350// given in section 7.27 of the DWARF4 standard. It is the md5 hash of a
351// flattened description of the DIE.
David Blaikie2aee7be2013-10-24 18:29:03 +0000352void DIEHash::computeHash(const DIE &Die) {
Eric Christopherd29614f2013-08-13 01:21:55 +0000353 // Append the letter 'D', followed by the DWARF tag of the DIE.
354 addULEB128('D');
David Blaikie2aee7be2013-10-24 18:29:03 +0000355 addULEB128(Die.getTag());
Eric Christopherd29614f2013-08-13 01:21:55 +0000356
357 // Add each of the attributes of the DIE.
358 addAttributes(Die);
359
360 // Then hash each of the children of the DIE.
Duncan P. N. Exon Smith8d3197f2015-05-28 19:56:34 +0000361 for (auto &C : Die.children()) {
David Blaikie65cc9692013-10-25 18:38:43 +0000362 // 7.27 Step 7
363 // If C is a nested type entry or a member function entry, ...
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000364 if (isType(C.getTag()) || C.getTag() == dwarf::DW_TAG_subprogram) {
365 StringRef Name = getDIEStringAttr(C, dwarf::DW_AT_name);
David Blaikie65cc9692013-10-25 18:38:43 +0000366 // ... and has a DW_AT_name attribute
367 if (!Name.empty()) {
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000368 hashNestedType(C, Name);
David Blaikie65cc9692013-10-25 18:38:43 +0000369 continue;
370 }
371 }
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000372 computeHash(C);
David Blaikie65cc9692013-10-25 18:38:43 +0000373 }
David Blaikie71a0ad62013-10-16 20:29:06 +0000374
375 // Following the last (or if there are no children), append a zero byte.
David Blaikie920bb2a2013-10-16 20:40:46 +0000376 Hash.update(makeArrayRef((uint8_t)'\0'));
Eric Christopherd29614f2013-08-13 01:21:55 +0000377}
378
Eric Christopher45731982013-08-08 23:45:55 +0000379/// This is based on the type signature computation given in section 7.27 of the
Eric Christopherd29614f2013-08-13 01:21:55 +0000380/// DWARF4 standard. It is an md5 hash of the flattened description of the DIE
381/// with the inclusion of the full CU and all top level CU entities.
Eric Christopher25b7adc2013-09-03 21:57:57 +0000382// TODO: Initialize the type chain at 0 instead of 1 for CU signatures.
Mehdi Amini96ab48f2017-05-29 06:32:34 +0000383uint64_t DIEHash::computeCUSignature(StringRef DWOName, const DIE &Die) {
David Blaikie980d4992013-10-21 18:59:40 +0000384 Numbering.clear();
David Blaikie2aee7be2013-10-24 18:29:03 +0000385 Numbering[&Die] = 1;
Eric Christopherd29614f2013-08-13 01:21:55 +0000386
Mehdi Amini96ab48f2017-05-29 06:32:34 +0000387 if (!DWOName.empty())
388 Hash.update(DWOName);
Eric Christopherd29614f2013-08-13 01:21:55 +0000389 // Hash the DIE.
390 computeHash(Die);
391
392 // Now return the result.
393 MD5::MD5Result Result;
394 Hash.final(Result);
395
396 // ... take the least significant 8 bytes and return those. Our MD5
Zachary Turner82a0c972017-03-20 23:33:18 +0000397 // implementation always returns its results in little endian, so we actually
398 // need the "high" word.
399 return Result.high();
Eric Christopherd29614f2013-08-13 01:21:55 +0000400}
Eric Christopher25b7adc2013-09-03 21:57:57 +0000401
402/// This is based on the type signature computation given in section 7.27 of the
403/// DWARF4 standard. It is an md5 hash of the flattened description of the DIE
404/// with the inclusion of additional forms not specifically called out in the
405/// standard.
David Blaikie2aee7be2013-10-24 18:29:03 +0000406uint64_t DIEHash::computeTypeSignature(const DIE &Die) {
David Blaikie980d4992013-10-21 18:59:40 +0000407 Numbering.clear();
David Blaikie2aee7be2013-10-24 18:29:03 +0000408 Numbering[&Die] = 1;
Eric Christopher25b7adc2013-09-03 21:57:57 +0000409
David Blaikie2aee7be2013-10-24 18:29:03 +0000410 if (const DIE *Parent = Die.getParent())
411 addParentContext(*Parent);
David Blaikie8a142aa2013-10-17 00:10:34 +0000412
Eric Christopher25b7adc2013-09-03 21:57:57 +0000413 // Hash the DIE.
414 computeHash(Die);
415
416 // Now return the result.
417 MD5::MD5Result Result;
418 Hash.final(Result);
419
420 // ... take the least significant 8 bytes and return those. Our MD5
Zachary Turner82a0c972017-03-20 23:33:18 +0000421 // implementation always returns its results in little endian, so we actually
422 // need the "high" word.
423 return Result.high();
Eric Christopher25b7adc2013-09-03 21:57:57 +0000424}