[lld] r243700 - COFF: Handle all COMDAT sections as non-GC root.

Rui Ueyama ruiu at google.com
Thu Jul 30 15:48:45 PDT 2015


Author: ruiu
Date: Thu Jul 30 17:48:45 2015
New Revision: 243700

URL: http://llvm.org/viewvc/llvm-project?rev=243700&view=rev
Log:
COFF: Handle all COMDAT sections as non-GC root.

I don't remember why I thought that only functions are subject
of garbage collection, but the comment here said so, which is
not correct. Moreover, the code just below the comment does not
do what the comment says -- it handles non-COMDAT, non-function
sections as GC root. As a result, it just handles non-COMDAT
sections as GC root.

This patch cleans that up by removing SectionChunk::isRoot and
use isCOMDAT instead.

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=243700&r1=243699&r2=243700&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Thu Jul 30 17:48:45 2015
@@ -39,10 +39,6 @@ SectionChunk::SectionChunk(ObjectFile *F
   unsigned Shift = (Header->Characteristics >> 20) & 0xF;
   if (Shift > 0)
     Align = uint32_t(1) << (Shift - 1);
-
-  // COMDAT sections are not GC root. Non-text sections are not
-  // subject of garbage collection (thus they are root).
-  Root = !isCOMDAT() && !(Header->Characteristics & IMAGE_SCN_CNT_CODE);
 }
 
 static void add16(uint8_t *P, int16_t V) { write16le(P, read16le(P) + V); }
@@ -150,9 +146,6 @@ void SectionChunk::writeTo(uint8_t *Buf)
 
 void SectionChunk::addAssociative(SectionChunk *Child) {
   AssocChildren.push_back(Child);
-  // Associative sections are live if their parent COMDATs are live,
-  // and vice versa, so they are not considered live by themselves.
-  Child->Root = false;
 }
 
 static uint8_t getBaserelType(const coff_relocation &Rel) {

Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=243700&r1=243699&r2=243700&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Thu Jul 30 17:48:45 2015
@@ -153,7 +153,6 @@ public:
   void setSymbol(DefinedRegular *S) { if (!Sym) Sym = S; }
 
   // Used by the garbage collector.
-  bool isRoot() { return Root; }
   bool isLive() { return Live; }
   void markLive() {
     assert(!Live && "Cannot mark an already live section!");
@@ -194,7 +193,6 @@ private:
 
   // Used by the garbage collector.
   bool Live = false;
-  bool Root;
 
   // Chunks are basically unnamed chunks of bytes.
   // Symbols are associated for debugging and logging purposs only.

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=243700&r1=243699&r2=243700&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Thu Jul 30 17:48:45 2015
@@ -132,7 +132,7 @@ void Writer::markLive() {
   }
   for (Chunk *C : Symtab->getChunks()) {
     auto *SC = dyn_cast<SectionChunk>(C);
-    if (!SC || !SC->isRoot() || SC->isLive())
+    if (!SC || SC->isCOMDAT() || SC->isLive())
       continue;
     SC->markLive();
     Worklist.push_back(SC);





More information about the llvm-commits mailing list