[Support] Convert BinaryStream class zoo to 64-bit offsets

Most PDB fields on disk are 32-bit but describe the file in terms of MSF
blocks, which are 4 kiB by default.

So PDB files can be a bit larger than 4 GiB, and much larger if you create them
with a block size > 4 kiB.

This is a first (necessary, but by far not not sufficient) step towards
supporting such PDB files.  Now we don't truncate in-memory file offsets (which
are in terms of bytes, not in terms of blocks).

No effective behavior change. lld-link will still error out if it were to
produce PDBs > 4 GiB.

Differential Revision: https://reviews.llvm.org/D109923
This commit is contained in:
Nico Weber 2021-09-16 19:14:52 -04:00
parent d9195d6603
commit 646299d183
16 changed files with 204 additions and 205 deletions

View File

@ -58,12 +58,12 @@ public:
return support::little;
}
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override;
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override;
uint32_t getLength() override;
uint64_t getLength() override;
BumpPtrAllocator &getAllocator() { return Allocator; }
@ -79,10 +79,10 @@ protected:
private:
const MSFStreamLayout &getStreamLayout() const { return StreamLayout; }
void fixCacheAfterWrite(uint32_t Offset, ArrayRef<uint8_t> Data) const;
void fixCacheAfterWrite(uint64_t Offset, ArrayRef<uint8_t> Data) const;
Error readBytes(uint32_t Offset, MutableArrayRef<uint8_t> Buffer);
bool tryReadContiguously(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, MutableArrayRef<uint8_t> Buffer);
bool tryReadContiguously(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer);
const uint32_t BlockSize;
@ -125,13 +125,13 @@ public:
return support::little;
}
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override;
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override;
uint32_t getLength() override;
uint64_t getLength() override;
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) override;
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Buffer) override;
Error commit() override;

View File

@ -38,7 +38,7 @@ public:
llvm::support::endianness getEndian() const override { return Endian; }
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForRead(Offset, Size))
return EC;
@ -46,7 +46,7 @@ public:
return Error::success();
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForRead(Offset, 1))
return EC;
@ -54,7 +54,7 @@ public:
return Error::success();
}
uint32_t getLength() override { return Data.size(); }
uint64_t getLength() override { return Data.size(); }
ArrayRef<uint8_t> data() const { return Data; }
@ -97,19 +97,19 @@ public:
return ImmutableStream.getEndian();
}
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
return ImmutableStream.readBytes(Offset, Size, Buffer);
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
return ImmutableStream.readLongestContiguousChunk(Offset, Buffer);
}
uint32_t getLength() override { return ImmutableStream.getLength(); }
uint64_t getLength() override { return ImmutableStream.getLength(); }
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) override {
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Buffer) override {
if (Buffer.empty())
return Error::success();
@ -145,7 +145,7 @@ public:
llvm::support::endianness getEndian() const override { return Endian; }
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForWrite(Offset, Buffer.size()))
return EC;
@ -154,11 +154,11 @@ public:
return Error::success();
}
void insert(uint32_t Offset, ArrayRef<uint8_t> Bytes) {
void insert(uint64_t Offset, ArrayRef<uint8_t> Bytes) {
Data.insert(Data.begin() + Offset, Bytes.begin(), Bytes.end());
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForWrite(Offset, 1))
return EC;
@ -167,9 +167,9 @@ public:
return Error::success();
}
uint32_t getLength() override { return Data.size(); }
uint64_t getLength() override { return Data.size(); }
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) override {
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Buffer) override {
if (Buffer.empty())
return Error::success();
@ -182,7 +182,7 @@ public:
if (Offset > getLength())
return make_error<BinaryStreamError>(stream_error_code::invalid_offset);
uint32_t RequiredSize = Offset + Buffer.size();
uint64_t RequiredSize = Offset + Buffer.size();
if (RequiredSize > Data.size())
Data.resize(RequiredSize);
@ -240,19 +240,19 @@ public:
return Impl.getEndian();
}
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
return Impl.readBytes(Offset, Size, Buffer);
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
return Impl.readLongestContiguousChunk(Offset, Buffer);
}
uint32_t getLength() override { return Impl.getLength(); }
uint64_t getLength() override { return Impl.getLength(); }
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) override {
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) override {
return Impl.writeBytes(Offset, Data);
}

View File

