diff options
author | jasonliu <jasonliu.development@gmail.com> | 2019-10-28 21:46:22 +0000 |
---|---|---|
committer | jasonliu <jasonliu.development@gmail.com> | 2019-10-28 22:04:23 +0000 |
commit | d83a2faacd3bce3885bb9574ec4169c9c8943144 (patch) | |
tree | 866994cf1d76c65ee6a04820856ed1f96cb4d722 /llvm/lib/MC/XCOFFObjectWriter.cpp | |
parent | 5ae881f96f999aaca98d8f83d3f00e037c783647 (diff) | |
download | bcm5719-llvm-d83a2faacd3bce3885bb9574ec4169c9c8943144.tar.gz bcm5719-llvm-d83a2faacd3bce3885bb9574ec4169c9c8943144.zip |
[NFCI][XCOFF][AIX] Skip empty Section during object file generation
This is a fix to D69112 where we common up the logic of writing CsectGroup.
However, we forget to skip the Sections that are empty in that patch.
Reviewed by: daltenty, xingxue
Differential Revision: https://reviews.llvm.org/D69447
Diffstat (limited to 'llvm/lib/MC/XCOFFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/XCOFFObjectWriter.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp index 3199c18fc16..05f3f769e5b 100644 --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -148,6 +148,7 @@ class XCOFFObjectWriter : public MCObjectWriter { uint32_t SymbolTableEntryCount = 0; uint32_t SymbolTableOffset = 0; + uint16_t SectionCount = 0; support::endian::Writer W; std::unique_ptr<MCXCOFFObjectTargetWriter> TargetObjectWriter; @@ -234,6 +235,7 @@ void XCOFFObjectWriter::reset() { // Reset the symbol table and string table. SymbolTableEntryCount = 0; SymbolTableOffset = 0; + SectionCount = 0; Strings.clear(); MCObjectWriter::reset(); @@ -467,7 +469,7 @@ void XCOFFObjectWriter::writeFileHeader() { // 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 +485,10 @@ void XCOFFObjectWriter::writeFileHeader() { 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 +515,10 @@ void XCOFFObjectWriter::writeSectionHeaderTable() { 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 +565,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) { if (SectionIndex > MaxSectionIndex) report_fatal_error("Section index overflow!"); Section->Index = SectionIndex++; + SectionCount++; bool SectionAddressSet = false; for (auto *Group : Section->Groups) { @@ -598,12 +609,13 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) { // 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. |