diff options
| author | Zachary Turner <zturner@google.com> | 2017-02-28 00:04:07 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2017-02-28 00:04:07 +0000 |
| commit | 695ed56ba5d3bd3b86c6a4ed6d79b89eb8fbd2f4 (patch) | |
| tree | caf35bd7345bb071545ef39b636b40ffafc41504 /llvm/lib/DebugInfo/PDB/Native | |
| parent | 59cd89332010b22e82c3110d558ff37948c4df1e (diff) | |
| download | bcm5719-llvm-695ed56ba5d3bd3b86c6a4ed6d79b89eb8fbd2f4.tar.gz bcm5719-llvm-695ed56ba5d3bd3b86c6a4ed6d79b89eb8fbd2f4.zip | |
[PDB] Make streams carry their own endianness.
Before the endianness was specified on each call to read
or write of the StreamReader / StreamWriter, but in practice
it's extremely rare for streams to have data encoded in
multiple different endiannesses, so we should optimize for the
99% use case.
This makes the code cleaner and more general, but otherwise
has NFC.
llvm-svn: 296415
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native')
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp | 31 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/HashTable.cpp | 16 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/ModStream.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp | 5 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/StringTable.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp | 5 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp | 6 |
12 files changed, 39 insertions, 44 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp index 06c34325a57..6ad0c25f0ad 100644 --- a/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp @@ -236,7 +236,7 @@ Error DbiStream::initializeSectionContributionData() { return Error::success(); BinaryStreamReader SCReader(SecContrSubstream); - if (auto EC = SCReader.readEnum(SectionContribVersion, llvm::support::little)) + if (auto EC = SCReader.readEnum(SectionContribVersion)) return EC; if (SectionContribVersion == DbiSecContribVer60) diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp index f8d44320889..2dbdceb6571 100644 --- a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp @@ -153,7 +153,8 @@ Error DbiStreamBuilder::generateModiSubstream() { uint32_t Size = calculateModiSubstreamSize(); auto Data = Allocator.Allocate<uint8_t>(Size); - ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size)); + ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size), + llvm::support::little); BinaryStreamWriter ModiWriter(ModInfoBuffer); for (const auto &M : ModuleInfoList) { @@ -179,8 +180,8 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { auto Data = Allocator.Allocate<uint8_t>(Size); uint32_t NamesOffset = Size - NameSize; - FileInfoBuffer = - MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size)); + FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size), + llvm::support::little); WritableBinaryStreamRef MetadataBuffer = WritableBinaryStreamRef(FileInfoBuffer).keep_front(NamesOffset); @@ -188,21 +189,17 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModuleInfos.size()); uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size()); - if (auto EC = MetadataWriter.writeInteger( - ModiCount, llvm::support::little)) // NumModules + if (auto EC = MetadataWriter.writeInteger(ModiCount)) // NumModules return EC; - if (auto EC = MetadataWriter.writeInteger( - FileCount, llvm::support::little)) // NumSourceFiles + if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles return EC; for (uint16_t I = 0; I < ModiCount; ++I) { - if (auto EC = MetadataWriter.writeInteger( - I, llvm::support::little)) // Mod Indices + if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices return EC; } for (const auto MI : ModuleInfoList) { FileCount = static_cast<uint16_t>(MI->SourceFiles.size()); - if (auto EC = MetadataWriter.writeInteger( - FileCount, llvm::support::little)) // Mod File Counts + if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts return EC; } @@ -224,8 +221,7 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { if (Result == SourceFileNames.end()) return make_error<RawError>(raw_error_code::no_entry, "The source file was not found."); - if (auto EC = MetadataWriter.writeInteger(Result->second, - llvm::support::little)) + if (auto EC = MetadataWriter.writeInteger(Result->second)) return EC; } } @@ -379,7 +375,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; if (!SectionContribs.empty()) { - if (auto EC = Writer.writeEnum(DbiSecContribVer60, llvm::support::little)) + if (auto EC = Writer.writeEnum(DbiSecContribVer60)) return EC; if (auto EC = Writer.writeArray(SectionContribs)) return EC; @@ -398,16 +394,15 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; for (auto &Stream : DbgStreams) - if (auto EC = - Writer.writeInteger(Stream.StreamNumber, llvm::support::little)) + if (auto EC = Writer.writeInteger(Stream.StreamNumber)) return EC; for (auto &Stream : DbgStreams) { if (Stream.StreamNumber == kInvalidStreamIndex) continue; - auto WritableBinaryStream = WritableMappedBlockStream::createIndexedStream( + auto WritableStream = WritableMappedBlockStream::createIndexedStream( Layout, Buffer, Stream.StreamNumber); - BinaryStreamWriter DbgStreamWriter(*WritableBinaryStream); + BinaryStreamWriter DbgStreamWriter(*WritableStream); if (auto EC = DbgStreamWriter.writeArray(Stream.Data)) return EC; } diff --git a/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp b/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp index 535799706c8..ebf8c9c04db 100644 --- a/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp @@ -48,9 +48,9 @@ Error HashTable::load(BinaryStreamReader &Stream) { "Present bit vector interesects deleted!"); for (uint32_t P : Present) { - if (auto EC = Stream.readInteger(Buckets[P].first, llvm::support::little)) + if (auto EC = Stream.readInteger(Buckets[P].first)) return EC; - if (auto EC = Stream.readInteger(Buckets[P].second, llvm::support::little)) + if (auto EC = Stream.readInteger(Buckets[P].second)) return EC; } @@ -91,9 +91,9 @@ Error HashTable::commit(BinaryStreamWriter &Writer) const { return EC; for (const auto &Entry : *this) { - if (auto EC = Writer.writeInteger(Entry.first, llvm::support::little)) + if (auto EC = Writer.writeInteger(Entry.first)) return EC; - if (auto EC = Writer.writeInteger(Entry.second, llvm::support::little)) + if (auto EC = Writer.writeInteger(Entry.second)) return EC; } return Error::success(); @@ -212,7 +212,7 @@ void HashTable::grow() { Error HashTable::readSparseBitVector(BinaryStreamReader &Stream, SparseBitVector<> &V) { uint32_t NumWords; - if (auto EC = Stream.readInteger(NumWords, llvm::support::little)) + if (auto EC = Stream.readInteger(NumWords)) return joinErrors( std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, @@ -220,7 +220,7 @@ Error HashTable::readSparseBitVector(BinaryStreamReader &Stream, for (uint32_t I = 0; I != NumWords; ++I) { uint32_t Word; - if (auto EC = Stream.readInteger(Word, llvm::support::little)) + if (auto EC = Stream.readInteger(Word)) return joinErrors(std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, "Expected hash table word")); @@ -235,7 +235,7 @@ Error HashTable::writeSparseBitVector(BinaryStreamWriter &Writer, SparseBitVector<> &Vec) { int ReqBits = Vec.find_last() + 1; uint32_t NumWords = alignTo(ReqBits, sizeof(uint32_t)) / sizeof(uint32_t); - if (auto EC = Writer.writeInteger(NumWords, llvm::support::little)) + if (auto EC = Writer.writeInteger(NumWords)) return joinErrors( std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, @@ -248,7 +248,7 @@ Error HashTable::writeSparseBitVector(BinaryStreamWriter &Writer, if (Vec.test(Idx)) Word |= (1 << WordIdx); } - if (auto EC = Writer.writeInteger(Word, llvm::support::little)) + if (auto EC = Writer.writeInteger(Word)) return joinErrors(std::move(EC), make_error<RawError>( raw_error_code::corrupt_file, "Could not write linear map word")); diff --git a/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp b/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp index 0c2d2c32c6e..df9ec818a1d 100644 --- a/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp @@ -43,7 +43,7 @@ Error ModStream::reload() { BinaryStreamRef S; - if (auto EC = Reader.readInteger(Signature, llvm::support::little)) + if (auto EC = Reader.readInteger(Signature)) return EC; if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4)) return EC; @@ -58,7 +58,7 @@ Error ModStream::reload() { return EC; uint32_t GlobalRefsSize; - if (auto EC = Reader.readInteger(GlobalRefsSize, llvm::support::little)) + if (auto EC = Reader.readInteger(GlobalRefsSize)) return EC; if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) return EC; diff --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp index 91cbf4bca07..1fa9bc443ec 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp @@ -31,7 +31,7 @@ Error NamedStreamMap::load(BinaryStreamReader &Stream) { FinalizedInfo.reset(); uint32_t StringBufferSize; - if (auto EC = Stream.readInteger(StringBufferSize, llvm::support::little)) + if (auto EC = Stream.readInteger(StringBufferSize)) return joinErrors(std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, "Expected string buffer size")); @@ -70,8 +70,7 @@ Error NamedStreamMap::commit(BinaryStreamWriter &Writer) const { assert(FinalizedInfo.hasValue()); // The first field is the number of bytes of string data. - if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes, - llvm::support::little)) + if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes)) return EC; // Now all of the string data itself. diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp index 4c858253b79..dff53344545 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -45,7 +45,8 @@ Error NativeSession::createFromPdb(StringRef Path, return make_error<GenericError>(generic_error_code::invalid_path); std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); - auto Stream = llvm::make_unique<MemoryBufferByteStream>(std::move(Buffer)); + auto Stream = llvm::make_unique<MemoryBufferByteStream>( + std::move(Buffer), llvm::support::little); auto Allocator = llvm::make_unique<BumpPtrAllocator>(); auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator); diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp index a08ecd0487e..03257c40829 100644 --- a/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp @@ -186,7 +186,7 @@ Error PDBFile::parseStreamData() { // been parsed, we can avoid this and reuse MappedBlockStream. auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer); BinaryStreamReader Reader(*DS); - if (auto EC = Reader.readInteger(NumStreams, llvm::support::little)) + if (auto EC = Reader.readInteger(NumStreams)) return EC; if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams)) diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp index 104867d169b..18c0cdf03b8 100644 --- a/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp @@ -118,7 +118,8 @@ Error PDBFileBuilder::commit(StringRef Filename) { if (OutFileOrError.getError()) return llvm::make_error<pdb::GenericError>(generic_error_code::invalid_path, Filename); - FileBufferByteStream Buffer(std::move(*OutFileOrError)); + FileBufferByteStream Buffer(std::move(*OutFileOrError), + llvm::support::little); BinaryStreamWriter Writer(Buffer); if (auto EC = Writer.writeObject(*Layout.SB)) @@ -132,8 +133,7 @@ Error PDBFileBuilder::commit(StringRef Filename) { auto DirStream = WritableMappedBlockStream::createDirectoryStream(Layout, Buffer); BinaryStreamWriter DW(*DirStream); - if (auto EC = DW.writeInteger<uint32_t>(Layout.StreamSizes.size(), - llvm::support::little)) + if (auto EC = DW.writeInteger<uint32_t>(Layout.StreamSizes.size())) return EC; if (auto EC = DW.writeArray(Layout.StreamSizes)) diff --git a/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp b/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp index e2b9ea20812..79a78c92598 100644 --- a/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp @@ -54,7 +54,7 @@ Error StringTable::load(BinaryStreamReader &Stream) { return make_error<RawError>(raw_error_code::corrupt_file, "Missing name count"); - if (auto EC = Stream.readInteger(NameCount, llvm::support::little)) + if (auto EC = Stream.readInteger(NameCount)) return EC; return Error::success(); } diff --git a/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp index 5432fe4b99e..9df97c9753e 100644 --- a/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp @@ -74,7 +74,7 @@ Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const { // Write a hash table. uint32_t BucketCount = computeBucketCount(Strings.size()); - if (auto EC = Writer.writeInteger(BucketCount, llvm::support::little)) + if (auto EC = Writer.writeInteger(BucketCount)) return EC; std::vector<ulittle32_t> Buckets(BucketCount); @@ -96,8 +96,7 @@ Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const { if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets))) return EC; - if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size()), - llvm::support::little)) + if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size()))) return EC; return Error::success(); } diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp index 2d351b05b0b..d38edcb88b8 100644 --- a/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp @@ -16,7 +16,6 @@ #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" - #include "llvm/Support/Endian.h" using namespace llvm; diff --git a/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp index 49412b1f95a..7d532ee56d8 100644 --- a/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp @@ -34,7 +34,8 @@ using namespace llvm::pdb; using namespace llvm::support; TpiStreamBuilder::TpiStreamBuilder(MSFBuilder &Msf, uint32_t StreamIdx) - : Msf(Msf), Allocator(Msf.getAllocator()), Header(nullptr), Idx(StreamIdx) { + : Msf(Msf), Allocator(Msf.getAllocator()), + TypeRecordStream(llvm::support::little), Header(nullptr), Idx(StreamIdx) { } TpiStreamBuilder::~TpiStreamBuilder() = default; @@ -113,7 +114,8 @@ Error TpiStreamBuilder::finalizeMsfLayout() { } ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(HashBuffer.data()), HashBufferSize); - HashValueStream = llvm::make_unique<BinaryByteStream>(Bytes); + HashValueStream = + llvm::make_unique<BinaryByteStream>(Bytes, llvm::support::little); return Error::success(); } |

