diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -122,6 +122,14 @@ int16_t Index; + virtual void advanceFileOffset(const uint64_t MaxRawDataSize, + uint64_t &RawPointer) { + FileOffsetToData = RawPointer; + RawPointer += Size; + if (RawPointer > MaxRawDataSize) + report_fatal_error("Section raw data overflowed this object file."); + } + // XCOFF has special section numbers for symbols: // -2 Specifies N_DEBUG, a special symbolic debugging symbol. // -1 Specifies N_ABS, an absolute symbol. The symbol has a value but is not @@ -189,6 +197,15 @@ // is for the size the DWARF section occupies including paddings. uint32_t MemorySize; + void advanceFileOffset(const uint64_t MaxRawDataSize, + uint64_t &RawPointer) override { + FileOffsetToData = RawPointer; + RawPointer += MemorySize; + + assert(RawPointer <= MaxRawDataSize && + "Section raw data overflowed this object file."); + } + DwarfSectionEntry(StringRef N, int32_t Flags, std::unique_ptr Sect) : SectionEntry(N, Flags | XCOFF::STYP_DWARF), DwarfSect(std::move(Sect)), @@ -1161,28 +1178,18 @@ if (Sec->Index == SectionEntry::UninitializedIndex || Sec->IsVirtual) continue; - Sec->FileOffsetToData = RawPointer; - RawPointer += Sec->Size; - if (RawPointer > MaxRawDataSize) - report_fatal_error("Section raw data overflowed this object file."); + Sec->advanceFileOffset(MaxRawDataSize, RawPointer); } if (!DwarfSections.empty()) { RawPointer += PaddingsBeforeDwarf; for (auto &DwarfSection : DwarfSections) { - DwarfSection.FileOffsetToData = RawPointer; - RawPointer += DwarfSection.MemorySize; - if (RawPointer > MaxRawDataSize) - report_fatal_error("Section raw data overflowed this object file."); + DwarfSection.advanceFileOffset(MaxRawDataSize, RawPointer); } } if (hasExceptionSection()) { - ExceptionSection.FileOffsetToData = RawPointer; - RawPointer += ExceptionSection.Size; - - assert(RawPointer <= MaxRawDataSize && - "Section raw data overflowed this object file."); + ExceptionSection.advanceFileOffset(MaxRawDataSize, RawPointer); } for (auto *Sec : Sections) {