@ -38,7 +38,7 @@ public:
llvm::support::endianness getEndian() const override { return Endian; }
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
auto ExpectedIndex = translateOffsetIndex(Offset);
if (!ExpectedIndex)
@ -52,7 +52,7 @@ public:
return Error::success();
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
auto ExpectedIndex = translateOffsetIndex(Offset);
if (!ExpectedIndex)
@ -66,7 +66,7 @@ public:
computeItemOffsets();
}
uint32_t getLength() override {
uint64_t getLength() override {
return ItemEndOffsets.empty() ? 0 : ItemEndOffsets.back();
}
@ -74,16 +74,16 @@ private:
void computeItemOffsets() {
ItemEndOffsets.clear();
ItemEndOffsets.reserve(Items.size());
uint32_t CurrentOffset = 0;
uint64_t CurrentOffset = 0;
for (const auto &Item : Items) {
uint32_t Len = Traits::length(Item);
uint64_t Len = Traits::length(Item);
assert(Len > 0 && "no empty items");
CurrentOffset += Len;
ItemEndOffsets.push_back(CurrentOffset);
}
}
Expected<uint32_t> translateOffsetIndex(uint32_t Offset) {
Expected<uint32_t> translateOffsetIndex(uint64_t Offset) {
// Make sure the offset is somewhere in our items array.
if (Offset >= getLength())
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
@ -98,7 +98,7 @@ private:
ArrayRef<T> Items;
// Sorted vector of offsets to accelerate lookup.
std::vector<uint32_t> ItemEndOffsets;
std::vector<uint64_t> ItemEndOffsets;
};
} // end namespace llvm

View File

@ -41,22 +41,22 @@ public:
/// Given an offset into the stream and a number of bytes, attempt to
/// read the bytes and set the output ArrayRef to point to data owned by the
/// stream.
virtual Error readBytes(uint32_t Offset, uint32_t Size,
virtual Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) = 0;
/// Given an offset into the stream, read as much as possible without
/// copying any data.
virtual Error readLongestContiguousChunk(uint32_t Offset,
virtual Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) = 0;
/// Return the number of bytes of data in this stream.
virtual uint32_t getLength() = 0;
virtual uint64_t getLength() = 0;
/// Return the properties of this stream.
virtual BinaryStreamFlags getFlags() const { return BSF_None; }
protected:
Error checkOffsetForRead(uint32_t Offset, uint32_t DataSize) {
Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize) {
if (Offset > getLength())
return make_error<BinaryStreamError>(stream_error_code::invalid_offset);
if (getLength() < DataSize + Offset)
@ -77,7 +77,7 @@ public:
/// Attempt to write the given bytes into the stream at the desired
/// offset. This will always necessitate a copy. Cannot shrink or grow the
/// stream, only writes into existing allocated space.
virtual Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) = 0;
virtual Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) = 0;
/// For buffered streams, commits changes to the backing store.
virtual Error commit() = 0;
@ -86,7 +86,7 @@ public:
BinaryStreamFlags getFlags() const override { return BSF_Write; }
protected:
Error checkOffsetForWrite(uint32_t Offset, uint32_t DataSize) {
Error checkOffsetForWrite(uint64_t Offset, uint64_t DataSize) {
if (!(getFlags() & BSF_Append))
return checkOffsetForRead(Offset, DataSize);

View File

@ -251,16 +251,16 @@ public:
}
bool empty() const { return bytesRemaining() == 0; }
void setOffset(uint32_t Off) { Offset = Off; }
uint32_t getOffset() const { return Offset; }
uint32_t getLength() const { return Stream.getLength(); }
uint32_t bytesRemaining() const { return getLength() - getOffset(); }
void setOffset(uint64_t Off) { Offset = Off; }
uint64_t getOffset() const { return Offset; }
uint64_t getLength() const { return Stream.getLength(); }
uint64_t bytesRemaining() const { return getLength() - getOffset(); }
/// Advance the stream's offset by \p Amount bytes.
///
/// \returns a success error code if at least \p Amount bytes remain in the
/// stream, otherwise returns an appropriate error code.
Error skip(uint32_t Amount);
Error skip(uint64_t Amount);
/// Examine the next byte of the underlying stream without advancing the
/// stream's offset. If the stream is empty the behavior is undefined.
@ -271,11 +271,11 @@ public:
Error padToAlignment(uint32_t Align);
std::pair<BinaryStreamReader, BinaryStreamReader>
split(uint32_t Offset) const;
split(uint64_t Offset) const;
private:
BinaryStreamRef Stream;
uint32_t Offset = 0;
uint64_t Offset = 0;
};
} // namespace llvm

View File

