[llvm] r332669 - [pdb] Change /DEBUG:GHASH to emit 8 byte hashes.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu May 17 14:22:49 PDT 2018


Author: zturner
Date: Thu May 17 14:22:48 2018
New Revision: 332669

URL: http://llvm.org/viewvc/llvm-project?rev=332669&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeHashing.h
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/trunk/lib/DebugInfo/CodeView/TypeHashing.cpp
    llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp
    llvm/trunk/test/DebugInfo/COFF/global-type-hashes.ll
    llvm/trunk/test/DebugInfo/PDB/obj-globalhash.test
    llvm/trunk/test/ObjectYAML/CodeView/sections.yaml

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeHashing.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeHashing.h?rev=332669&r1=332668&r2=332669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeHashing.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeHashing.h Thu May 17 14:22:48 2018
@@ -58,7 +58,10 @@ struct LocallyHashedType {
   }
 };
 
-enum class GlobalTypeHashAlg : uint16_t { SHA1 = 0 };
+enum class GlobalTypeHashAlg : uint16_t {
+  SHA1 = 0,  // standard 20-byte SHA1 hash
+  SHA1_8     // last 8-bytes of standard SHA1 hash
+};
 
 /// A globally hashed type represents a hash value that is sufficient to
 /// uniquely identify a record across multiple type streams or type sequences.
