llvm.org GIT mirror llvm / b26b734
Resubmit [pdb] Change /DEBUG:GHASH to emit 8 byte hashes." This fixes the remaining failing tests, so resubmitting with no functional change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332676 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 1 year, 3 months ago
8 changed file(s) with 73 addition(s) and 71 deletion(s). Raw diff Collapse all Expand all
5757 }
5858 };
5959
60 enum class GlobalTypeHashAlg : uint16_t { SHA1 = 0 };
60 enum class GlobalTypeHashAlg : uint16_t {
61 SHA1 = 0, // standard 20-byte SHA1 hash
62 SHA1_8 // last 8-bytes of standard SHA1 hash
63 };
6164
6265 /// A globally hashed type represents a hash value that is sufficient to
6366 /// uniquely identify a record across multiple type streams or type sequences.
7679 GloballyHashedType(StringRef H)
7780 : GloballyHashedType(ArrayRef(H.bytes_begin(), H.bytes_end())) {}
7881 GloballyHashedType(ArrayRef H) {
79 assert(H.size() == 20);
80 ::memcpy(Hash.data(), H.data(), 20);
81 }
82 std::array Hash;
82 assert(H.size() == 8);
83 ::memcpy(Hash.data(), H.data(), 8);
84 }
85 std::array Hash;
8386
8487 /// Given a sequence of bytes representing a record, compute a global hash for
8588 /// this record. Due to the nature of global hashes incorporating the hashes
3131 struct GlobalHash {
3232 GlobalHash() = default;
3333 explicit GlobalHash(StringRef S) : Hash(S) {
34 assert(S.size() == 20 && "Invalid hash size!");
34 assert(S.size() == 8 && "Invalid hash size!");
3535 }
3636 explicit GlobalHash(ArrayRef S) : Hash(S) {
37 assert(S.size() == 20 && "Invalid hash size!");
37 assert(S.size() == 8 && "Invalid hash size!");
3838 }
3939 yaml::BinaryRef Hash;
4040 };
588588 OS.AddComment("Section Version");
589589 OS.EmitIntValue(0, 2);
590590 OS.AddComment("Hash Algorithm");
591 OS.EmitIntValue(uint16_t(GlobalTypeHashAlg::SHA1), 2);
591 OS.EmitIntValue(uint16_t(GlobalTypeHashAlg::SHA1_8), 2);
592592
593593 TypeIndex TI(TypeIndex::FirstNonSimpleIndex);
594594 for (const auto &GHR : TypeTable.hashes()) {
601601 OS.AddComment(Comment);
602602 ++TI;
603603 }
604 assert(GHR.Hash.size() % 20 == 0);
604 assert(GHR.Hash.size() == 8);
605605 StringRef S(reinterpret_cast(GHR.Hash.data()),
606606 GHR.Hash.size());
607607 OS.EmitBinaryData(S);
1717 LocallyHashedType DenseMapInfo::Empty{0, {}};
1818 LocallyHashedType DenseMapInfo::Tombstone{hash_code(-1), {}};
1919
20 static std::array EmptyHash;
21 static std::array TombstoneHash = {
22 {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
20 static std::array EmptyHash = {
21 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
22 static std::array TombstoneHash = {
23 {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
2424
2525 GloballyHashedType DenseMapInfo::Empty{EmptyHash};
2626 GloballyHashedType DenseMapInfo::Tombstone{TombstoneHash};
7070 auto TrailingBytes = RecordData.drop_front(Off);
7171 S.update(TrailingBytes);
7272
73 return {S.final()};
73 return {S.final().take_back(8)};
7474 }
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
15
16 #include "llvm/BinaryFormat/COFF.h"
1517 #include "llvm/Support/BinaryByteStream.h"
1618 #include "llvm/Support/BinaryStreamReader.h"
1719 #include "llvm/Support/BinaryStreamWriter.h"
4547
4648 DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef DebugH) {
4749 assert(DebugH.size() >= 8);
48 assert((DebugH.size() - 8) % 20 == 0);
50 assert((DebugH.size() - 8) % 8 == 0);
4951
5052 BinaryStreamReader Reader(DebugH, llvm::support::little);
5153 DebugHSection DHS;
5254 cantFail(Reader.readInteger(DHS.Magic));
5355 cantFail(Reader.readInteger(DHS.Version));
5456 cantFail(Reader.readInteger(DHS.HashAlgorithm));
57
5558 while (Reader.bytesRemaining() != 0) {
5659 ArrayRef S;
57 cantFail(Reader.readBytes(S, 20));
60 cantFail(Reader.readBytes(S, 8));
5861 DHS.Hashes.emplace_back(S);
5962 }
6063 assert(Reader.bytesRemaining() == 0);
6366
6467 ArrayRef llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH,
6568 BumpPtrAllocator &Alloc) {
66 uint32_t Size = 8 + 20 * DebugH.Hashes.size();
69 uint32_t Size = 8 + 8 * DebugH.Hashes.size();
6770 uint8_t *Data = Alloc.Allocate(Size);
6871 MutableArrayRef Buffer(Data, Size);
6972 BinaryStreamWriter Writer(Buffer, llvm::support::little);
73
7074 cantFail(Writer.writeInteger(DebugH.Magic));
7175 cantFail(Writer.writeInteger(DebugH.Version));
7276 cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
73 SmallString<20> Hash;
77 SmallString<8> Hash;
7478 for (const auto &H : DebugH.Hashes) {
7579 Hash.clear();
7680 raw_svector_ostream OS(Hash);
7781 H.Hash.writeAsBinary(OS);
78 assert((Hash.size() == 20) && "Invalid hash size!");
82 assert((Hash.size() == 8) && "Invalid hash size!");
7983 cantFail(Writer.writeFixedString(Hash));
8084 }
8185 assert(Writer.bytesRemaining() == 0);
272272 ; YAML: Alignment: 4
273273 ; YAML: GlobalHashes:
274274 ; YAML: Version: 0
275 ; YAML: HashAlgorithm: 0
275 ; YAML: HashAlgorithm: 1
276276 ; YAML: HashValues:
277 ; YAML: - 624A7FEE7323656B7F1C5A63800309EE1ED8BB5B
278 ; YAML: - 0EB2C87AD629AA9E5C98B7A3ED69DB1355707DF1
279 ; YAML: - 624E463ACE08649D0FC35F163E20CC43089ADCA6
280 ; YAML: - 4B712C03EDA4CB88537EBAE4005A09006A9FB389
281 ; YAML: - 59EC21C3D8D594FF77854ABAC324F82D24D22283
282 ; YAML: - DA76AFB7C767EC00BAA171FEFAA2801D95716C22
283 ; YAML: - 4927143F1D91A64983DDA6B6DDE23757322DB7C3
284 ; YAML: - DFDF871AD3841199ACD961EA57243C7A1305B4DD
285 ; YAML: - 20015FA1AD3D0FF3546B4428D341E2F9BE57A1C7
286 ; YAML: - 8DC9D77BACDD53AAE3A5AC8F41C43D3C3122DCBC
287 ; YAML: - 77A85205D34B9C26802849355086C2937E3F45D8
288 ; YAML: - 4AEF9C1D1509C0FFA2A02F86B3C28FB0F254096C
289 ; YAML: - 83B03F51A4BABAE1E8B560B40634944401BCC520
290 ; YAML: - A82772A0D760F3EB5FC7A3022A6D376F5D7A92E2
291 ; YAML: - 235B46C1A3E3FB71D89ED6085E8B8D38632AACD6
292 ; YAML: - D52F03DB055DE93F19066E93FB3BA86C5A652429
277 ; YAML: - 800309EE1ED8BB5B
278 ; YAML: - 5397319F1CC14E2C
279 ; YAML: - DF04AA3125BBC50E
280 ; YAML: - 95CEBA304A2C4493
281 ; YAML: - C324F82D24D22283
282 ; YAML: - 74698BE366891D3D
283 ; YAML: - DDE23757322DB7C3
284 ; YAML: - 3C458A5105FEA7C1
285 ; YAML: - D341E2F9BE57A1C7
286 ; YAML: - 243F76AED6D8FB79
287 ; YAML: - B038D36C0C67EEEA
288 ; YAML: - C0A51CE268B50087
289 ; YAML: - 0634944401BCC520
290 ; YAML: - 8CFC595FACFE1AB2
291 ; YAML: - F1795EA10053AC52
292 ; YAML: - 17D3CDC3384402DD
293 ; ...
293294
294295
295296 ; ASM: .section .debug$H,"dr"
296297 ; ASM-NEXT: .p2align 2
297298 ; ASM-NEXT: .long 20171205 # Magic
298299 ; ASM-NEXT: .short 0 # Section Version
299 ; ASM-NEXT: .short 0 # Hash Algorithm
300 ; ASM-NEXT: .byte 0x62, 0x4a, 0x7f, 0xee # 0x1000 [624A7FEE7323656B7F1C5A63800309EE1ED8BB5B]
301 ; ASM-NEXT: .byte 0x73, 0x23, 0x65, 0x6b
302 ; ASM-NEXT: .byte 0x7f, 0x1c, 0x5a, 0x63
303 ; ASM-NEXT: .byte 0x80, 0x03, 0x09, 0xee
300 ; ASM-NEXT: .short 1 # Hash Algorithm
301 ; ASM-NEXT: .byte 0x80, 0x03, 0x09, 0xee # 0x1000 [800309EE1ED8BB5B]
304302 ; ASM-NEXT: .byte 0x1e, 0xd8, 0xbb, 0x5b
305 ; ASM-NEXT: .byte 0x0e, 0xb2, 0xc8, 0x7a # 0x1001 [0EB2C87AD629AA9E5C98B7A3ED69DB1355707DF1]
306 ; ASM-NEXT: .byte 0xd6, 0x29, 0xaa, 0x9e
307 ; ASM-NEXT: .byte 0x5c, 0x98, 0xb7, 0xa3
308 ; ASM-NEXT: .byte 0xed, 0x69, 0xdb, 0x13
309 ; ASM-NEXT: .byte 0x55, 0x70, 0x7d, 0xf1
310 ; ASM-NEXT: .byte 0x62, 0x4e, 0x46, 0x3a # 0x1002 [624E463ACE08649D0FC35F163E20CC43089ADCA6]
303 ; ASM-NEXT: .byte 0x53, 0x97, 0x31, 0x9f # 0x1001 [5397319F1CC14E2C]
304 ; ASM-NEXT: .byte 0x1c, 0xc1, 0x4e, 0x2c
305 ; ASM-NEXT: .byte 0xdf, 0x04, 0xaa, 0x31 # 0x1002 [DF04AA3125BBC50E]
1313 ; char**. Both the local and global hashes should be the same, since the only
1414 ; back-references are for simple types which have fixed indices.
1515 CHECK-ONE: obj-hashes-1
16 CHECK-ONE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 414E8FCAB16EC28AB86498D1A7F8CF106F39A384
16 CHECK-ONE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: A7F8CF106F39A384
1717 CHECK-ONE: obj-hashes-2
18 CHECK-ONE: TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 414E8FCAB16EC28AB86498D1A7F8CF106F39A384
18 CHECK-ONE: TI: 0x1000, LocalHash: {{.*}}, GlobalHash: A7F8CF106F39A384
1919
2020 ; int**. Same as char**, both the local and global hashes should be the same.
2121 CHECK-TWO: obj-hashes-1
22 CHECK-TWO: TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 91D2E2AD5D0F20EC1A24BE2E95D0616C5962F4B1
22 CHECK-TWO: TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 95D0616C5962F4B1
2323 CHECK-TWO: obj-hashes-2
24 CHECK-TWO: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 91D2E2AD5D0F20EC1A24BE2E95D0616C5962F4B1
24 CHECK-TWO: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 95D0616C5962F4B1
2525
2626 ; int***. Different local hashes, since the referent type (int**) is not at the
2727 ; same TypeIndex in both streams. Same global hash, since they represent the
2828 ; same record.
2929 CHECK-THREE: obj-hashes-1
30 CHECK-THREE: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 68A6DDB5C538D379E72E6425591A2B16352DF93D
30 CHECK-THREE: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 48D95F14F6176F4F
3131 CHECK-THREE: obj-hashes-2
32 CHECK-THREE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 68A6DDB5C538D379E72E6425591A2B16352DF93D
32 CHECK-THREE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 48D95F14F6176F4F
3333
3434 ; arg list (char**, int***). Different local hashes, since the parameter types
3535 ; both occur at different TypeIndices in their respective input streams. Same
3636 ; global hash, since the global hash of all referenced types is the same in
3737 ; both streams.
3838 CHECK-FOUR: obj-hashes-1
39 CHECK-FOUR: TI: 0x1003, LocalHash: {{.*}}, GlobalHash: FD539365C0A8DEC0A1567C3E2F4C82E7AADB0E51
39 CHECK-FOUR: TI: 0x1003, LocalHash: {{.*}}, GlobalHash: 99410CD14F5EE80D
4040 CHECK-FOUR: obj-hashes-2
41 CHECK-FOUR: TI: 0x1004, LocalHash: {{.*}}, GlobalHash: FD539365C0A8DEC0A1567C3E2F4C82E7AADB0E51
41 CHECK-FOUR: TI: 0x1004, LocalHash: {{.*}}, GlobalHash: 99410CD14F5EE80D
4242
4343 ; double**. This is only in stream 2, as a means to throw off the indexing.
4444 CHECK-FIVE: obj-hashes-1
4545 CHECK-FIVE: obj-hashes-2
46 CHECK-FIVE: TI: 0x1003, LocalHash: {{.*}}, GlobalHash: 5BB6926CA7924D06908872FA20691EA9B88584CC
46 CHECK-FIVE: TI: 0x1003, LocalHash: {{.*}}, GlobalHash: 20691EA9B88584CC
4747
4848 ; int** (char**, int***). For the same logic as described in previous records,
4949 ; these two records have the same global hash but different local hashes.
5050 CHECK-SIX: obj-hashes-1
51 CHECK-SIX: TI: 0x1004, LocalHash: {{.*}}, GlobalHash: 7A8576BA937B2E87BBF94A9CBFA8F993EE746065
51 CHECK-SIX: TI: 0x1004, LocalHash: {{.*}}, GlobalHash: 7ACF479173341AC1
5252 CHECK-SIX: obj-hashes-2
53 CHECK-SIX: TI: 0x1005, LocalHash: {{.*}}, GlobalHash: 7A8576BA937B2E87BBF94A9CBFA8F993EE746065
53 CHECK-SIX: TI: 0x1005, LocalHash: {{.*}}, GlobalHash: 7ACF479173341AC1
2020 Alignment: 4
2121 GlobalHashes:
2222 Version: 0
23 HashAlgorithm: 0
23 HashAlgorithm: 1
2424 HashValues:
25 - 1522A98D88FAF71B618D97BCAC2B89A424EC4805
26 - 8B2BA87CC27BF9D290A31A6070FA296AAA577E53
27 - EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4
28 - 1088AD64CEBC88D9E015058A159516AF20B79286
29 - 457ABCB8AB70407594B5D72BF471B6BDECC99BC9
25 - AC2B89A424EC4805
26 - 70FA296AAA577E53
27 - E2C98293782A7EB4
28 - 159516AF20B79286
29 - F471B6BDECC99BC9
3030 symbols:
3131 - Name: '.debug$T'
3232 Value: 0
7373 # CHECK: Alignment: 4
7474 # CHECK: GlobalHashes:
7575 # CHECK: Version: 0
76 # CHECK: HashAlgorithm: 0
76 # CHECK: HashAlgorithm: 1
7777 # CHECK: HashValues:
78 # CHECK: - 1522A98D88FAF71B618D97BCAC2B89A424EC4805
79 # CHECK: - 8B2BA87CC27BF9D290A31A6070FA296AAA577E53
80 # CHECK: - EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4
81 # CHECK: - 1088AD64CEBC88D9E015058A159516AF20B79286
82 # CHECK: - 457ABCB8AB70407594B5D72BF471B6BDECC99BC9
78 # CHECK: - AC2B89A424EC4805
79 # CHECK: - 70FA296AAA577E53
80 # CHECK: - E2C98293782A7EB4
81 # CHECK: - 159516AF20B79286
82 # CHECK: - F471B6BDECC99BC9
8383 # CHECK: symbols:
8484 # CHECK: - Name: '.debug$T'
8585 # CHECK: Value: 0
108108 # CHECK: ...
109109
110110 # HEADERS: 0 .debug$T 00000040 0000000000000000 DATA
111 # HEADERS: 1 .debug$H 0000006c 0000000000000000 DATA
111 # HEADERS: 1 .debug$H 00000030 0000000000000000 DATA