[llvm] r327675 - [PDB] Fix a bug where we were serializing hash tables incorrectly.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 15 15:31:00 PDT 2018
Author: zturner
Date: Thu Mar 15 15:31:00 2018
New Revision: 327675
URL: http://llvm.org/viewvc/llvm-project?rev=327675&view=rev
Log:
[PDB] Fix a bug where we were serializing hash tables incorrectly.
There was some code that tried to calculate the number of 4-byte
words required to hold N bits, but it was instead computing the
number of bytes required to hold N bits. This was leading to
extraneous data being output into the hash table, which would
cause certain operations in DIA (the Microsoft PDB reader) to
fail.
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/Native/HashTable.h
llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/HashTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/HashTable.h?rev=327675&r1=327674&r2=327675&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/HashTable.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/HashTable.h Thu Mar 15 15:31:00 2018
@@ -161,16 +161,23 @@ public:
uint32_t calculateSerializedLength() const {
uint32_t Size = sizeof(Header);
+ constexpr int BitsPerWord = 8 * sizeof(uint32_t);
+
int NumBitsP = Present.find_last() + 1;
int NumBitsD = Deleted.find_last() + 1;
- // Present bit set number of words, followed by that many actual words.
+ uint32_t NumWordsP = alignTo(NumBitsP, BitsPerWord) / BitsPerWord;
+ uint32_t NumWordsD = alignTo(NumBitsD, BitsPerWord) / BitsPerWord;
+
+ // Present bit set number of words (4 bytes), followed by that many actual
+ // words (4 bytes each).
Size += sizeof(uint32_t);
- Size += alignTo(NumBitsP, sizeof(uint32_t));
+ Size += NumWordsP * sizeof(uint32_t);
- // Deleted bit set number of words, followed by that many actual words.
+ // Deleted bit set number of words (4 bytes), followed by that many actual
+ // words (4 bytes each).
Size += sizeof(uint32_t);
- Size += alignTo(NumBitsD, sizeof(uint32_t));
+ Size += NumWordsD * sizeof(uint32_t);
// One (Key, ValueT) pair for each entry Present.
Size += (sizeof(uint32_t) + sizeof(ValueT)) * size();
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp?rev=327675&r1=327674&r2=327675&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp Thu Mar 15 15:31:00 2018
@@ -46,16 +46,18 @@ Error llvm::pdb::readSparseBitVector(Bin
Error llvm::pdb::writeSparseBitVector(BinaryStreamWriter &Writer,
SparseBitVector<> &Vec) {
+ constexpr int BitsPerWord = 8 * sizeof(uint32_t);
+
int ReqBits = Vec.find_last() + 1;
- uint32_t NumWords = alignTo(ReqBits, sizeof(uint32_t)) / sizeof(uint32_t);
- if (auto EC = Writer.writeInteger(NumWords))
+ uint32_t ReqWords = alignTo(ReqBits, BitsPerWord) / BitsPerWord;
+ if (auto EC = Writer.writeInteger(ReqWords))
return joinErrors(
std::move(EC),
make_error<RawError>(raw_error_code::corrupt_file,
"Could not write linear map number of words"));
uint32_t Idx = 0;
- for (uint32_t I = 0; I != NumWords; ++I) {
+ for (uint32_t I = 0; I != ReqWords; ++I) {
uint32_t Word = 0;
for (uint32_t WordIdx = 0; WordIdx < 32; ++WordIdx, ++Idx) {
if (Vec.test(Idx))
More information about the llvm-commits
mailing list