mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-09 05:13:01 +00:00
[pdbdump] Verify part of TPI hash streams.
TPI hash table contains a parallel array for the type records. For each type record R, a hash value is calculated by `H(R) % NumBuckets` where H is a hash function, and the result is stored to a bucket element. H is TPI1::hashPrec function in microsoft-pdb repository. Our hash function does not support all type record types yet. Currently it supports only records for line number. I'll extend it in a follow up patch. The aim of verify the hash table is not only detect corrupted files. It ensures that our understanding of how the hash values are calculated is correct. llvm-svn: 272229
This commit is contained in:
parent
43ac37c834
commit
ddd97c558f
@ -13,6 +13,7 @@
|
||||
#include "llvm/DebugInfo/CodeView/StreamReader.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
|
||||
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/Hash.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
|
||||
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
||||
@ -68,6 +69,22 @@ TpiStream::TpiStream(const PDBFile &File,
|
||||
|
||||
TpiStream::~TpiStream() {}
|
||||
|
||||
// Verifies that a given type record matches with a given hash value.
|
||||
// Currently we only verify SRC_LINE records.
|
||||
static Error verifyTIHash(const codeview::CVType &Rec, uint32_t Expected,
|
||||
uint32_t NumHashBuckets) {
|
||||
ArrayRef<uint8_t> D = Rec.Data;
|
||||
if (Rec.Type == codeview::LF_UDT_SRC_LINE ||
|
||||
Rec.Type == codeview::LF_UDT_MOD_SRC_LINE) {
|
||||
uint32_t Hash =
|
||||
hashStringV1(StringRef((const char *)D.data(), 4)) % NumHashBuckets;
|
||||
if (Hash != Expected)
|
||||
return make_error<RawError>(raw_error_code::corrupt_file,
|
||||
"Corrupt TPI hash table.");
|
||||
}
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
Error TpiStream::reload() {
|
||||
codeview::StreamReader Reader(*Stream);
|
||||
|
||||
@ -135,6 +152,17 @@ Error TpiStream::reload() {
|
||||
return EC;
|
||||
|
||||
HashStream = std::move(*HS);
|
||||
|
||||
// TPI hash table is a parallel array for the type records.
|
||||
// Verify that the hash values match with type records.
|
||||
size_t I = 0;
|
||||
bool HasError;
|
||||
for (const codeview::CVType &Rec : types(&HasError)) {
|
||||
if (auto EC = verifyTIHash(Rec, HashValues[I], Header->NumHashBuckets))
|
||||
return EC;
|
||||
++I;
|
||||
}
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user