diff --git a/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h b/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h index fedd2e4bcf3..9fca26b0e6e 100644 --- a/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h +++ b/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h @@ -53,7 +53,7 @@ public: TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete; void setVersionHeader(PdbRaw_TpiVer Version); - void addTypeRecord(const codeview::CVType &Record); + void addTypeRecord(ArrayRef Type, Optional Hash); Error finalizeMsfLayout(); @@ -68,9 +68,11 @@ private: msf::MSFBuilder &Msf; BumpPtrAllocator &Allocator; + size_t TypeRecordBytes = 0; + Optional VerHeader; - std::vector TypeRecords; - BinaryItemStream TypeRecordStream; + std::vector> TypeRecords; + std::vector TypeHashes; uint32_t HashStreamIndex = kInvalidStreamIndex; std::unique_ptr HashValueStream; diff --git a/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp b/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp index c34da581f01..27b9dad02ac 100644 --- a/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp @@ -34,8 +34,7 @@ using namespace llvm::pdb; using namespace llvm::support; TpiStreamBuilder::TpiStreamBuilder(MSFBuilder &Msf, uint32_t StreamIdx) - : Msf(Msf), Allocator(Msf.getAllocator()), - TypeRecordStream(llvm::support::little), Header(nullptr), Idx(StreamIdx) { + : Msf(Msf), Allocator(Msf.getAllocator()), Header(nullptr), Idx(StreamIdx) { } TpiStreamBuilder::~TpiStreamBuilder() = default; @@ -44,9 +43,12 @@ void TpiStreamBuilder::setVersionHeader(PdbRaw_TpiVer Version) { VerHeader = Version; } -void TpiStreamBuilder::addTypeRecord(const codeview::CVType &Record) { +void TpiStreamBuilder::addTypeRecord(ArrayRef Record, + Optional Hash) { + TypeRecordBytes += Record.size(); TypeRecords.push_back(Record); - TypeRecordStream.setItems(TypeRecords); + if (Hash) + TypeHashes.push_back(*Hash); } Error TpiStreamBuilder::finalize() { @@ -62,7 +64,7 @@ Error TpiStreamBuilder::finalize() { H->HeaderSize = sizeof(TpiStreamHeader); H->TypeIndexBegin = codeview::TypeIndex::FirstNonSimpleIndex; H->TypeIndexEnd = H->TypeIndexBegin + Count; - H->TypeRecordBytes = TypeRecordStream.getLength(); + H->TypeRecordBytes = TypeRecordBytes; H->HashStreamIndex = HashStreamIndex; H->HashAuxStreamIndex = kInvalidStreamIndex; @@ -84,13 +86,13 @@ Error TpiStreamBuilder::finalize() { } uint32_t TpiStreamBuilder::calculateSerializedLength() { - return sizeof(TpiStreamHeader) + TypeRecordStream.getLength(); + return sizeof(TpiStreamHeader) + TypeRecordBytes; } uint32_t TpiStreamBuilder::calculateHashBufferSize() const { - if (TypeRecords.empty() || !TypeRecords[0].Hash.hasValue()) - return 0; - return TypeRecords.size() * sizeof(ulittle32_t); + assert(TypeHashes.size() == TypeHashes.size() && + "either all or no type records should have hashes"); + return TypeHashes.size() * sizeof(ulittle32_t); } Error TpiStreamBuilder::finalizeMsfLayout() { @@ -107,10 +109,10 @@ Error TpiStreamBuilder::finalizeMsfLayout() { if (!ExpectedIndex) return ExpectedIndex.takeError(); HashStreamIndex = *ExpectedIndex; - ulittle32_t *H = Allocator.Allocate(TypeRecords.size()); - MutableArrayRef HashBuffer(H, TypeRecords.size()); - for (uint32_t I = 0; I < TypeRecords.size(); ++I) { - HashBuffer[I] = *TypeRecords[I].Hash % MinTpiHashBuckets; + ulittle32_t *H = Allocator.Allocate(TypeHashes.size()); + MutableArrayRef HashBuffer(H, TypeHashes.size()); + for (uint32_t I = 0; I < TypeHashes.size(); ++I) { + HashBuffer[I] = TypeHashes[I] % MinTpiHashBuckets; } ArrayRef Bytes(reinterpret_cast(HashBuffer.data()), HashBufferSize); @@ -131,9 +133,9 @@ Error TpiStreamBuilder::commit(const msf::MSFLayout &Layout, if (auto EC = Writer.writeObject(*Header)) return EC; - auto RecordArray = VarStreamArray(TypeRecordStream); - if (auto EC = Writer.writeArray(RecordArray)) - return EC; + for (auto Rec : TypeRecords) + if (auto EC = Writer.writeBytes(Rec)) + return EC; if (HashStreamIndex != kInvalidStreamIndex) { auto HVS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbdump/llvm-pdbdump.cpp index 3bd5fd7273b..76d05c463e3 100644 --- a/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -436,13 +436,13 @@ static void yamlToPdb(StringRef Path) { const auto &Tpi = YamlObj.TpiStream.getValueOr(DefaultTpiStream); TpiBuilder.setVersionHeader(Tpi.Version); for (const auto &R : Tpi.Records) - TpiBuilder.addTypeRecord(R.Record); + TpiBuilder.addTypeRecord(R.Record.data(), R.Record.Hash); const auto &Ipi = YamlObj.IpiStream.getValueOr(DefaultTpiStream); auto &IpiBuilder = Builder.getIpiBuilder(); IpiBuilder.setVersionHeader(Ipi.Version); for (const auto &R : Ipi.Records) - IpiBuilder.addTypeRecord(R.Record); + TpiBuilder.addTypeRecord(R.Record.data(), R.Record.Hash); ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile)); }