@@ -77,10 +80,10 @@ struct GloballyHashedType {
   GloballyHashedType(StringRef H)
       : GloballyHashedType(ArrayRef<uint8_t>(H.bytes_begin(), H.bytes_end())) {}
   GloballyHashedType(ArrayRef<uint8_t> H) {
-    assert(H.size() == 20);
-    ::memcpy(Hash.data(), H.data(), 20);
+    assert(H.size() == 8);
+    ::memcpy(Hash.data(), H.data(), 8);
   }
-  std::array<uint8_t, 20> Hash;
+  std::array<uint8_t, 8> Hash;
 
   /// Given a sequence of bytes representing a record, compute a global hash for
   /// this record.  Due to the nature of global hashes incorporating the hashes

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=332669&r1=332668&r2=332669&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Thu May 17 14:22:48 2018
@@ -589,7 +589,7 @@ void CodeViewDebug::emitTypeGlobalHashes
   OS.AddComment("Section Version");
   OS.EmitIntValue(0, 2);
   OS.AddComment("Hash Algorithm");
-  OS.EmitIntValue(uint16_t(GlobalTypeHashAlg::SHA1), 2);
+  OS.EmitIntValue(uint16_t(GlobalTypeHashAlg::SHA1_8), 2);
 
   TypeIndex TI(TypeIndex::FirstNonSimpleIndex);
   for (const auto &GHR : TypeTable.hashes()) {
@@ -602,7 +602,7 @@ void CodeViewDebug::emitTypeGlobalHashes
       OS.AddComment(Comment);
       ++TI;
     }
-    assert(GHR.Hash.size() % 20 == 0);
+    assert(GHR.Hash.size() == 8);
     StringRef S(reinterpret_cast<const char *>(GHR.Hash.data()),
                 GHR.Hash.size());
     OS.EmitBinaryData(S);

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeHashing.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeHashing.cpp?rev=332669&r1=332668&r2=332669&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeHashing.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeHashing.cpp Thu May 17 14:22:48 2018
@@ -18,10 +18,9 @@ using namespace llvm::codeview;
 LocallyHashedType DenseMapInfo<LocallyHashedType>::Empty{0, {}};
 LocallyHashedType DenseMapInfo<LocallyHashedType>::Tombstone{hash_code(-1), {}};
 
-static std::array<uint8_t, 20> EmptyHash;
-static std::array<uint8_t, 20> TombstoneHash = {
-    {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
+static std::array<uint8_t, 8> EmptyHash = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
+static std::array<uint8_t, 8> TombstoneHash = {
+  {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
 
 GloballyHashedType DenseMapInfo<GloballyHashedType>::Empty{EmptyHash};
 GloballyHashedType DenseMapInfo<GloballyHashedType>::Tombstone{TombstoneHash};
@@ -71,5 +70,5 @@ GloballyHashedType::hashType(ArrayRef<ui
   auto TrailingBytes = RecordData.drop_front(Off);
   S.update(TrailingBytes);
 
-  return {S.final()};
+  return {S.final().take_back(8)};
 }

Modified: llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp?rev=332669&r1=332668&r2=332669&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp Thu May 17 14:22:48 2018
@@ -13,6 +13,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
+
+#include "llvm/BinaryFormat/COFF.h"
 #include "llvm/Support/BinaryByteStream.h"
 #include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/BinaryStreamWriter.h"
@@ -46,16 +48,20 @@ StringRef ScalarTraits<GlobalHash>::inpu
 
 DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef<uint8_t> DebugH) {
   assert(DebugH.size() >= 8);
-  assert((DebugH.size() - 8) % 20 == 0);
+  assert((DebugH.size() - 8) % 8 == 0);
 
   BinaryStreamReader Reader(DebugH, llvm::support::little);
   DebugHSection DHS;
   cantFail(Reader.readInteger(DHS.Magic));
   cantFail(Reader.readInteger(DHS.Version));
   cantFail(Reader.readInteger(DHS.HashAlgorithm));
+  assert(DHS.Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$H section!");
+  assert(DHS.Version == 1 && "Invalid .debug$H version!");
+  assert(DHS.HashAlgorithm == 1 && "Invalid .debug$H algorithm!");
+
   while (Reader.bytesRemaining() != 0) {
     ArrayRef<uint8_t> S;
-    cantFail(Reader.readBytes(S, 20));
+    cantFail(Reader.readBytes(S, 8));
     DHS.Hashes.emplace_back(S);
   }
   assert(Reader.bytesRemaining() == 0);
@@ -64,19 +70,23 @@ DebugHSection llvm::CodeViewYAML::fromDe
 
 ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH,
                                                BumpPtrAllocator &Alloc) {
-  uint32_t Size = 8 + 20 * DebugH.Hashes.size();
+  uint32_t Size = 8 + 8 * DebugH.Hashes.size();
   uint8_t *Data = Alloc.Allocate<uint8_t>(Size);
   MutableArrayRef<uint8_t> Buffer(Data, Size);
   BinaryStreamWriter Writer(Buffer, llvm::support::little);
+  assert(DebugH.Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$H section!");
+  assert(DebugH.Version == 1 && "Invalid .debug$H version!");
+  assert(DebugH.HashAlgorithm == 1 && "Invalid .debug$H algorithm!");
+
   cantFail(Writer.writeInteger(DebugH.Magic));
   cantFail(Writer.writeInteger(DebugH.Version));
   cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
-  SmallString<20> Hash;
+  SmallString<8> Hash;
   for (const auto &H : DebugH.Hashes) {
     Hash.clear();
     raw_svector_ostream OS(Hash);
     H.Hash.writeAsBinary(OS);
-    assert((Hash.size() == 20) && "Invalid hash size!");
+    assert((Hash.size() == 8) && "Invalid hash size!");
     cantFail(Writer.writeFixedString(Hash));
   }
   assert(Writer.bytesRemaining() == 0);

Modified: llvm/trunk/test/DebugInfo/COFF/global-type-hashes.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/global-type-hashes.ll?rev=332669&r1=332668&r2=332669&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/global-type-hashes.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/global-type-hashes.ll Thu May 17 14:22:48 2018
@@ -273,39 +273,34 @@ attributes #2 = { noinline nounwind optn
 ; YAML:     Alignment:       4
 ; YAML:     GlobalHashes:
 ; YAML:       Version:         0
-; YAML:       HashAlgorithm:   0
+; YAML:       HashAlgorithm:   1
 ; YAML:       HashValues:
-; YAML:         - 624A7FEE7323656B7F1C5A63800309EE1ED8BB5B
-; YAML:         - 0EB2C87AD629AA9E5C98B7A3ED69DB1355707DF1
-; YAML:         - 624E463ACE08649D0FC35F163E20CC43089ADCA6
-; YAML:         - 4B712C03EDA4CB88537EBAE4005A09006A9FB389
-; YAML:         - 59EC21C3D8D594FF77854ABAC324F82D24D22283
-; YAML:         - DA76AFB7C767EC00BAA171FEFAA2801D95716C22
-; YAML:         - 4927143F1D91A64983DDA6B6DDE23757322DB7C3
-; YAML:         - DFDF871AD3841199ACD961EA57243C7A1305B4DD
-; YAML:         - 20015FA1AD3D0FF3546B4428D341E2F9BE57A1C7
-; YAML:         - 8DC9D77BACDD53AAE3A5AC8F41C43D3C3122DCBC
-; YAML:         - 77A85205D34B9C26802849355086C2937E3F45D8
-; YAML:         - 4AEF9C1D1509C0FFA2A02F86B3C28FB0F254096C
-; YAML:         - 83B03F51A4BABAE1E8B560B40634944401BCC520
-; YAML:         - A82772A0D760F3EB5FC7A3022A6D376F5D7A92E2
-; YAML:         - 235B46C1A3E3FB71D89ED6085E8B8D38632AACD6
-; YAML:         - D52F03DB055DE93F19066E93FB3BA86C5A652429
+; YAML:         - E09E6E9DA0F4EE31
+; YAML:         - AC3421E42389A5FD
+; YAML:         - 09DDDA6CB66C9F23
+; YAML:         - 01B4ACFA70BEACA1
+; YAML:         - 8A222FBBEBBE140E
+; YAML:         - 4497C6AE188A6220
+; YAML:         - 14A9932F03846156
+; YAML:         - CBC539F8C18B2D2D
+; YAML:         - 3E52C5C25299E473
+; YAML:         - 8FEE74F5141FCC22
+; YAML:         - DF48EB0A8ED58F85
+; YAML:         - 8EE98BB0F291CBF8
+; YAML:         - D18EEE3C1C0C4C09
+; YAML:         - 67C712E2108F482A
+; YAML:         - 23945F2B63311976
+; YAML:         - 7F1CACD4255A7ADF
+; ...
 
 
 ; ASM:      .section        .debug$H,"dr"
 ; ASM-NEXT: .p2align        2
 ; ASM-NEXT: .long   20171205                # Magic
 ; ASM-NEXT: .short  0                       # Section Version
-; ASM-NEXT: .short  0                       # Hash Algorithm
-; ASM-NEXT: .byte   0x62, 0x4a, 0x7f, 0xee  # 0x1000 [624A7FEE7323656B7F1C5A63800309EE1ED8BB5B]
-; ASM-NEXT: .byte   0x73, 0x23, 0x65, 0x6b
-; ASM-NEXT: .byte   0x7f, 0x1c, 0x5a, 0x63
-; ASM-NEXT: .byte   0x80, 0x03, 0x09, 0xee
-; ASM-NEXT: .byte   0x1e, 0xd8, 0xbb, 0x5b
-; ASM-NEXT: .byte   0x0e, 0xb2, 0xc8, 0x7a  # 0x1001 [0EB2C87AD629AA9E5C98B7A3ED69DB1355707DF1]
-; ASM-NEXT: .byte   0xd6, 0x29, 0xaa, 0x9e
-; ASM-NEXT: .byte   0x5c, 0x98, 0xb7, 0xa3
-; ASM-NEXT: .byte   0xed, 0x69, 0xdb, 0x13
-; ASM-NEXT: .byte   0x55, 0x70, 0x7d, 0xf1
-; ASM-NEXT: .byte   0x62, 0x4e, 0x46, 0x3a  # 0x1002 [624E463ACE08649D0FC35F163E20CC43089ADCA6]
+; ASM-NEXT: .short  1                       # Hash Algorithm
+; ASM-NEXT: .byte   0xe0, 0x9e, 0x6e, 0x9d  # 0x1000 [E09E6E9DA0F4EE31]
+; ASM-NEXT: .byte   0xa0, 0xf4, 0xee, 0x31
+; ASM-NEXT: .byte   0xac, 0x34, 0x21, 0xe4  # 0x1001 [AC3421E42389A5FD]
+; ASM-NEXT: .byte   0x23, 0x89, 0xa5, 0xfd
+; ASM-NEXT: .byte   0x09, 0xdd, 0xda, 0x6c  # 0x1002 [09DDDA6CB66C9F23]

Modified: llvm/trunk/test/DebugInfo/PDB/obj-globalhash.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/obj-globalhash.test?rev=332669&r1=332668&r2=332669&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/obj-globalhash.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/obj-globalhash.test Thu May 17 14:22:48 2018
@@ -14,41 +14,41 @@ RUN: cat %T/hashes-combined.out | FileCh
 ; char**.  Both the local and global hashes should be the same, since the only
 ; back-references are for simple types which have fixed indices.
 CHECK-ONE:   obj-hashes-1
-CHECK-ONE:   TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 414E8FCAB16EC28AB86498D1A7F8CF106F39A384
+CHECK-ONE:   TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 70FA296AAA577E53
 CHECK-ONE:   obj-hashes-2
-CHECK-ONE:   TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 414E8FCAB16EC28AB86498D1A7F8CF106F39A384
+CHECK-ONE:   TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 70FA296AAA577E53
 
 ; int**.  Same as char**, both the local and global hashes should be the same.
 CHECK-TWO:   obj-hashes-1
-CHECK-TWO:   TI: 0x1000, LocalHash: {{.*}}, GlobalHash: 91D2E2AD5D0F20EC1A24BE2E95D0616C5962F4B1
+CHECK-TWO:   TI: 0x1000, LocalHash: {{.*}}, GlobalHash: AC2B89A424EC4805
 CHECK-TWO:   obj-hashes-2
-CHECK-TWO:   TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 91D2E2AD5D0F20EC1A24BE2E95D0616C5962F4B1
+CHECK-TWO:   TI: 0x1002, LocalHash: {{.*}}, GlobalHash: AC2B89A424EC4805
 
 ; int***. Different local hashes, since the referent type (int**) is not at the
 ; same TypeIndex in both streams.  Same global hash, since they represent the
 ; same record.
 CHECK-THREE: obj-hashes-1
-CHECK-THREE: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 68A6DDB5C538D379E72E6425591A2B16352DF93D
+CHECK-THREE: TI: 0x1002, LocalHash: {{.*}}, GlobalHash: 9D6275A3E1B37A7D
 CHECK-THREE: obj-hashes-2
-CHECK-THREE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 68A6DDB5C538D379E72E6425591A2B16352DF93D
+CHECK-THREE: TI: 0x1001, LocalHash: {{.*}}, GlobalHash: 9D6275A3E1B37A7D
 
 ; arg list (char**, int***).  Different local hashes, since the parameter types
 ; both occur at different TypeIndices in their respective input streams.  Same
 ; global hash, since the global hash of all referenced types is the same in
 ; both streams.
 CHECK-FOUR:  obj-hashes-1
-CHECK-FOUR:  TI: 0x1003, LocalHash: {{.*}}, GlobalHash: FD539365C0A8DEC0A1567C3E2F4C82E7AADB0E51
+CHECK-FOUR:  TI: 0x1003, LocalHash: {{.*}}, GlobalHash: C82DFD641EB22940
 CHECK-FOUR:  obj-hashes-2
-CHECK-FOUR:  TI: 0x1004, LocalHash: {{.*}}, GlobalHash: FD539365C0A8DEC0A1567C3E2F4C82E7AADB0E51
+CHECK-FOUR:  TI: 0x1004, LocalHash: {{.*}}, GlobalHash: C82DFD641EB22940
 
 ; double**.  This is only in stream 2, as a means to throw off the indexing.
 CHECK-FIVE:  obj-hashes-1
 CHECK-FIVE:  obj-hashes-2
-CHECK-FIVE:  TI: 0x1003, LocalHash: {{.*}}, GlobalHash: 5BB6926CA7924D06908872FA20691EA9B88584CC
+CHECK-FIVE:  TI: 0x1003, LocalHash: {{.*}}, GlobalHash: 102BD08F68315506
 
 ; int** (char**, int***).  For the same logic as described in previous records,
 ; these two records have the same global hash but different local hashes.
 CHECK-SIX:   obj-hashes-1
-CHECK-SIX:   TI: 0x1004, LocalHash: {{.*}}, GlobalHash: 7A8576BA937B2E87BBF94A9CBFA8F993EE746065
+CHECK-SIX:   TI: 0x1004, LocalHash: {{.*}}, GlobalHash: 526C704BC7D94D40
 CHECK-SIX:   obj-hashes-2
-CHECK-SIX:   TI: 0x1005, LocalHash: {{.*}}, GlobalHash: 7A8576BA937B2E87BBF94A9CBFA8F993EE746065
+CHECK-SIX:   TI: 0x1005, LocalHash: {{.*}}, GlobalHash: 526C704BC7D94D40

Modified: llvm/trunk/test/ObjectYAML/CodeView/sections.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/CodeView/sections.yaml?rev=332669&r1=332668&r2=332669&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/CodeView/sections.yaml (original)
+++ llvm/trunk/test/ObjectYAML/CodeView/sections.yaml Thu May 17 14:22:48 2018
@@ -23,11 +23,11 @@ sections:
       Version:          0
       HashAlgorithm:    0
       HashValues:
-        - 1522A98D88FAF71B618D97BCAC2B89A424EC4805
-        - 8B2BA87CC27BF9D290A31A6070FA296AAA577E53
-        - EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4
-        - 1088AD64CEBC88D9E015058A159516AF20B79286
-        - 457ABCB8AB70407594B5D72BF471B6BDECC99BC9
+        - AC2B89A424EC4805
+        - 70FA296AAA577E53
+        - E2C98293782A7EB4
+        - 159516AF20B79286
+        - F471B6BDECC99BC9
 symbols:
   - Name:            '.debug$T'
     Value:           0
@@ -76,11 +76,11 @@ symbols:
 # CHECK:       Version:          0
 # CHECK:       HashAlgorithm:    0
 # CHECK:       HashValues:
-# CHECK:         - 1522A98D88FAF71B618D97BCAC2B89A424EC4805
-# CHECK:         - 8B2BA87CC27BF9D290A31A6070FA296AAA577E53
-# CHECK:         - EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4
-# CHECK:         - 1088AD64CEBC88D9E015058A159516AF20B79286
-# CHECK:         - 457ABCB8AB70407594B5D72BF471B6BDECC99BC9
+# CHECK:         - AC2B89A424EC4805
+# CHECK:         - 70FA296AAA577E53
+# CHECK:         - E2C98293782A7EB4
+# CHECK:         - 159516AF20B79286
+# CHECK:         - F471B6BDECC99BC9
 # CHECK: symbols:
 # CHECK:   - Name:            '.debug$T'
 # CHECK:     Value:           0
@@ -109,4 +109,4 @@ symbols:
 # CHECK: ...
 
 # HEADERS:   0 .debug$T      00000040 0000000000000000 DATA
-# HEADERS:   1 .debug$H      0000006c 0000000000000000 DATA
+# HEADERS:   1 .debug$H      00000030 0000000000000000 DATA




More information about the llvm-commits mailing list