@ -30,12 +30,12 @@ protected:
Length = BorrowedImpl.getLength();
}
BinaryStreamRefBase(std::shared_ptr<StreamType> SharedImpl, uint32_t Offset,
Optional<uint32_t> Length)
BinaryStreamRefBase(std::shared_ptr<StreamType> SharedImpl, uint64_t Offset,
Optional<uint64_t> Length)
: SharedImpl(SharedImpl), BorrowedImpl(SharedImpl.get()),
ViewOffset(Offset), Length(Length) {}
BinaryStreamRefBase(StreamType &BorrowedImpl, uint32_t Offset,
Optional<uint32_t> Length)
BinaryStreamRefBase(StreamType &BorrowedImpl, uint64_t Offset,
Optional<uint64_t> Length)
: BorrowedImpl(&BorrowedImpl), ViewOffset(Offset), Length(Length) {}
BinaryStreamRefBase(const BinaryStreamRefBase &Other) = default;
BinaryStreamRefBase &operator=(const BinaryStreamRefBase &Other) = default;
@ -48,7 +48,7 @@ public:
return BorrowedImpl->getEndian();
}
uint32_t getLength() const {
uint64_t getLength() const {
if (Length.hasValue())
return *Length;
@ -58,7 +58,7 @@ public:
/// Return a new BinaryStreamRef with the first \p N elements removed. If
/// this BinaryStreamRef is length-tracking, then the resulting one will be
/// too.
RefType drop_front(uint32_t N) const {
RefType drop_front(uint64_t N) const {
if (!BorrowedImpl)
return RefType();
@ -76,7 +76,7 @@ public:
/// Return a new BinaryStreamRef with the last \p N elements removed. If
/// this BinaryStreamRef is length-tracking and \p N is greater than 0, then
/// this BinaryStreamRef will no longer length-track.
RefType drop_back(uint32_t N) const {
RefType drop_back(uint64_t N) const {
if (!BorrowedImpl)
return RefType();
@ -96,26 +96,26 @@ public:
}
/// Return a new BinaryStreamRef with only the first \p N elements remaining.
RefType keep_front(uint32_t N) const {
RefType keep_front(uint64_t N) const {
assert(N <= getLength());
return drop_back(getLength() - N);
}
/// Return a new BinaryStreamRef with only the last \p N elements remaining.
RefType keep_back(uint32_t N) const {
RefType keep_back(uint64_t N) const {
assert(N <= getLength());
return drop_front(getLength() - N);
}
/// Return a new BinaryStreamRef with the first and last \p N elements
/// removed.
RefType drop_symmetric(uint32_t N) const {
RefType drop_symmetric(uint64_t N) const {
return drop_front(N).drop_back(N);
}
/// Return a new BinaryStreamRef with the first \p Offset elements removed,
/// and retaining exactly \p Len elements.
RefType slice(uint32_t Offset, uint32_t Len) const {
RefType slice(uint64_t Offset, uint64_t Len) const {
return drop_front(Offset).keep_front(Len);
}
@ -132,7 +132,7 @@ public:
}
protected:
Error checkOffsetForRead(uint32_t Offset, uint32_t DataSize) const {
Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize) const {
if (Offset > getLength())
return make_error<BinaryStreamError>(stream_error_code::invalid_offset);
if (getLength() < DataSize + Offset)
@ -142,8 +142,8 @@ protected:
std::shared_ptr<StreamType> SharedImpl;
StreamType *BorrowedImpl = nullptr;
uint32_t ViewOffset = 0;
Optional<uint32_t> Length;
uint64_t ViewOffset = 0;
Optional<uint64_t> Length;
};
/// BinaryStreamRef is to BinaryStream what ArrayRef is to an Array. It
@ -157,15 +157,15 @@ class BinaryStreamRef
: public BinaryStreamRefBase<BinaryStreamRef, BinaryStream> {
friend BinaryStreamRefBase<BinaryStreamRef, BinaryStream>;
friend class WritableBinaryStreamRef;
BinaryStreamRef(std::shared_ptr<BinaryStream> Impl, uint32_t ViewOffset,
Optional<uint32_t> Length)
BinaryStreamRef(std::shared_ptr<BinaryStream> Impl, uint64_t ViewOffset,
Optional<uint64_t> Length)
: BinaryStreamRefBase(Impl, ViewOffset, Length) {}
public:
BinaryStreamRef() = default;
BinaryStreamRef(BinaryStream &Stream);
BinaryStreamRef(BinaryStream &Stream, uint32_t Offset,
Optional<uint32_t> Length);
BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
Optional<uint64_t> Length);
explicit BinaryStreamRef(ArrayRef<uint8_t> Data,
llvm::support::endianness Endian);
explicit BinaryStreamRef(StringRef Data, llvm::support::endianness Endian);
@ -176,8 +176,8 @@ public:
BinaryStreamRef &operator=(BinaryStreamRef &&Other) = default;
// Use BinaryStreamRef.slice() instead.
BinaryStreamRef(BinaryStreamRef &S, uint32_t Offset,
uint32_t Length) = delete;
BinaryStreamRef(BinaryStreamRef &S, uint64_t Offset,
uint64_t Length) = delete;
/// Given an Offset into this StreamRef and a Size, return a reference to a
/// buffer owned by the stream.
@ -185,7 +185,7 @@ public:
/// \returns a success error code if the entire range of data is within the
/// bounds of this BinaryStreamRef's view and the implementation could read
/// the data, and an appropriate error code otherwise.
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) const;
/// Given an Offset into this BinaryStreamRef, return a reference to the
@ -193,29 +193,28 @@ public:
///
/// \returns a success error code if implementation could read the data,
/// and an appropriate error code otherwise.
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) const;
};
struct BinarySubstreamRef {
uint32_t Offset = 0; // Offset in the parent stream
uint64_t Offset = 0; // Offset in the parent stream
BinaryStreamRef StreamData; // Stream Data
BinarySubstreamRef slice(uint32_t Off, uint32_t Size) const {
BinarySubstreamRef slice(uint64_t Off, uint64_t Size) const {
BinaryStreamRef SubSub = StreamData.slice(Off, Size);
return {Off + Offset, SubSub};
}
BinarySubstreamRef drop_front(uint32_t N) const {
BinarySubstreamRef drop_front(uint64_t N) const {
return slice(N, size() - N);
}
BinarySubstreamRef keep_front(uint32_t N) const { return slice(0, N); }
BinarySubstreamRef keep_front(uint64_t N) const { return slice(0, N); }
std::pair<BinarySubstreamRef, BinarySubstreamRef>
split(uint32_t Off) const {
std::pair<BinarySubstreamRef, BinarySubstreamRef> split(uint64_t Off) const {
return std::make_pair(keep_front(Off), drop_front(Off));
}
uint32_t size() const { return StreamData.getLength(); }
uint64_t size() const { return StreamData.getLength(); }
bool empty() const { return size() == 0; }
};
@ -224,10 +223,10 @@ class WritableBinaryStreamRef
WritableBinaryStream> {
friend BinaryStreamRefBase<WritableBinaryStreamRef, WritableBinaryStream>;
WritableBinaryStreamRef(std::shared_ptr<WritableBinaryStream> Impl,
uint32_t ViewOffset, Optional<uint32_t> Length)
uint64_t ViewOffset, Optional<uint64_t> Length)
: BinaryStreamRefBase(Impl, ViewOffset, Length) {}
Error checkOffsetForWrite(uint32_t Offset, uint32_t DataSize) const {
Error checkOffsetForWrite(uint64_t Offset, uint64_t DataSize) const {
if (!(BorrowedImpl->getFlags() & BSF_Append))
return checkOffsetForRead(Offset, DataSize);
@ -239,8 +238,8 @@ class WritableBinaryStreamRef
public:
WritableBinaryStreamRef() = default;
WritableBinaryStreamRef(WritableBinaryStream &Stream);
WritableBinaryStreamRef(WritableBinaryStream &Stream, uint32_t Offset,
Optional<uint32_t> Length);
WritableBinaryStreamRef(WritableBinaryStream &Stream, uint64_t Offset,
Optional<uint64_t> Length);
explicit WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
llvm::support::endianness Endian);
WritableBinaryStreamRef(const WritableBinaryStreamRef &Other) = default;
@ -251,8 +250,8 @@ public:
WritableBinaryStreamRef &operator=(WritableBinaryStreamRef &&Other) = default;
// Use WritableBinaryStreamRef.slice() instead.
WritableBinaryStreamRef(WritableBinaryStreamRef &S, uint32_t Offset,
uint32_t Length) = delete;
WritableBinaryStreamRef(WritableBinaryStreamRef &S, uint64_t Offset,
uint64_t Length) = delete;
/// Given an Offset into this WritableBinaryStreamRef and some input data,
/// writes the data to the underlying stream.
@ -260,7 +259,7 @@ public:
/// \returns a success error code if the data could fit within the underlying
/// stream at the specified location and the implementation could write the
/// data, and an appropriate error code otherwise.
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const;
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) const;
/// Conver this WritableBinaryStreamRef to a read-only BinaryStreamRef.
operator BinaryStreamRef() const;

View File

@ -124,7 +124,7 @@ public:
///
/// \returns a success error code if the data was successfully written,
/// otherwise returns an appropriate error code.
Error writeStreamRef(BinaryStreamRef Ref, uint32_t Size);
Error writeStreamRef(BinaryStreamRef Ref, uint64_t Size);
/// Writes the object \p Obj to the underlying stream, as if by using memcpy.
/// It is up to the caller to ensure that type of \p Obj can be safely copied
@ -178,17 +178,17 @@ public:
}
/// Splits the Writer into two Writers at a given offset.
std::pair<BinaryStreamWriter, BinaryStreamWriter> split(uint32_t Off) const;
std::pair<BinaryStreamWriter, BinaryStreamWriter> split(uint64_t Off) const;
void setOffset(uint32_t Off) { Offset = Off; }
uint32_t getOffset() const { return Offset; }
uint32_t getLength() const { return Stream.getLength(); }
uint32_t bytesRemaining() const { return getLength() - getOffset(); }
void setOffset(uint64_t Off) { Offset = Off; }
uint64_t getOffset() const { return Offset; }
uint64_t getLength() const { return Stream.getLength(); }
uint64_t bytesRemaining() const { return getLength() - getOffset(); }
Error padToAlignment(uint32_t Align);
protected:
WritableBinaryStreamRef Stream;
uint32_t Offset = 0;
uint64_t Offset = 0;
};
} // end namespace llvm

View File

@ -35,7 +35,7 @@ public:
} // end anonymous namespace
using Interval = std::pair<uint32_t, uint32_t>;
using Interval = std::pair<uint64_t, uint64_t>;
static Interval intersect(const Interval &I1, const Interval &I2) {
return std::make_pair(std::max(I1.first, I2.first),
@ -85,7 +85,7 @@ MappedBlockStream::createFpmStream(const MSFLayout &Layout,
return createStream(Layout.SB->BlockSize, SL, MsfData, Allocator);
}
Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
Error MappedBlockStream::readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) {
// Make sure we aren't trying to read beyond the end of the stream.
if (auto EC = checkOffsetForRead(Offset, Size))
@ -138,7 +138,7 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
if (Intersection != RequestExtent)
continue;
uint32_t CacheRangeOffset =
uint64_t CacheRangeOffset =
AbsoluteDifference(CachedExtent.first, Intersection.first);
Buffer = CachedAlloc.slice(CacheRangeOffset, Size);
return Error::success();
@ -163,14 +163,14 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
return Error::success();
}
Error MappedBlockStream::readLongestContiguousChunk(uint32_t Offset,
Error MappedBlockStream::readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) {
// Make sure we aren't trying to read beyond the end of the stream.
if (auto EC = checkOffsetForRead(Offset, 1))
return EC;
uint32_t First = Offset / BlockSize;
uint32_t Last = First;
uint64_t First = Offset / BlockSize;
uint64_t Last = First;
while (Last < getNumBlocks() - 1) {
if (StreamLayout.Blocks[Last] != StreamLayout.Blocks[Last + 1] - 1)
@ -178,13 +178,13 @@ Error MappedBlockStream::readLongestContiguousChunk(uint32_t Offset,
++Last;
}
uint32_t OffsetInFirstBlock = Offset % BlockSize;
uint32_t BytesFromFirstBlock = BlockSize - OffsetInFirstBlock;
uint32_t BlockSpan = Last - First + 1;
uint32_t ByteSpan = BytesFromFirstBlock + (BlockSpan - 1) * BlockSize;
uint64_t OffsetInFirstBlock = Offset % BlockSize;
uint64_t BytesFromFirstBlock = BlockSize - OffsetInFirstBlock;
uint64_t BlockSpan = Last - First + 1;
uint64_t ByteSpan = BytesFromFirstBlock + (BlockSpan - 1) * BlockSize;
ArrayRef<uint8_t> BlockData;
uint32_t MsfOffset = blockToOffset(StreamLayout.Blocks[First], BlockSize);
uint64_t MsfOffset = blockToOffset(StreamLayout.Blocks[First], BlockSize);
if (auto EC = MsfData.readBytes(MsfOffset, BlockSize, BlockData))
return EC;
@ -193,9 +193,9 @@ Error MappedBlockStream::readLongestContiguousChunk(uint32_t Offset,
return Error::success();
}
uint32_t MappedBlockStream::getLength() { return StreamLayout.Length; }
uint64_t MappedBlockStream::getLength() { return StreamLayout.Length; }
bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size,
bool MappedBlockStream::tryReadContiguously(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) {
if (Size == 0) {
Buffer = ArrayRef<uint8_t>();
@ -206,15 +206,15 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size,
// all subsequent blocks are contiguous. For example, a 10k read with a 4k
// block size can be filled with a reference if, from the starting offset,
// 3 blocks in a row are contiguous.
uint32_t BlockNum = Offset / BlockSize;
uint32_t OffsetInBlock = Offset % BlockSize;
uint32_t BytesFromFirstBlock = std::min(Size, BlockSize - OffsetInBlock);
uint32_t NumAdditionalBlocks =
uint64_t BlockNum = Offset / BlockSize;
uint64_t OffsetInBlock = Offset % BlockSize;
uint64_t BytesFromFirstBlock = std::min(Size, BlockSize - OffsetInBlock);
uint64_t NumAdditionalBlocks =
alignTo(Size - BytesFromFirstBlock, BlockSize) / BlockSize;
uint32_t RequiredContiguousBlocks = NumAdditionalBlocks + 1;
uint32_t E = StreamLayout.Blocks[BlockNum];
for (uint32_t I = 0; I < RequiredContiguousBlocks; ++I, ++E) {
uint64_t RequiredContiguousBlocks = NumAdditionalBlocks + 1;
uint64_t E = StreamLayout.Blocks[BlockNum];
for (uint64_t I = 0; I < RequiredContiguousBlocks; ++I, ++E) {
if (StreamLayout.Blocks[I + BlockNum] != E)
return false;
}
@ -225,8 +225,8 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size,
// cross-block span, explicitly resize the ArrayRef to cover the entire
// request length.
ArrayRef<uint8_t> BlockData;
uint32_t FirstBlockAddr = StreamLayout.Blocks[BlockNum];
uint32_t MsfOffset = blockToOffset(FirstBlockAddr, BlockSize);
uint64_t FirstBlockAddr = StreamLayout.Blocks[BlockNum];
uint64_t MsfOffset = blockToOffset(FirstBlockAddr, BlockSize);
if (auto EC = MsfData.readBytes(MsfOffset, BlockSize, BlockData)) {
consumeError(std::move(EC));
return false;
@ -236,28 +236,28 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size,
return true;
}
Error MappedBlockStream::readBytes(uint32_t Offset,
Error MappedBlockStream::readBytes(uint64_t Offset,
MutableArrayRef<uint8_t> Buffer) {
uint32_t BlockNum = Offset / BlockSize;
uint32_t OffsetInBlock = Offset % BlockSize;
uint64_t BlockNum = Offset / BlockSize;
uint64_t OffsetInBlock = Offset % BlockSize;
// Make sure we aren't trying to read beyond the end of the stream.
if (auto EC = checkOffsetForRead(Offset, Buffer.size()))
return EC;
uint32_t BytesLeft = Buffer.size();
uint32_t BytesWritten = 0;
uint64_t BytesLeft = Buffer.size();
uint64_t BytesWritten = 0;
uint8_t *WriteBuffer = Buffer.data();
while (BytesLeft > 0) {
uint32_t StreamBlockAddr = StreamLayout.Blocks[BlockNum];
uint64_t StreamBlockAddr = StreamLayout.Blocks[BlockNum];
ArrayRef<uint8_t> BlockData;
uint32_t Offset = blockToOffset(StreamBlockAddr, BlockSize);
uint64_t Offset = blockToOffset(StreamBlockAddr, BlockSize);
if (auto EC = MsfData.readBytes(Offset, BlockSize, BlockData))
return EC;
const uint8_t *ChunkStart = BlockData.data() + OffsetInBlock;
uint32_t BytesInChunk = std::min(BytesLeft, BlockSize - OffsetInBlock);
uint64_t BytesInChunk = std::min(BytesLeft, BlockSize - OffsetInBlock);
::memcpy(WriteBuffer + BytesWritten, ChunkStart, BytesInChunk);
BytesWritten += BytesInChunk;
@ -271,7 +271,7 @@ Error MappedBlockStream::readBytes(uint32_t Offset,
void MappedBlockStream::invalidateCache() { CacheMap.shrink_and_clear(); }
void MappedBlockStream::fixCacheAfterWrite(uint32_t Offset,
void MappedBlockStream::fixCacheAfterWrite(uint64_t Offset,
ArrayRef<uint8_t> Data) const {
// If this write overlapped a read which previously came from the pool,
// someone may still be holding a pointer to that alloc which is now invalid.
@ -297,10 +297,10 @@ void MappedBlockStream::fixCacheAfterWrite(uint32_t Offset,
auto Intersection = intersect(WriteInterval, CachedInterval);
assert(Intersection.first <= Intersection.second);
uint32_t Length = Intersection.second - Intersection.first;
uint32_t SrcOffset =
uint64_t Length = Intersection.second - Intersection.first;
uint64_t SrcOffset =
AbsoluteDifference(WriteInterval.first, Intersection.first);
uint32_t DestOffset =
uint64_t DestOffset =
AbsoluteDifference(CachedInterval.first, Intersection.first);
::memcpy(Alloc.data() + DestOffset, Data.data() + SrcOffset, Length);
}
@ -370,39 +370,39 @@ WritableMappedBlockStream::createFpmStream(const MSFLayout &Layout,
return createStream(Layout.SB->BlockSize, MinLayout, MsfData, Allocator);
}
Error WritableMappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
Error WritableMappedBlockStream::readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) {
return ReadInterface.readBytes(Offset, Size, Buffer);
}
Error WritableMappedBlockStream::readLongestContiguousChunk(
uint32_t Offset, ArrayRef<uint8_t> &Buffer) {
uint64_t Offset, ArrayRef<uint8_t> &Buffer) {
return ReadInterface.readLongestContiguousChunk(Offset, Buffer);
}
uint32_t WritableMappedBlockStream::getLength() {
uint64_t WritableMappedBlockStream::getLength() {
return ReadInterface.getLength();
}
Error WritableMappedBlockStream::writeBytes(uint32_t Offset,
Error WritableMappedBlockStream::writeBytes(uint64_t Offset,
ArrayRef<uint8_t> Buffer) {
// Make sure we aren't trying to write beyond the end of the stream.
if (auto EC = checkOffsetForWrite(Offset, Buffer.size()))
return EC;
uint32_t BlockNum = Offset / getBlockSize();
uint32_t OffsetInBlock = Offset % getBlockSize();
uint64_t BlockNum = Offset / getBlockSize();
uint64_t OffsetInBlock = Offset % getBlockSize();
uint32_t BytesLeft = Buffer.size();
uint32_t BytesWritten = 0;
uint64_t BytesLeft = Buffer.size();
uint64_t BytesWritten = 0;
while (BytesLeft > 0) {
uint32_t StreamBlockAddr = getStreamLayout().Blocks[BlockNum];
uint32_t BytesToWriteInChunk =
uint64_t StreamBlockAddr = getStreamLayout().Blocks[BlockNum];
uint64_t BytesToWriteInChunk =
std::min(BytesLeft, getBlockSize() - OffsetInBlock);
const uint8_t *Chunk = Buffer.data() + BytesWritten;
ArrayRef<uint8_t> ChunkData(Chunk, BytesToWriteInChunk);
uint32_t MsfOffset = blockToOffset(StreamBlockAddr, getBlockSize());
uint64_t MsfOffset = blockToOffset(StreamBlockAddr, getBlockSize());
MsfOffset += OffsetInBlock;
if (auto EC = WriteInterface.writeBytes(MsfOffset, ChunkData))
return EC;

View File

@ -17,8 +17,8 @@ namespace pdb {
namespace {
Expected<std::string> readStreamData(BinaryStream &Stream, uint32_t Limit) {
uint32_t Offset = 0, DataLength = std::min(Limit, Stream.getLength());
Expected<std::string> readStreamData(BinaryStream &Stream, uint64_t Limit) {
uint64_t Offset = 0, DataLength = std::min(Limit, Stream.getLength());
std::string Result;
Result.reserve(DataLength);
while (Offset < DataLength) {

View File

@ -72,10 +72,10 @@ Error BinaryStreamReader::readSLEB128(int64_t &Dest) {
}
Error BinaryStreamReader::readCString(StringRef &Dest) {
uint32_t OriginalOffset = getOffset();
uint32_t FoundOffset = 0;
uint64_t OriginalOffset = getOffset();
uint64_t FoundOffset = 0;
while (true) {
uint32_t ThisOffset = getOffset();
uint64_t ThisOffset = getOffset();
ArrayRef<uint8_t> Buffer;
if (auto EC = readLongestContiguousChunk(Buffer))
return EC;
@ -100,8 +100,8 @@ Error BinaryStreamReader::readCString(StringRef &Dest) {
}
Error BinaryStreamReader::readWideString(ArrayRef<UTF16> &Dest) {
uint32_t Length = 0;
uint32_t OriginalOffset = getOffset();
uint64_t Length = 0;
uint64_t OriginalOffset = getOffset();
const UTF16 *C;
while (true) {
if (auto EC = readObject(C))
@ -110,7 +110,7 @@ Error BinaryStreamReader::readWideString(ArrayRef<UTF16> &Dest) {
break;
++Length;
}
uint32_t NewOffset = getOffset();
uint64_t NewOffset = getOffset();
setOffset(OriginalOffset);
if (auto EC = readArray(Dest, Length))
@ -145,7 +145,7 @@ Error BinaryStreamReader::readSubstream(BinarySubstreamRef &Ref,
return readStreamRef(Ref.StreamData, Length);
}
Error BinaryStreamReader::skip(uint32_t Amount) {
Error BinaryStreamReader::skip(uint64_t Amount) {
if (Amount > bytesRemaining())
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
Offset += Amount;
@ -166,7 +166,7 @@ uint8_t BinaryStreamReader::peek() const {
}
std::pair<BinaryStreamReader, BinaryStreamReader>
BinaryStreamReader::split(uint32_t Off) const {
BinaryStreamReader::split(uint64_t Off) const {
assert(getLength() >= Off);
BinaryStreamRef First = Stream.drop_front(Offset);

View File

@ -21,15 +21,15 @@ public:
llvm::support::endianness getEndian() const override {
return BBS.getEndian();
}
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readBytes(Offset, Size, Buffer);
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readLongestContiguousChunk(Offset, Buffer);
}
uint32_t getLength() override { return BBS.getLength(); }
uint64_t getLength() override { return BBS.getLength(); }
private:
BinaryByteStream BBS;
@ -44,17 +44,17 @@ public:
llvm::support::endianness getEndian() const override {
return BBS.getEndian();
}
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readBytes(Offset, Size, Buffer);
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readLongestContiguousChunk(Offset, Buffer);
}
uint32_t getLength() override { return BBS.getLength(); }
uint64_t getLength() override { return BBS.getLength(); }
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) override {
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> Data) override {
return BBS.writeBytes(Offset, Data);
}
Error commit() override { return BBS.commit(); }
@ -66,8 +66,8 @@ private:
BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream)
: BinaryStreamRefBase(Stream) {}
BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream, uint32_t Offset,
Optional<uint32_t> Length)
BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
Optional<uint64_t> Length)
: BinaryStreamRefBase(Stream, Offset, Length) {}
BinaryStreamRef::BinaryStreamRef(ArrayRef<uint8_t> Data, endianness Endian)
: BinaryStreamRefBase(std::make_shared<ArrayRefImpl>(Data, Endian), 0,
@ -76,7 +76,7 @@ BinaryStreamRef::BinaryStreamRef(StringRef Data, endianness Endian)
: BinaryStreamRef(makeArrayRef(Data.bytes_begin(), Data.bytes_end()),
Endian) {}
Error BinaryStreamRef::readBytes(uint32_t Offset, uint32_t Size,
Error BinaryStreamRef::readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) const {
if (auto EC = checkOffsetForRead(Offset, Size))
return EC;
@ -84,7 +84,7 @@ Error BinaryStreamRef::readBytes(uint32_t Offset, uint32_t Size,
}
Error BinaryStreamRef::readLongestContiguousChunk(
uint32_t Offset, ArrayRef<uint8_t> &Buffer) const {
uint64_t Offset, ArrayRef<uint8_t> &Buffer) const {
if (auto EC = checkOffsetForRead(Offset, 1))
return EC;
@ -94,7 +94,7 @@ Error BinaryStreamRef::readLongestContiguousChunk(
// This StreamRef might refer to a smaller window over a larger stream. In
// that case we will have read out more bytes than we should return, because
// we should not read past the end of the current view.
uint32_t MaxLength = getLength() - Offset;
uint64_t MaxLength = getLength() - Offset;
if (Buffer.size() > MaxLength)
Buffer = Buffer.slice(0, MaxLength);
return Error::success();
@ -104,8 +104,8 @@ WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream)
: BinaryStreamRefBase(Stream) {}
WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream,
uint32_t Offset,
Optional<uint32_t> Length)
uint64_t Offset,
Optional<uint64_t> Length)
: BinaryStreamRefBase(Stream, Offset, Length) {}
WritableBinaryStreamRef::WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
@ -113,8 +113,7 @@ WritableBinaryStreamRef::WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
: BinaryStreamRefBase(std::make_shared<MutableArrayRefImpl>(Data, Endian),
0, Data.size()) {}
Error WritableBinaryStreamRef::writeBytes(uint32_t Offset,
Error WritableBinaryStreamRef::writeBytes(uint64_t Offset,
ArrayRef<uint8_t> Data) const {
if (auto EC = checkOffsetForWrite(Offset, Data.size()))
return EC;

View File

@ -62,7 +62,7 @@ Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref) {
return writeStreamRef(Ref, Ref.getLength());
}
Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref, uint32_t Length) {
Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref, uint64_t Length) {
BinaryStreamReader SrcReader(Ref.slice(0, Length));
// This is a bit tricky. If we just call readBytes, we are requiring that it
// return us the entire stream as a contiguous buffer. There is no guarantee
@ -80,7 +80,7 @@ Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref, uint32_t Length) {
}
std::pair<BinaryStreamWriter, BinaryStreamWriter>
BinaryStreamWriter::split(uint32_t Off) const {
BinaryStreamWriter::split(uint64_t Off) const {
assert(getLength() >= Off);
WritableBinaryStreamRef First = Stream.drop_front(Offset);
@ -93,7 +93,7 @@ BinaryStreamWriter::split(uint32_t Off) const {
}
Error BinaryStreamWriter::padToAlignment(uint32_t Align) {
uint32_t NewOffset = alignTo(Offset, Align);
uint64_t NewOffset = alignTo(Offset, Align);
if (NewOffset > getLength())
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
while (Offset < NewOffset)

View File

@ -100,7 +100,7 @@ bool LinePrinter::IsClassExcluded(const ClassLayout &Class) {
}
void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
uint32_t StartOffset) {
uint64_t StartOffset) {
NewLine();
OS << Label << " (";
if (!Data.empty()) {
@ -113,7 +113,7 @@ void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
}
void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
uint64_t Base, uint32_t StartOffset) {
uint64_t Base, uint64_t StartOffset) {
NewLine();
OS << Label << " (";
if (!Data.empty()) {
@ -131,7 +131,7 @@ struct Run {
Run() = default;
explicit Run(uint32_t Block) : Block(Block) {}
uint32_t Block = 0;
uint32_t ByteLen = 0;
uint64_t ByteLen = 0;
};
} // namespace
@ -143,7 +143,7 @@ static std::vector<Run> computeBlockRuns(uint32_t BlockSize,
ArrayRef<support::ulittle32_t> Blocks = Layout.Blocks;
assert(!Blocks.empty());
uint32_t StreamBytesRemaining = Layout.Length;
uint64_t StreamBytesRemaining = Layout.Length;
uint32_t CurrentBlock = Blocks[0];
Runs.emplace_back(CurrentBlock);
while (!Blocks.empty()) {
@ -153,7 +153,8 @@ static std::vector<Run> computeBlockRuns(uint32_t BlockSize,
Runs.emplace_back(NextBlock);
CurrentRun = &Runs.back();
}
uint32_t Used = std::min(BlockSize, StreamBytesRemaining);
uint64_t Used =
std::min(static_cast<uint64_t>(BlockSize), StreamBytesRemaining);
CurrentRun->ByteLen += Used;
StreamBytesRemaining -= Used;
CurrentBlock = NextBlock;
@ -162,7 +163,7 @@ static std::vector<Run> computeBlockRuns(uint32_t BlockSize,
return Runs;
}
static std::pair<Run, uint32_t> findRun(uint32_t Offset, ArrayRef<Run> Runs) {
static std::pair<Run, uint64_t> findRun(uint64_t Offset, ArrayRef<Run> Runs) {
for (const auto &R : Runs) {
if (Offset < R.ByteLen)
return std::make_pair(R, Offset);
@ -173,8 +174,8 @@ static std::pair<Run, uint32_t> findRun(uint32_t Offset, ArrayRef<Run> Runs) {
void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
uint32_t StreamIdx,
StringRef StreamPurpose, uint32_t Offset,
uint32_t Size) {
StringRef StreamPurpose, uint64_t Offset,
uint64_t Size) {
if (StreamIdx >= File.getNumStreams()) {
formatLine("Stream {0}: Not present", StreamIdx);
return;
@ -193,7 +194,7 @@ void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
return;
}
uint32_t End =
uint64_t End =
(Size == 0) ? S->getLength() : std::min(Offset + Size, S->getLength());
Size = End - Offset;
@ -222,10 +223,10 @@ void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
OS << "\n";
Run FoundRun;
uint32_t RunOffset;
uint64_t RunOffset;
std::tie(FoundRun, RunOffset) = findRun(Substream.Offset, Runs);
assert(FoundRun.ByteLen >= RunOffset);
uint32_t Len = FoundRun.ByteLen - RunOffset;
uint64_t Len = FoundRun.ByteLen - RunOffset;
Len = std::min(Len, Reader.bytesRemaining());
uint64_t Base = FoundRun.Block * File.getBlockSize() + RunOffset;
ArrayRef<uint8_t> Data;
@ -246,13 +247,14 @@ void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
void LinePrinter::formatMsfStreamBlocks(
PDBFile &File, const msf::MSFStreamLayout &StreamLayout) {
auto Blocks = makeArrayRef(StreamLayout.Blocks);
uint32_t L = StreamLayout.Length;
uint64_t L = StreamLayout.Length;
while (L > 0) {
NewLine();
assert(!Blocks.empty());
OS << formatv("Block {0} (\n", uint32_t(Blocks.front()));
uint32_t UsedBytes = std::min(L, File.getBlockSize());
uint64_t UsedBytes =
std::min(L, static_cast<uint64_t>(File.getBlockSize()));
ArrayRef<uint8_t> BlockData =
cantFail(File.getBlockData(Blocks.front(), File.getBlockSize()));
uint64_t BaseOffset = Blocks.front();
@ -267,7 +269,7 @@ void LinePrinter::formatMsfStreamBlocks(
}
}
bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size) {
bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size) {
if (IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters))
return true;
if (Size < opts::pretty::SizeThreshold)

View File

@ -49,13 +49,13 @@ public:
}
void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
uint32_t StartOffset);
uint64_t StartOffset);
void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
uint32_t StartOffset);
uint64_t StartOffset);
void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
StringRef StreamPurpose, uint32_t Offset,
uint32_t Size);
StringRef StreamPurpose, uint64_t Offset,
uint64_t Size);
void formatMsfStreamData(StringRef Label, PDBFile &File,
const msf::MSFStreamLayout &Stream,
BinarySubstreamRef Substream);
@ -66,7 +66,7 @@ public:
int getIndentLevel() const { return CurrentIndent; }
bool IsClassExcluded(const ClassLayout &Class);
bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
bool IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size);
bool IsSymbolExcluded(llvm::StringRef SymbolName);
bool IsCompilandExcluded(llvm::StringRef CompilandName);

View File

@ -36,7 +36,7 @@ public:
endianness getEndian() const override { return little; }
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForRead(Offset, Size))
return EC;
@ -44,7 +44,7 @@ public:
return Error::success();
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForRead(Offset, 1))
return EC;
@ -52,9 +52,9 @@ public:
return Error::success();
}
uint32_t getLength() override { return Data.size(); }
uint64_t getLength() override { return Data.size(); }
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> SrcData) override {
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> SrcData) override {
if (auto EC = checkOffsetForWrite(Offset, SrcData.size()))
return EC;
::memcpy(&Data[Offset], SrcData.data(), SrcData.size());

View File

@ -25,25 +25,24 @@ namespace {
class BrokenStream : public WritableBinaryStream {
public:
BrokenStream(MutableArrayRef<uint8_t> Data, endianness Endian,
uint32_t Align)
BrokenStream(MutableArrayRef<uint8_t> Data, endianness Endian, uint32_t Align)
: Data(Data), PartitionIndex(alignDown(Data.size() / 2, Align)),
Endian(Endian) {}
endianness getEndian() const override { return Endian; }
Error readBytes(uint32_t Offset, uint32_t Size,
Error readBytes(uint64_t Offset, uint64_t Size,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForRead(Offset, Size))
return EC;
uint32_t S = startIndex(Offset);
uint64_t S = startIndex(Offset);
auto Ref = Data.drop_front(S);
if (Ref.size() >= Size) {
Buffer = Ref.take_front(Size);
return Error::success();
}
uint32_t BytesLeft = Size - Ref.size();
uint64_t BytesLeft = Size - Ref.size();
uint8_t *Ptr = Allocator.Allocate<uint8_t>(Size);
::memcpy(Ptr, Ref.data(), Ref.size());
::memcpy(Ptr + Ref.size(), Data.data(), BytesLeft);
@ -51,24 +50,24 @@ public:
return Error::success();
}
Error readLongestContiguousChunk(uint32_t Offset,
Error readLongestContiguousChunk(uint64_t Offset,
ArrayRef<uint8_t> &Buffer) override {
if (auto EC = checkOffsetForRead(Offset, 1))
return EC;
uint32_t S = startIndex(Offset);
uint64_t S = startIndex(Offset);
Buffer = Data.drop_front(S);
return Error::success();
}
uint32_t getLength() override { return Data.size(); }
uint64_t getLength() override { return Data.size(); }
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> SrcData) override {
Error writeBytes(uint64_t Offset, ArrayRef<uint8_t> SrcData) override {
if (auto EC = checkOffsetForWrite(Offset, SrcData.size()))
return EC;
if (SrcData.empty())
return Error::success();
uint32_t S = startIndex(Offset);
uint64_t S = startIndex(Offset);
MutableArrayRef<uint8_t> Ref(Data);
Ref = Ref.drop_front(S);
if (Ref.size() >= SrcData.size()) {
@ -76,7 +75,7 @@ public:
return Error::success();
}
uint32_t BytesLeft = SrcData.size() - Ref.size();
uint64_t BytesLeft = SrcData.size() - Ref.size();
::memcpy(Ref.data(), SrcData.data(), Ref.size());
::memcpy(&Data[0], SrcData.data() + Ref.size(), BytesLeft);
return Error::success();
@ -84,11 +83,11 @@ public:
Error commit() override { return Error::success(); }
private:
uint32_t startIndex(uint32_t Offset) const {
uint64_t startIndex(uint64_t Offset) const {
return (Offset + PartitionIndex) % Data.size();
}
uint32_t endIndex(uint32_t Offset, uint32_t Size) const {
uint64_t endIndex(uint64_t Offset, uint64_t Size) const {
return (startIndex(Offset) + Size - 1) % Data.size();
}
@ -134,9 +133,9 @@ protected:
BrokenInputData.resize(InputData.size());
if (!Input.empty()) {
uint32_t PartitionIndex = alignDown(InputData.size() / 2, Align);
uint32_t RightBytes = InputData.size() - PartitionIndex;
uint32_t LeftBytes = PartitionIndex;
uint64_t PartitionIndex = alignDown(InputData.size() / 2, Align);
uint64_t RightBytes = InputData.size() - PartitionIndex;
uint64_t LeftBytes = PartitionIndex;
if (RightBytes > 0)
::memcpy(&BrokenInputData[PartitionIndex], Input.data(), RightBytes);
if (LeftBytes > 0)
@ -154,7 +153,7 @@ protected:
}
}
void initializeOutput(uint32_t Size, uint32_t Align) {
void initializeOutput(uint64_t Size, uint32_t Align) {
OutputData.resize(Size);
BrokenOutputData.resize(Size);
@ -368,7 +367,7 @@ TEST_F(BinaryStreamTest, MutableBinaryByteStreamBounds) {
// from the middle.
uint32_t Offsets[] = {0, 3};
for (auto Offset : Offsets) {
uint32_t ExpectedSize = Stream.Input->getLength() - Offset;
uint64_t ExpectedSize = Stream.Input->getLength() - Offset;
// Read everything from Offset until the end of the input data.
ArrayRef<uint8_t> Data;