Skip to content

Commit

Permalink
[NFC][COFF] Use COFFSection.MCSection when writeSection
Browse files Browse the repository at this point in the history
Each COFFSection bind MCSection when created. No need to iterate
throught MCAssembler when writeSection.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D151793
  • Loading branch information
HaohaiWen committed Jun 5, 2023
1 parent 4b27ad7 commit 01cc388
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions llvm/lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class WinCOFFObjectWriter : public MCObjectWriter {
uint32_t writeSectionContents(MCAssembler &Asm, const MCAsmLayout &Layout,
const MCSection &MCSec);
void writeSection(MCAssembler &Asm, const MCAsmLayout &Layout,
const COFFSection &Sec, const MCSection &MCSec);
const COFFSection &Sec);

// MCObjectWriter interface implementation.

Expand Down Expand Up @@ -603,8 +603,7 @@ uint32_t WinCOFFObjectWriter::writeSectionContents(MCAssembler &Asm,

void WinCOFFObjectWriter::writeSection(MCAssembler &Asm,
const MCAsmLayout &Layout,
const COFFSection &Sec,
const MCSection &MCSec) {
const COFFSection &Sec) {
if (Sec.Number == -1)
return;

Expand All @@ -613,11 +612,10 @@ void WinCOFFObjectWriter::writeSection(MCAssembler &Asm,
assert(W.OS.tell() == Sec.Header.PointerToRawData &&
"Section::PointerToRawData is insane!");

uint32_t CRC = writeSectionContents(Asm, Layout, MCSec);
uint32_t CRC = writeSectionContents(Asm, Layout, *Sec.MCSection);

// Update the section definition auxiliary symbol to record the CRC.
COFFSection *Sec = SectionMap[&MCSec];
COFFSymbol::AuxiliarySymbols &AuxSyms = Sec->Symbol->Aux;
COFFSymbol::AuxiliarySymbols &AuxSyms = Sec.Symbol->Aux;
assert(AuxSyms.size() == 1 && AuxSyms[0].AuxType == ATSectionDefinition);
AuxSymbol &SecDef = AuxSyms[0];
SecDef.Aux.SectionDefinition.CheckSum = CRC;
Expand Down Expand Up @@ -1142,13 +1140,18 @@ uint64_t WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
WriteFileHeader(Header);
writeSectionHeaders();

// Write section contents.
#ifndef NDEBUG
sections::iterator I = Sections.begin();
sections::iterator IE = Sections.end();
MCAssembler::iterator J = Asm.begin();
MCAssembler::iterator JE = Asm.end();
for (; I != IE && J != JE; ++I, ++J)
writeSection(Asm, Layout, **I, *J);
assert((**I).MCSection == &*J && "Wrong bound MCSection");
#endif

// Write section contents.
for (std::unique_ptr<COFFSection> &Sec : Sections)
writeSection(Asm, Layout, *Sec);

assert(W.OS.tell() == Header.PointerToSymbolTable &&
"Header::PointerToSymbolTable is insane!");
Expand Down

0 comments on commit 01cc388

Please sign in to comment.