[PATCH] D155199: [NFC][XCOFF] Use common function to calculate file offset
Jake Egan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 13 06:38:14 PDT 2023
Jake-Egan created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Jake-Egan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155199
Files:
llvm/lib/MC/XCOFFObjectWriter.cpp
Index: llvm/lib/MC/XCOFFObjectWriter.cpp
===================================================================
--- llvm/lib/MC/XCOFFObjectWriter.cpp
+++ llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -122,6 +122,13 @@
int16_t Index;
+ 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 +196,14 @@
// is for the size the DWARF section occupies including paddings.
uint32_t MemorySize;
+ void advanceFileOffset(const uint64_t &MaxRawDataSize, uint64_t &RawPointer) {
+ FileOffsetToData = RawPointer;
+ RawPointer += MemorySize;
+
+ assert(RawPointer <= MaxRawDataSize &&
+ "Section raw data overflowed this object file.");
+ }
+
DwarfSectionEntry(StringRef N, int32_t Flags,
std::unique_ptr<XCOFFSection> Sect)
: SectionEntry(N, Flags | XCOFF::STYP_DWARF), DwarfSect(std::move(Sect)),
@@ -1161,28 +1176,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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155199.539999.patch
Type: text/x-patch
Size: 2384 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230713/c36e0097/attachment.bin>
More information about the llvm-commits
mailing list