[llvm] r272229 - [pdbdump] Verify part of TPI hash streams.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 8 17:10:20 PDT 2016
Author: ruiu
Date: Wed Jun 8 19:10:19 2016
New Revision: 272229
URL: http://llvm.org/viewvc/llvm-project?rev=272229&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp?rev=272229&r1=272228&r2=272229&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp Wed Jun 8 19:10:19 2016
@@ -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();
}
More information about the llvm-commits
mailing list