Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/MachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class LLVM_ABI MachOObjectFile : public ObjectFile {
uint64_t getSectionAddress(DataRefImpl Sec) const override;
uint64_t getSectionIndex(DataRefImpl Sec) const override;
uint64_t getSectionSize(DataRefImpl Sec) const override;
ArrayRef<uint8_t> getSectionContents(uint32_t Offset, uint64_t Size) const;
ArrayRef<uint8_t> getSectionContents(uint64_t Offset, uint64_t Size) const;
Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const override;
uint64_t getSectionAlignment(DataRefImpl Sec) const override;
Expand Down
18 changes: 16 additions & 2 deletions llvm/lib/Object/MachOObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,20 +1978,34 @@ uint64_t MachOObjectFile::getSectionSize(DataRefImpl Sec) const {
return SectSize;
}

ArrayRef<uint8_t> MachOObjectFile::getSectionContents(uint32_t Offset,
ArrayRef<uint8_t> MachOObjectFile::getSectionContents(uint64_t Offset,
uint64_t Size) const {
return arrayRefFromStringRef(getData().substr(Offset, Size));
}

Expected<ArrayRef<uint8_t>>
MachOObjectFile::getSectionContents(DataRefImpl Sec) const {
uint32_t Offset;
uint64_t Offset;
uint64_t Size;

if (is64Bit()) {
MachO::section_64 Sect = getSection64(Sec);
Offset = Sect.offset;
Size = Sect.size;
// Check for large mach-o files where the section contents might exceed
// 4GB. MachO::section_64 objects only have 32 bit file offsets to the
// section contents and can overflow in dSYM files. We can track this and
// adjust the section offset to be 64 bit safe.
uint64_t SectOffsetAdjust = 0;
for (uint32_t SectIdx=0; SectIdx<Sec.d.a; ++SectIdx) {
MachO::section_64 CurrSect =
getStruct<MachO::section_64>(*this, Sections[SectIdx]);
const uint64_t EndSectFileOffset =
(uint64_t)CurrSect.offset + CurrSect.size;
if (EndSectFileOffset >= UINT32_MAX)
SectOffsetAdjust += EndSectFileOffset & 0xFFFFFFFF00000000ull;
}
Offset += SectOffsetAdjust;
} else {
MachO::section Sect = getSection(Sec);
Offset = Sect.offset;
Expand Down
Loading