[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
This commit is contained in:
Reid Kleckner 2019-05-24 00:02:00 +00:00
parent ae02e89448
commit 11c141eb68
3 changed files with 20 additions and 15 deletions

View File

@ -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;

View File

@ -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"; }

View File

@ -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 <typename PEHeaderTy> void Writer::writeHeader() {