Skip to content

Commit 457d287

Browse files
Update llvm/lib/Object/MachOObjectFile.cpp
Make sure sections are ordered when the cross the UINT32_MAX barrier Co-authored-by: Peter Rong <[email protected]>
1 parent 159cfd7 commit 457d287

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

llvm/lib/Object/MachOObjectFile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,14 +1996,19 @@ MachOObjectFile::getSectionContents(DataRefImpl Sec) const {
19961996
// 4GB. MachO::section_64 objects only have 32 bit file offsets to the
19971997
// section contents and can overflow in dSYM files. We can track this and
19981998
// adjust the section offset to be 64 bit safe.
1999+
// Assumes the sections are ordered.
2000+
uint64_t PrevTrueOffset = 0;
19992001
uint64_t SectOffsetAdjust = 0;
20002002
for (uint32_t SectIdx=0; SectIdx<Sec.d.a; ++SectIdx) {
20012003
MachO::section_64 CurrSect =
20022004
getStruct<MachO::section_64>(*this, Sections[SectIdx]);
2005+
uint64_t CurrTrueOffset = (uint64_t) CurrSect.offset | SectOffsetAdjust;
2006+
assert(SectOffsetAdjust == 0 || (PrevTrueOffset <= CurrTrueOffset) && "Overflowing sections must be ordered for adjustment")
20032007
const uint64_t EndSectFileOffset =
20042008
(uint64_t)CurrSect.offset + CurrSect.size;
20052009
if (EndSectFileOffset >= UINT32_MAX)
20062010
SectOffsetAdjust += EndSectFileOffset & 0xFFFFFFFF00000000ull;
2011+
PrevTrueOffset = CurrTrueOffset;
20072012
}
20082013
Offset += SectOffsetAdjust;
20092014
} else {

0 commit comments

Comments
 (0)