[lld] r361573 - [COFF] Remove finalizeContents virtual method from Chunk, NFC

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 17:02:00 PDT 2019


Author: rnk
Date: Thu May 23 17:02:00 2019
New Revision: 361573

URL: http://llvm.org/viewvc/llvm-project?rev=361573&view=rev
Log:
[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.

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/COFF/Chunks.h
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=361573&r1=361572&r2=361573&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Thu May 23 17:02:00 2019
@@ -873,14 +873,15 @@ void MergeChunk::addSection(SectionChunk
 }
 
 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;

Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=361573&r1=361572&r2=361573&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Thu May 23 17:02:00 2019
@@ -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"; }

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=361573&r1=361572&r2=361573&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Thu May 23 17:02:00 2019
@@ -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() {




More information about the llvm-commits mailing list