From 11c141eb68531eec30af8ff8f82b8159de99e555 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 24 May 2019 00:02:00 +0000 Subject: [PATCH] [COFF] Remove finalizeContents virtual method from Chunk, NFC This only needs to be done for MergeChunks, so just do that in a separate pass in the Writer. This is one small step towards eliminating the vtable in Chunk. llvm-svn: 361573 --- lld/COFF/Chunks.cpp | 15 ++++++++------- lld/COFF/Chunks.h | 7 ++----- lld/COFF/Writer.cpp | 13 ++++++++++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 76b0c8301b90..b016ac1e86d3 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -873,14 +873,15 @@ void MergeChunk::addSection(SectionChunk *C) { } void MergeChunk::finalizeContents() { - if (!Finalized) { - for (SectionChunk *C : Sections) - if (C->Live) - Builder.add(toStringRef(C->getContents())); - Builder.finalize(); - Finalized = true; - } + assert(!Finalized && "should only finalize once"); + for (SectionChunk *C : Sections) + if (C->Live) + Builder.add(toStringRef(C->getContents())); + Builder.finalize(); + Finalized = true; +} +void MergeChunk::assignSubsectionRVAs() { for (SectionChunk *C : Sections) { if (!C->Live) continue; diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h index d15638e7b0cc..672003b31f98 100644 --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -78,10 +78,6 @@ public: // before calling this function. virtual void writeTo(uint8_t *Buf) const {} - // Called by the writer after an RVA is assigned, but before calling - // getSize(). - virtual void finalizeContents() {} - // The writer sets and uses the addresses. In practice, PE images cannot be // larger than 2GB. Chunks are always laid as part of the image, so Chunk RVAs // can be stored with 32 bits. @@ -320,7 +316,8 @@ class MergeChunk : public Chunk { public: MergeChunk(uint32_t Alignment); static void addSection(SectionChunk *C); - void finalizeContents() override; + void finalizeContents(); + void assignSubsectionRVAs(); uint32_t getOutputCharacteristics() const override; StringRef getSectionName() const override { return ".rdata"; } diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index f629715fbd2a..d673fc8de852 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -865,9 +865,12 @@ void Writer::createSections() { } void Writer::createMiscChunks() { - for (MergeChunk *P : MergeChunk::Instances) - if (P) + for (MergeChunk *P : MergeChunk::Instances) { + if (P) { + P->finalizeContents(); RdataSec->addChunk(P); + } + } // Create thunks for locally-dllimported symbols. if (!Symtab->LocalImportChunks.empty()) { @@ -1162,7 +1165,6 @@ void Writer::assignAddresses() { VirtualSize += Padding; VirtualSize = alignTo(VirtualSize, C->getAlignment()); C->setRVA(RVA + VirtualSize); - C->finalizeContents(); VirtualSize += C->getSize(); if (C->hasData()) RawSize = alignTo(VirtualSize, SectorSize); @@ -1177,6 +1179,11 @@ void Writer::assignAddresses() { FileSize += alignTo(RawSize, SectorSize); } SizeOfImage = alignTo(RVA, PageSize); + + // Assign addresses to sections in MergeChunks. + for (MergeChunk *MC : MergeChunk::Instances) + if (MC) + MC->assignSubsectionRVAs(); } template void Writer::writeHeader() {