[PATCH] D69447: [NFCI][XCOFF][AIX] Skip empty Section during object file generation
Jason Liu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 25 13:15:30 PDT 2019
jasonliu created this revision.
jasonliu added reviewers: daltenty, xingxue, DiggerLin, hubert.reinterpretcast, sfertile.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This is a fix to D69112 <https://reviews.llvm.org/D69112> where we common up the logic of writing CsectGroup.
However, we forget to skip the Sections that are empty in that patch.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69447
Files:
llvm/lib/MC/XCOFFObjectWriter.cpp
Index: llvm/lib/MC/XCOFFObjectWriter.cpp
===================================================================
--- llvm/lib/MC/XCOFFObjectWriter.cpp
+++ llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -148,6 +148,7 @@
uint32_t SymbolTableEntryCount = 0;
uint32_t SymbolTableOffset = 0;
+ int16_t SectionCount = 0;
support::endian::Writer W;
std::unique_ptr<MCXCOFFObjectTargetWriter> TargetObjectWriter;
@@ -467,7 +468,7 @@
// Magic.
W.write<uint16_t>(0x01df);
// Number of sections.
- W.write<uint16_t>(Sections.size());
+ W.write<uint16_t>(SectionCount);
// Timestamp field. For reproducible output we write a 0, which represents no
// timestamp.
W.write<int32_t>(0);
@@ -483,6 +484,10 @@
void XCOFFObjectWriter::writeSectionHeaderTable() {
for (const auto *Sec : Sections) {
+ // Nothing to write for this Section.
+ if (Sec->Index == Section::UninitializedIndex)
+ continue;
+
// Write Name.
ArrayRef<char> NameRef(Sec->Name, XCOFF::NameSize);
W.write(NameRef);
@@ -509,6 +514,10 @@
void XCOFFObjectWriter::writeSymbolTable(const MCAsmLayout &Layout) {
for (const auto *Section : Sections) {
+ // Nothing to write for this Section.
+ if (Section->Index == Section::UninitializedIndex)
+ continue;
+
for (const auto *Group : Section->Groups) {
if (Group->Csects.empty())
continue;
@@ -555,6 +564,7 @@
if (SectionIndex > MaxSectionIndex)
report_fatal_error("Section index overflow!");
Section->Index = SectionIndex++;
+ SectionCount++;
bool SectionAddressSet = false;
for (auto *Group : Section->Groups) {
@@ -598,12 +608,13 @@
// Calculate the RawPointer value for each section.
uint64_t RawPointer = sizeof(XCOFF::FileHeader32) + auxiliaryHeaderSize() +
- Sections.size() * sizeof(XCOFF::SectionHeader32);
+ SectionCount * sizeof(XCOFF::SectionHeader32);
for (auto *Sec : Sections) {
- if (!Sec->IsVirtual) {
- Sec->FileOffsetToData = RawPointer;
- RawPointer += Sec->Size;
- }
+ if (Sec->Index == Section::UninitializedIndex || Sec->IsVirtual)
+ continue;
+
+ Sec->FileOffsetToData = RawPointer;
+ RawPointer += Sec->Size;
}
// TODO Add in Relocation storage to the RawPointer Calculation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69447.226491.patch
Type: text/x-patch
Size: 2316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191025/d250dd84/attachment.bin>
More information about the llvm-commits
mailing list