llvm.org GIT mirror llvm / d0e6e5a
[pdb] Change /DEBUG:GHASH to emit 8 byte hashes. Previously we emitted 20-byte SHA1 hashes. This is overkill for identifying debug info records, and has the negative side effect of making object files bigger and links slower. By using only the last 8 bytes of a SHA1, we get smaller object files and ~10% faster links. This modifies the format of the .debug$H section by adding a new value for the hash algorithm field, so that the linker will still work when its object files have an old format. Differential Revision: https://reviews.llvm.org/D46855 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332669 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 1 year, 3 months ago
7 changed file(s) with 75 addition(s) and 68 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
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 = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
21 static std::array TombstoneHash = {
22 {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
2423
2524 GloballyHashedType DenseMapInfo::Empty{EmptyHash};
2625 GloballyHashedType DenseMapInfo::Tombstone{TombstoneHash};
7069 auto TrailingBytes = RecordData.drop_front(Off);
7170 S.update(TrailingBytes);
7271
73 return {S.final()};
72 return {S.final().take_back(8)};
7473 }
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 assert(DHS.Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$H section!");
58 assert(DHS.Version == 1 && "Invalid .debug$H version!");
59 assert(DHS.HashAlgorithm == 1 && "Invalid .debug$H algorithm!");
60
5561 while (Reader.bytesRemaining() != 0) {
5662 ArrayRef S;
57 cantFail(Reader.readBytes(S, 20));
63 cantFail(Reader.readBytes(S, 8));
5864 DHS.Hashes.emplace_back(S);
5965 }
6066 assert(Reader.bytesRemaining() == 0);
6369
6470 ArrayRef llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH,
6571 BumpPtrAllocator &Alloc) {
66 uint32_t Size = 8 + 20 * DebugH.Hashes.size();
72 uint32_t Size = 8 + 8 * DebugH.Hashes.size();
6773 uint8_t *Data = Alloc.Allocate(Size);
6874 MutableArrayRef Buffer(Data, Size);
6975 BinaryStreamWriter Writer(Buffer, llvm::support::little);
76 assert(DebugH.Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$H section!");
77 assert(DebugH.Version == 1 && "Invalid .debug$H version!");
78 assert(DebugH.HashAlgorithm == 1 && "Invalid .debug$H algorithm!");
79
7080 cantFail(Writer.writeInteger(DebugH.Magic));
7181 cantFail(Writer.writeInteger(DebugH.Version));
7282 cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
73 SmallString<20> Hash;
83 SmallString<8> Hash;
7484 for (const auto &H : DebugH.Hashes) {
7585 Hash.clear();
7686 raw_svector_ostream OS(Hash);
7787 H.Hash.writeAsBinary(OS);
78 assert((Hash.size() == 20) && "Invalid hash size!");
88 assert((Hash.size() == 8) && "Invalid hash size!");
7989 cantFail(Writer.writeFixedString(Hash));
8090 }
8191 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: - E09E6E9DA0F4EE31
278 ; YAML: - AC3421E42389A5FD
279 ; YAML: - 09DDDA6CB66C9F23
280 ; YAML: - 01B4ACFA70BEACA1
281 ; YAML: - 8A222FBBEBBE140E
282 ; YAML: - 4497C6AE188A6220
283 ; YAML: - 14A9932F03846156
284 ; YAML: - CBC539F8C18B2D2D
285 ; YAML: - 3E52C5C25299E473
286 ; YAML: - 8FEE74F5141FCC22
287 ; YAML: - DF48EB0A8ED58F85
288 ; YAML: - 8EE98BB0F291CBF8
289 ; YAML: - D18EEE3C1C0C4C09
290 ; YAML: - 67C712E2108F482A
291 ; YAML: - 23945F2B63311976
292 ; YAML: - 7F1CACD4255A7ADF
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
304 ; 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]
300 ; ASM-NEXT: .short 1 # Hash Algorithm
301 ; ASM-NEXT: .byte 0xe0, 0x9e, 0x6e, 0x9d # 0x1000 [E09E6E9DA0F4EE31]
302 ; ASM-NEXT: .byte 0xa0, 0xf4, 0xee, 0x31
303 ; ASM-NEXT: .byte 0xac, 0x34, 0x21, 0xe4 # 0x1001 [AC3421E42389A5FD]
304 ; ASM-NEXT: .byte 0x23, 0x89, 0xa5, 0xfd
305 ; ASM-NEXT: .byte 0x09, 0xdd, 0xda, 0x6c # 0x1002 [09DDDA6CB66C9F23]
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: 70FA296AAA577E53
1717 CHECK-ONE: obj-hashes-2
18 CHECK-ONE: TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 414E8FCAB16EC28AB86498D1A7F8CF106F39A384
18 CHECK-ONE: TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 70FA296AAA577E53
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: AC2B89A424EC4805
2323 CHECK-TWO: obj-hashes-2
24 CHECK-TWO: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 91D2E2AD5D0F20EC1A24BE2E95D0616C5962F4B1
24 CHECK-TWO: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: AC2B89A424EC4805
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: 9D6275A3E1B37A7D
3131 CHECK-THREE: obj-hashes-2
32 CHECK-THREE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 68A6DDB5C538D379E72E6425591A2B16352DF93D
32 CHECK-THREE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 9D6275A3E1B37A7D
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: C82DFD641EB22940
4040 CHECK-FOUR: obj-hashes-2
41 CHECK-FOUR: TI: 0x1004, LocalHash: {{.*}}, GlobalHash: FD539365C0A8DEC0A1567C3E2F4C82E7AADB0E51
41 CHECK-FOUR: TI: 0x1004, LocalHash: {{.*}}, GlobalHash: C82DFD641EB22940
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: 102BD08F68315506
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: 526C704BC7D94D40
5252 CHECK-SIX: obj-hashes-2
53 CHECK-SIX: TI: 0x1005, LocalHash: {{.*}}, GlobalHash: 7A8576BA937B2E87BBF94A9CBFA8F993EE746065
53 CHECK-SIX: TI: 0x1005, LocalHash: {{.*}}, GlobalHash: 526C704BC7D94D40
2222 Version: 0
2323 HashAlgorithm: 0
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
7575 # CHECK: Version: 0
7676 # CHECK: HashAlgorithm: 0
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