From 980cadce138cc5b4bb0b9b594177d62ab08777cc Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sat, 18 Feb 2017 01:35:33 +0000 Subject: [PATCH] Don't assume little endian in StreamReader / StreamWriter. In an effort to generalize this so it can be used by more than just PDB code, we shouldn't assume little endian. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295525 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../DebugInfo/CodeView/CodeViewRecordIO.h | 8 +-- .../llvm/DebugInfo/CodeView/TypeSerializer.h | 2 +- include/llvm/DebugInfo/MSF/StreamReader.h | 38 ++++++++--- include/llvm/DebugInfo/MSF/StreamWriter.h | 38 +++++++---- lib/DebugInfo/CodeView/CVTypeVisitor.cpp | 2 +- lib/DebugInfo/CodeView/CodeViewRecordIO.cpp | 44 +++++++------ .../CodeView/RecordSerialization.cpp | 20 +++--- lib/DebugInfo/CodeView/TypeSerializer.cpp | 8 +-- lib/DebugInfo/MSF/StreamReader.cpp | 64 ------------------- lib/DebugInfo/MSF/StreamWriter.cpp | 28 -------- lib/DebugInfo/PDB/Native/DbiStream.cpp | 2 +- lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp | 20 ++++-- lib/DebugInfo/PDB/Native/HashTable.cpp | 16 ++--- lib/DebugInfo/PDB/Native/ModStream.cpp | 4 +- lib/DebugInfo/PDB/Native/NamedStreamMap.cpp | 6 +- lib/DebugInfo/PDB/Native/PDBFile.cpp | 2 +- lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp | 4 +- lib/DebugInfo/PDB/Native/StringTable.cpp | 2 +- .../PDB/Native/StringTableBuilder.cpp | 5 +- tools/llvm-readobj/COFFDumper.cpp | 6 +- .../DebugInfo/PDB/MappedBlockStreamTest.cpp | 12 ++-- 21 files changed, 144 insertions(+), 187 deletions(-) diff --git a/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h b/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h index 5a036b9d5b6..292f43ff79d 100644 --- a/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h +++ b/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h @@ -59,9 +59,9 @@ public: template Error mapInteger(T &Value) { if (isWriting()) - return Writer->writeInteger(Value); + return Writer->writeInteger(Value, llvm::support::little); - return Reader->readInteger(Value); + return Reader->readInteger(Value, llvm::support::little); } template Error mapEnum(T &Value) { @@ -93,7 +93,7 @@ public: SizeType Size; if (isWriting()) { Size = static_cast(Items.size()); - if (auto EC = Writer->writeInteger(Size)) + if (auto EC = Writer->writeInteger(Size, llvm::support::little)) return EC; for (auto &X : Items) { @@ -101,7 +101,7 @@ public: return EC; } } else { - if (auto EC = Reader->readInteger(Size)) + if (auto EC = Reader->readInteger(Size, llvm::support::little)) return EC; for (SizeType I = 0; I < Size; ++I) { typename T::value_type Item; diff --git a/include/llvm/DebugInfo/CodeView/TypeSerializer.h b/include/llvm/DebugInfo/CodeView/TypeSerializer.h index e0592219463..f1bfffea23b 100644 --- a/include/llvm/DebugInfo/CodeView/TypeSerializer.h +++ b/include/llvm/DebugInfo/CodeView/TypeSerializer.h @@ -109,7 +109,7 @@ private: Error visitKnownMemberImpl(CVMemberRecord &CVR, RecordType &Record) { assert(CVR.Kind == static_cast(Record.getKind())); - if (auto EC = Writer.writeEnum(CVR.Kind)) + if (auto EC = Writer.writeEnum(CVR.Kind, llvm::support::little)) return EC; if (auto EC = Mapping.visitKnownMember(CVR, Record)) diff --git a/include/llvm/DebugInfo/MSF/StreamReader.h b/include/llvm/DebugInfo/MSF/StreamReader.h index fc2ca78dc18..01261226c2a 100644 --- a/include/llvm/DebugInfo/MSF/StreamReader.h +++ b/include/llvm/DebugInfo/MSF/StreamReader.h @@ -29,28 +29,42 @@ public: Error readLongestContiguousChunk(ArrayRef &Buffer); Error readBytes(ArrayRef &Buffer, uint32_t Size); - Error readInteger(uint8_t &Dest); - Error readInteger(uint16_t &Dest); - Error readInteger(uint32_t &Dest); - Error readInteger(uint64_t &Dest); - Error readInteger(int8_t &Dest); - Error readInteger(int16_t &Dest); - Error readInteger(int32_t &Dest); - Error readInteger(int64_t &Dest); + + template + Error readInteger(T &Dest, + llvm::support::endianness Endian = llvm::support::native) { + static_assert(std::is_integral::value, + "Cannot call readInteger with non-integral value!"); + + ArrayRef Bytes; + if (auto EC = readBytes(Bytes, sizeof(T))) + return EC; + + Dest = llvm::support::endian::read( + Bytes.data(), Endian); + return Error::success(); + } + Error readZeroString(StringRef &Dest); Error readFixedString(StringRef &Dest, uint32_t Length); Error readStreamRef(ReadableStreamRef &Ref); Error readStreamRef(ReadableStreamRef &Ref, uint32_t Length); - template Error readEnum(T &Dest) { + template + Error readEnum(T &Dest, + llvm::support::endianness Endian = llvm::support::native) { + static_assert(std::is_enum::value, + "Cannot call readEnum with non-enum value!"); typename std::underlying_type::type N; - if (auto EC = readInteger(N)) + if (auto EC = readInteger(N, Endian)) return EC; Dest = static_cast(N); return Error::success(); } template Error readObject(const T *&Dest) { + static_assert(std::is_trivially_copyable::value, + "Can only read trivially copyable object types!"); ArrayRef Buffer; if (auto EC = readBytes(Buffer, sizeof(T))) return EC; @@ -60,6 +74,8 @@ public: template Error readArray(ArrayRef &Array, uint32_t NumElements) { + static_assert(std::is_trivially_copyable::value, + "Can only read trivially copyable object types!"); ArrayRef Bytes; if (NumElements == 0) { Array = ArrayRef(); @@ -86,6 +102,8 @@ public: template Error readArray(FixedStreamArray &Array, uint32_t NumItems) { + static_assert(std::is_trivially_copyable::value, + "Can only read trivially copyable object types!"); if (NumItems == 0) { Array = FixedStreamArray(); return Error::success(); diff --git a/include/llvm/DebugInfo/MSF/StreamWriter.h b/include/llvm/DebugInfo/MSF/StreamWriter.h index 2bb14434dd8..87af18f0206 100644 --- a/include/llvm/DebugInfo/MSF/StreamWriter.h +++ b/include/llvm/DebugInfo/MSF/StreamWriter.h @@ -15,6 +15,7 @@ #include "llvm/DebugInfo/MSF/MSFError.h" #include "llvm/DebugInfo/MSF/StreamArray.h" #include "llvm/DebugInfo/MSF/StreamRef.h" +#include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" #include #include @@ -28,22 +29,31 @@ public: explicit StreamWriter(WritableStreamRef Stream); Error writeBytes(ArrayRef Buffer); - Error writeInteger(uint8_t Int); - Error writeInteger(uint16_t Dest); - Error writeInteger(uint32_t Dest); - Error writeInteger(uint64_t Dest); - Error writeInteger(int8_t Int); - Error writeInteger(int16_t Dest); - Error writeInteger(int32_t Dest); - Error writeInteger(int64_t Dest); + + template + Error writeInteger(T Value, + llvm::support::endianness Endian = llvm::support::native) { + static_assert(std::is_integral::value, + "Cannot call writeInteger with non-integral value!"); + uint8_t Buffer[sizeof(T)]; + llvm::support::endian::write(Buffer, Value, + Endian); + return writeBytes(Buffer); + } + Error writeZeroString(StringRef Str); Error writeFixedString(StringRef Str); Error writeStreamRef(ReadableStreamRef Ref); Error writeStreamRef(ReadableStreamRef Ref, uint32_t Size); - template Error writeEnum(T Num) { - return writeInteger( - static_cast::type>(Num)); + template + Error writeEnum(T Num, + llvm::support::endianness Endian = llvm::support::native) { + static_assert(std::is_enum::value, + "Cannot call writeEnum with non-Enum type"); + + using U = typename std::underlying_type::type; + return writeInteger(static_cast(Num), Endian); } template Error writeObject(const T &Obj) { @@ -51,11 +61,15 @@ public: "writeObject should not be used with pointers, to write " "the pointed-to value dereference the pointer before calling " "writeObject"); + static_assert(std::is_trivially_copyable::value, + "Can only serialize trivially copyable object types"); return writeBytes( ArrayRef(reinterpret_cast(&Obj), sizeof(T))); } template Error writeArray(ArrayRef Array) { + static_assert(std::is_trivially_copyable::value, + "Can only serialize trivially copyable object types"); if (Array.empty()) return Error::success(); @@ -73,6 +87,8 @@ public: } template Error writeArray(FixedStreamArray Array) { + static_assert(std::is_trivially_copyable::value, + "Can only serialize trivially copyable object types"); return writeStreamRef(Array.getUnderlyingStream()); } diff --git a/lib/DebugInfo/CodeView/CVTypeVisitor.cpp b/lib/DebugInfo/CodeView/CVTypeVisitor.cpp index 48160252c6d..db5db3eeded 100644 --- a/lib/DebugInfo/CodeView/CVTypeVisitor.cpp +++ b/lib/DebugInfo/CodeView/CVTypeVisitor.cpp @@ -182,7 +182,7 @@ Error CVTypeVisitor::visitFieldListMemberStream(msf::StreamReader Reader) { TypeLeafKind Leaf; while (!Reader.empty()) { - if (auto EC = Reader.readEnum(Leaf)) + if (auto EC = Reader.readEnum(Leaf, llvm::support::little)) return EC; CVMemberRecord Record; diff --git a/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp b/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp index 9bd85cf9dc6..b7e74a1f455 100644 --- a/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp +++ b/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp @@ -87,13 +87,14 @@ Error CodeViewRecordIO::mapByteVectorTail(std::vector &Bytes) { Error CodeViewRecordIO::mapInteger(TypeIndex &TypeInd) { if (isWriting()) { - if (auto EC = Writer->writeInteger(TypeInd.getIndex())) + if (auto EC = + Writer->writeInteger(TypeInd.getIndex(), llvm::support::little)) return EC; return Error::success(); } uint32_t I; - if (auto EC = Reader->readInteger(I)) + if (auto EC = Reader->readInteger(I, llvm::support::little)) return EC; TypeInd.setIndex(I); return Error::success(); @@ -176,7 +177,7 @@ Error CodeViewRecordIO::mapStringZVectorZ(std::vector &Value) { if (auto EC = mapStringZ(V)) return EC; } - if (auto EC = Writer->writeInteger(uint8_t(0))) + if (auto EC = Writer->writeInteger(0, llvm::support::little)) return EC; } else { StringRef S; @@ -194,24 +195,28 @@ Error CodeViewRecordIO::mapStringZVectorZ(std::vector &Value) { Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) { assert(Value < 0 && "Encoded integer is not signed!"); if (Value >= std::numeric_limits::min()) { - if (auto EC = Writer->writeInteger(static_cast(LF_CHAR))) + if (auto EC = + Writer->writeInteger(LF_CHAR, llvm::support::little)) return EC; - if (auto EC = Writer->writeInteger(static_cast(Value))) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } else if (Value >= std::numeric_limits::min()) { - if (auto EC = Writer->writeInteger(static_cast(LF_SHORT))) + if (auto EC = + Writer->writeInteger(LF_SHORT, llvm::support::little)) return EC; - if (auto EC = Writer->writeInteger(static_cast(Value))) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } else if (Value >= std::numeric_limits::min()) { - if (auto EC = Writer->writeInteger(static_cast(LF_LONG))) + if (auto EC = + Writer->writeInteger(LF_LONG, llvm::support::little)) return EC; - if (auto EC = Writer->writeInteger(static_cast(Value))) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } else { - if (auto EC = Writer->writeInteger(static_cast(LF_QUADWORD))) + if (auto EC = + Writer->writeInteger(LF_QUADWORD, llvm::support::little)) return EC; - if (auto EC = Writer->writeInteger(Value)) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } return Error::success(); @@ -219,22 +224,25 @@ Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) { Error CodeViewRecordIO::writeEncodedUnsignedInteger(const uint64_t &Value) { if (Value < LF_NUMERIC) { - if (auto EC = Writer->writeInteger(static_cast(Value))) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } else if (Value <= std::numeric_limits::max()) { - if (auto EC = Writer->writeInteger(static_cast(LF_USHORT))) + if (auto EC = + Writer->writeInteger(LF_USHORT, llvm::support::little)) return EC; - if (auto EC = Writer->writeInteger(static_cast(Value))) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } else if (Value <= std::numeric_limits::max()) { - if (auto EC = Writer->writeInteger(static_cast(LF_ULONG))) + if (auto EC = + Writer->writeInteger(LF_ULONG, llvm::support::little)) return EC; - if (auto EC = Writer->writeInteger(static_cast(Value))) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } else { - if (auto EC = Writer->writeInteger(static_cast(LF_UQUADWORD))) + if (auto EC = + Writer->writeInteger(LF_UQUADWORD, llvm::support::little)) return EC; - if (auto EC = Writer->writeInteger(Value)) + if (auto EC = Writer->writeInteger(Value, llvm::support::little)) return EC; } diff --git a/lib/DebugInfo/CodeView/RecordSerialization.cpp b/lib/DebugInfo/CodeView/RecordSerialization.cpp index 6f29caa9bbf..6be9a059b89 100644 --- a/lib/DebugInfo/CodeView/RecordSerialization.cpp +++ b/lib/DebugInfo/CodeView/RecordSerialization.cpp @@ -37,7 +37,7 @@ Error llvm::codeview::consume(msf::StreamReader &Reader, APSInt &Num) { // Used to avoid overload ambiguity on APInt construtor. bool FalseVal = false; uint16_t Short; - if (auto EC = Reader.readInteger(Short)) + if (auto EC = Reader.readInteger(Short, llvm::support::little)) return EC; if (Short < LF_NUMERIC) { @@ -49,49 +49,49 @@ Error llvm::codeview::consume(msf::StreamReader &Reader, APSInt &Num) { switch (Short) { case LF_CHAR: { int8_t N; - if (auto EC = Reader.readInteger(N)) + if (auto EC = Reader.readInteger(N, llvm::support::little)) return EC; Num = APSInt(APInt(8, N, true), false); return Error::success(); } case LF_SHORT: { int16_t N; - if (auto EC = Reader.readInteger(N)) + if (auto EC = Reader.readInteger(N, llvm::support::little)) return EC; Num = APSInt(APInt(16, N, true), false); return Error::success(); } case LF_USHORT: { uint16_t N; - if (auto EC = Reader.readInteger(N)) + if (auto EC = Reader.readInteger(N, llvm::support::little)) return EC; Num = APSInt(APInt(16, N, false), true); return Error::success(); } case LF_LONG: { int32_t N; - if (auto EC = Reader.readInteger(N)) + if (auto EC = Reader.readInteger(N, llvm::support::little)) return EC; Num = APSInt(APInt(32, N, true), false); return Error::success(); } case LF_ULONG: { uint32_t N; - if (auto EC = Reader.readInteger(N)) + if (auto EC = Reader.readInteger(N, llvm::support::little)) return EC; Num = APSInt(APInt(32, N, FalseVal), true); return Error::success(); } case LF_QUADWORD: { int64_t N; - if (auto EC = Reader.readInteger(N)) + if (auto EC = Reader.readInteger(N, llvm::support::little)) return EC; Num = APSInt(APInt(64, N, true), false); return Error::success(); } case LF_UQUADWORD: { uint64_t N; - if (auto EC = Reader.readInteger(N)) + if (auto EC = Reader.readInteger(N, llvm::support::little)) return EC; Num = APSInt(APInt(64, N, false), true); return Error::success(); @@ -124,7 +124,7 @@ Error llvm::codeview::consume_numeric(msf::StreamReader &Reader, } Error llvm::codeview::consume(msf::StreamReader &Reader, uint32_t &Item) { - return Reader.readInteger(Item); + return Reader.readInteger(Item, llvm::support::little); } Error llvm::codeview::consume(StringRef &Data, uint32_t &Item) { @@ -137,7 +137,7 @@ Error llvm::codeview::consume(StringRef &Data, uint32_t &Item) { } Error llvm::codeview::consume(msf::StreamReader &Reader, int32_t &Item) { - return Reader.readInteger(Item); + return Reader.readInteger(Item, llvm::support::little); } Error llvm::codeview::consume(msf::StreamReader &Reader, StringRef &Item) { diff --git a/lib/DebugInfo/CodeView/TypeSerializer.cpp b/lib/DebugInfo/CodeView/TypeSerializer.cpp index f24fcff8627..299e9ad6930 100644 --- a/lib/DebugInfo/CodeView/TypeSerializer.cpp +++ b/lib/DebugInfo/CodeView/TypeSerializer.cpp @@ -76,7 +76,7 @@ TypeSerializer::addPadding(MutableArrayRef Record) { int N = PaddingBytes; while (PaddingBytes > 0) { uint8_t Pad = static_cast(LF_PAD0 + PaddingBytes); - if (auto EC = Writer.writeInteger(Pad)) + if (auto EC = Writer.writeInteger(Pad, llvm::support::little)) return std::move(EC); --PaddingBytes; } @@ -207,11 +207,11 @@ Error TypeSerializer::visitMemberEnd(CVMemberRecord &Record) { msf::StreamWriter CW(CS); if (auto EC = CW.writeBytes(CopyData)) return EC; - if (auto EC = CW.writeEnum(TypeLeafKind::LF_INDEX)) + if (auto EC = CW.writeEnum(TypeLeafKind::LF_INDEX, llvm::support::little)) return EC; - if (auto EC = CW.writeInteger(uint16_t(0))) + if (auto EC = CW.writeInteger(0, llvm::support::little)) return EC; - if (auto EC = CW.writeInteger(uint32_t(0xB0C0B0C0))) + if (auto EC = CW.writeInteger(0xB0C0B0C0, llvm::support::little)) return EC; FieldListSegments.push_back(SavedSegment); diff --git a/lib/DebugInfo/MSF/StreamReader.cpp b/lib/DebugInfo/MSF/StreamReader.cpp index b85fd14a3b7..d460a4eeab3 100644 --- a/lib/DebugInfo/MSF/StreamReader.cpp +++ b/lib/DebugInfo/MSF/StreamReader.cpp @@ -31,70 +31,6 @@ Error StreamReader::readBytes(ArrayRef &Buffer, uint32_t Size) { return Error::success(); } -Error StreamReader::readInteger(uint8_t &Dest) { - const uint8_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - -Error StreamReader::readInteger(uint16_t &Dest) { - const support::ulittle16_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - -Error StreamReader::readInteger(uint32_t &Dest) { - const support::ulittle32_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - -Error StreamReader::readInteger(uint64_t &Dest) { - const support::ulittle64_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - -Error StreamReader::readInteger(int8_t &Dest) { - const int8_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - -Error StreamReader::readInteger(int16_t &Dest) { - const support::little16_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - -Error StreamReader::readInteger(int32_t &Dest) { - const support::little32_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - -Error StreamReader::readInteger(int64_t &Dest) { - const support::little64_t *P; - if (auto EC = readObject(P)) - return EC; - Dest = *P; - return Error::success(); -} - Error StreamReader::readZeroString(StringRef &Dest) { uint32_t Length = 0; // First compute the length of the string by reading 1 byte at a time. diff --git a/lib/DebugInfo/MSF/StreamWriter.cpp b/lib/DebugInfo/MSF/StreamWriter.cpp index cdae7c5acc0..a24fb047e60 100644 --- a/lib/DebugInfo/MSF/StreamWriter.cpp +++ b/lib/DebugInfo/MSF/StreamWriter.cpp @@ -25,34 +25,6 @@ Error StreamWriter::writeBytes(ArrayRef Buffer) { return Error::success(); } -Error StreamWriter::writeInteger(uint8_t Int) { return writeObject(Int); } - -Error StreamWriter::writeInteger(uint16_t Int) { - return writeObject(support::ulittle16_t(Int)); -} - -Error StreamWriter::writeInteger(uint32_t Int) { - return writeObject(support::ulittle32_t(Int)); -} - -Error StreamWriter::writeInteger(uint64_t Int) { - return writeObject(support::ulittle64_t(Int)); -} - -Error StreamWriter::writeInteger(int8_t Int) { return writeObject(Int); } - -Error StreamWriter::writeInteger(int16_t Int) { - return writeObject(support::little16_t(Int)); -} - -Error StreamWriter::writeInteger(int32_t Int) { - return writeObject(support::little32_t(Int)); -} - -Error StreamWriter::writeInteger(int64_t Int) { - return writeObject(support::little64_t(Int)); -} - Error StreamWriter::writeZeroString(StringRef Str) { if (auto EC = writeFixedString(Str)) return EC; diff --git a/lib/DebugInfo/PDB/Native/DbiStream.cpp b/lib/DebugInfo/PDB/Native/DbiStream.cpp index 5d15e62d3e4..f2f25c2bfeb 100644 --- a/lib/DebugInfo/PDB/Native/DbiStream.cpp +++ b/lib/DebugInfo/PDB/Native/DbiStream.cpp @@ -236,7 +236,7 @@ Error DbiStream::initializeSectionContributionData() { return Error::success(); StreamReader SCReader(SecContrSubstream); - if (auto EC = SCReader.readEnum(SectionContribVersion)) + if (auto EC = SCReader.readEnum(SectionContribVersion, llvm::support::little)) return EC; if (SectionContribVersion == DbiSecContribVer60) diff --git a/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp index df6e9b060df..0b56d05b468 100644 --- a/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp @@ -187,17 +187,21 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { uint16_t ModiCount = std::min(UINT16_MAX, ModuleInfos.size()); uint16_t FileCount = std::min(UINT16_MAX, SourceFileNames.size()); - if (auto EC = MetadataWriter.writeInteger(ModiCount)) // NumModules + if (auto EC = MetadataWriter.writeInteger( + ModiCount, llvm::support::little)) // NumModules return EC; - if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles + if (auto EC = MetadataWriter.writeInteger( + FileCount, llvm::support::little)) // NumSourceFiles return EC; for (uint16_t I = 0; I < ModiCount; ++I) { - if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices + if (auto EC = MetadataWriter.writeInteger( + I, llvm::support::little)) // Mod Indices return EC; } for (const auto MI : ModuleInfoList) { FileCount = static_cast(MI->SourceFiles.size()); - if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts + if (auto EC = MetadataWriter.writeInteger( + FileCount, llvm::support::little)) // Mod File Counts return EC; } @@ -219,7 +223,8 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { if (Result == SourceFileNames.end()) return make_error(raw_error_code::no_entry, "The source file was not found."); - if (auto EC = MetadataWriter.writeInteger(Result->second)) + if (auto EC = MetadataWriter.writeInteger(Result->second, + llvm::support::little)) return EC; } } @@ -373,7 +378,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; if (!SectionContribs.empty()) { - if (auto EC = Writer.writeEnum(DbiSecContribVer60)) + if (auto EC = Writer.writeEnum(DbiSecContribVer60, llvm::support::little)) return EC; if (auto EC = Writer.writeArray(SectionContribs)) return EC; @@ -392,7 +397,8 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; for (auto &Stream : DbgStreams) - if (auto EC = Writer.writeInteger(Stream.StreamNumber)) + if (auto EC = + Writer.writeInteger(Stream.StreamNumber, llvm::support::little)) return EC; for (auto &Stream : DbgStreams) { diff --git a/lib/DebugInfo/PDB/Native/HashTable.cpp b/lib/DebugInfo/PDB/Native/HashTable.cpp index b3fe6fa45c5..dd95c078d7e 100644 --- a/lib/DebugInfo/PDB/Native/HashTable.cpp +++ b/lib/DebugInfo/PDB/Native/HashTable.cpp @@ -48,9 +48,9 @@ Error HashTable::load(msf::StreamReader &Stream) { "Present bit vector interesects deleted!"); for (uint32_t P : Present) { - if (auto EC = Stream.readInteger(Buckets[P].first)) + if (auto EC = Stream.readInteger(Buckets[P].first, llvm::support::little)) return EC; - if (auto EC = Stream.readInteger(Buckets[P].second)) + if (auto EC = Stream.readInteger(Buckets[P].second, llvm::support::little)) return EC; } @@ -91,9 +91,9 @@ Error HashTable::commit(msf::StreamWriter &Writer) const { return EC; for (const auto &Entry : *this) { - if (auto EC = Writer.writeInteger(Entry.first)) + if (auto EC = Writer.writeInteger(Entry.first, llvm::support::little)) return EC; - if (auto EC = Writer.writeInteger(Entry.second)) + if (auto EC = Writer.writeInteger(Entry.second, llvm::support::little)) return EC; } return Error::success(); @@ -212,7 +212,7 @@ void HashTable::grow() { Error HashTable::readSparseBitVector(msf::StreamReader &Stream, SparseBitVector<> &V) { uint32_t NumWords; - if (auto EC = Stream.readInteger(NumWords)) + if (auto EC = Stream.readInteger(NumWords, llvm::support::little)) return joinErrors( std::move(EC), make_error(raw_error_code::corrupt_file, @@ -220,7 +220,7 @@ Error HashTable::readSparseBitVector(msf::StreamReader &Stream, for (uint32_t I = 0; I != NumWords; ++I) { uint32_t Word; - if (auto EC = Stream.readInteger(Word)) + if (auto EC = Stream.readInteger(Word, llvm::support::little)) return joinErrors(std::move(EC), make_error(raw_error_code::corrupt_file, "Expected hash table word")); @@ -235,7 +235,7 @@ Error HashTable::writeSparseBitVector(msf::StreamWriter &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)) + if (auto EC = Writer.writeInteger(NumWords, llvm::support::little)) return joinErrors( std::move(EC), make_error(raw_error_code::corrupt_file, @@ -248,7 +248,7 @@ Error HashTable::writeSparseBitVector(msf::StreamWriter &Writer, if (Vec.test(Idx)) Word |= (1 << WordIdx); } - if (auto EC = Writer.writeInteger(Word)) + if (auto EC = Writer.writeInteger(Word, llvm::support::little)) return joinErrors(std::move(EC), make_error( raw_error_code::corrupt_file, "Could not write linear map word")); diff --git a/lib/DebugInfo/PDB/Native/ModStream.cpp b/lib/DebugInfo/PDB/Native/ModStream.cpp index 25370f26ec3..ee8374ff120 100644 --- a/lib/DebugInfo/PDB/Native/ModStream.cpp +++ b/lib/DebugInfo/PDB/Native/ModStream.cpp @@ -43,7 +43,7 @@ Error ModStream::reload() { ReadableStreamRef S; - if (auto EC = Reader.readInteger(Signature)) + if (auto EC = Reader.readInteger(Signature, llvm::support::little)) 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)) + if (auto EC = Reader.readInteger(GlobalRefsSize, llvm::support::little)) return EC; if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) return EC; diff --git a/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp index 47fd0e1ba24..8a9579ca385 100644 --- a/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp +++ b/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp @@ -32,7 +32,7 @@ Error NamedStreamMap::load(StreamReader &Stream) { FinalizedInfo.reset(); uint32_t StringBufferSize; - if (auto EC = Stream.readInteger(StringBufferSize)) + if (auto EC = Stream.readInteger(StringBufferSize, llvm::support::little)) return joinErrors(std::move(EC), make_error(raw_error_code::corrupt_file, "Expected string buffer size")); @@ -71,8 +71,8 @@ Error NamedStreamMap::commit(msf::StreamWriter &Writer) const { assert(FinalizedInfo.hasValue()); // The first field is the number of bytes of string data. - if (auto EC = Writer.writeInteger( - FinalizedInfo->StringDataBytes)) // Number of bytes of string data + if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes, + llvm::support::little)) return EC; // Now all of the string data itself. diff --git a/lib/DebugInfo/PDB/Native/PDBFile.cpp b/lib/DebugInfo/PDB/Native/PDBFile.cpp index 3a3692dcac5..26d9e0ee9e9 100644 --- a/lib/DebugInfo/PDB/Native/PDBFile.cpp +++ b/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); StreamReader Reader(*DS); - if (auto EC = Reader.readInteger(NumStreams)) + if (auto EC = Reader.readInteger(NumStreams, llvm::support::little)) return EC; if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams)) diff --git a/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp b/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp index 57ca2ba488a..fb8e34e7e82 100644 --- a/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp @@ -132,8 +132,8 @@ Error PDBFileBuilder::commit(StringRef Filename) { auto DirStream = WritableMappedBlockStream::createDirectoryStream(Layout, Buffer); StreamWriter DW(*DirStream); - if (auto EC = - DW.writeInteger(static_cast(Layout.StreamSizes.size()))) + if (auto EC = DW.writeInteger(Layout.StreamSizes.size(), + llvm::support::little)) return EC; if (auto EC = DW.writeArray(Layout.StreamSizes)) diff --git a/lib/DebugInfo/PDB/Native/StringTable.cpp b/lib/DebugInfo/PDB/Native/StringTable.cpp index 5b8ae9b7e9c..34f2b480260 100644 --- a/lib/DebugInfo/PDB/Native/StringTable.cpp +++ b/lib/DebugInfo/PDB/Native/StringTable.cpp @@ -55,7 +55,7 @@ Error StringTable::load(StreamReader &Stream) { return make_error(raw_error_code::corrupt_file, "Missing name count"); - if (auto EC = Stream.readInteger(NameCount)) + if (auto EC = Stream.readInteger(NameCount, llvm::support::little)) return EC; return Error::success(); } diff --git a/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp b/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp index ef9caee4cd6..304f3a6ed11 100644 --- a/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp +++ b/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp @@ -74,7 +74,7 @@ Error StringTableBuilder::commit(msf::StreamWriter &Writer) const { // Write a hash table. uint32_t BucketCount = computeBucketCount(Strings.size()); - if (auto EC = Writer.writeInteger(BucketCount)) + if (auto EC = Writer.writeInteger(BucketCount, llvm::support::little)) return EC; std::vector Buckets(BucketCount); @@ -96,7 +96,8 @@ Error StringTableBuilder::commit(msf::StreamWriter &Writer) const { if (auto EC = Writer.writeArray(ArrayRef(Buckets))) return EC; - if (auto EC = Writer.writeInteger(static_cast(Strings.size()))) + if (auto EC = Writer.writeInteger(static_cast(Strings.size()), + llvm::support::little)) return EC; return Error::success(); } diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index a0274c0ad95..d089206e1fa 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -1015,7 +1015,7 @@ void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) { msf::ByteStream S(Subsection); msf::StreamReader SR(S); uint32_t Signature; - error(SR.readInteger(Signature)); + error(SR.readInteger(Signature, llvm::support::little)); bool HasExtraFiles = Signature == unsigned(InlineeLinesSignature::ExtraFiles); while (!SR.empty()) { @@ -1028,12 +1028,12 @@ void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) { if (HasExtraFiles) { uint32_t ExtraFileCount; - error(SR.readInteger(ExtraFileCount)); + error(SR.readInteger(ExtraFileCount, llvm::support::little)); W.printNumber("ExtraFileCount", ExtraFileCount); ListScope ExtraFiles(W, "ExtraFiles"); for (unsigned I = 0; I < ExtraFileCount; ++I) { uint32_t FileID; - error(SR.readInteger(FileID)); + error(SR.readInteger(FileID, llvm::support::little)); printFileNameForOffset("FileID", FileID); } } diff --git a/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp b/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp index 07591ca69d3..4593f3c6716 100644 --- a/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp +++ b/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp @@ -325,8 +325,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) { StreamReader Reader(*S); StreamWriter Writer(*S); - EXPECT_NO_ERROR(Writer.writeInteger(u16[0])); - EXPECT_NO_ERROR(Reader.readInteger(u16[1])); + EXPECT_NO_ERROR(Writer.writeInteger(u16[0], llvm::support::little)); + EXPECT_NO_ERROR(Reader.readInteger(u16[1], llvm::support::little)); EXPECT_EQ(u16[0], u16[1]); EXPECT_EQ(std::vector({0, 0x7A, 0xEC, 0, 0, 0, 0, 0, 0, 0}), DataBytes); @@ -334,8 +334,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) { Reader.setOffset(0); Writer.setOffset(0); ::memset(DataBytes.data(), 0, 10); - EXPECT_NO_ERROR(Writer.writeInteger(u32[0])); - EXPECT_NO_ERROR(Reader.readInteger(u32[1])); + EXPECT_NO_ERROR(Writer.writeInteger(u32[0], llvm::support::little)); + EXPECT_NO_ERROR(Reader.readInteger(u32[1], llvm::support::little)); EXPECT_EQ(u32[0], u32[1]); EXPECT_EQ(std::vector({0x17, 0x5C, 0x50, 0, 0, 0, 0x35, 0, 0, 0}), DataBytes); @@ -343,8 +343,8 @@ TEST(MappedBlockStreamTest, TestWriteThenRead) { Reader.setOffset(0); Writer.setOffset(0); ::memset(DataBytes.data(), 0, 10); - EXPECT_NO_ERROR(Writer.writeEnum(Enum[0])); - EXPECT_NO_ERROR(Reader.readEnum(Enum[1])); + EXPECT_NO_ERROR(Writer.writeEnum(Enum[0], llvm::support::little)); + EXPECT_NO_ERROR(Reader.readEnum(Enum[1], llvm::support::little)); EXPECT_EQ(Enum[0], Enum[1]); EXPECT_EQ(std::vector({0x2C, 0x60, 0x4A, 0, 0, 0, 0, 0, 0, 0}), DataBytes); -- 2.40.0