Index: lld/COFF/Chunks.h =================================================================== --- lld/COFF/Chunks.h +++ lld/COFF/Chunks.h @@ -47,7 +47,7 @@ // doesn't even have actual data (if common or bss). class Chunk { public: - enum Kind { SectionKind, OtherKind }; + enum Kind : uint8_t { SectionKind, OtherKind }; Kind kind() const { return ChunkKind; } virtual ~Chunk() = default; @@ -92,10 +92,33 @@ // bytes, so this is used only for logging or debugging. virtual StringRef getDebugName() { return ""; } + // Returns true if the chunk was not dropped by GC or COMDAT deduplication. + bool isLive() { return Live && !Discarded; } + + // Used by the garbage collector. + void markLive() { + assert(Config->DoGC && "should only mark things live from GC"); + assert(!isLive() && "Cannot mark an already live section!"); + Live = true; + } + + // Returns true if this chunk was dropped by COMDAT deduplication. + bool isDiscarded() const { return Discarded; } + + // Used by the SymbolTable when discarding unused comdat sections. This is + // redundant when GC is enabled, as all comdat sections will start out dead. + void markDiscarded() { Discarded = true; } + protected: Chunk(Kind K = OtherKind) : ChunkKind(K) {} const Kind ChunkKind; + // True if this chunk was discarded because it was a duplicate comdat section. + bool Discarded; + + // Used by the garbage collector. + bool Live; + // The alignment of this chunk. The writer uses the value. uint32_t Align = 1; @@ -155,28 +178,11 @@ // Adds COMDAT associative sections to this COMDAT section. A chunk // and its children are treated as a group by the garbage collector. - void addAssociative(SectionChunk *Child); + void addAssociative(Chunk *Child); StringRef getDebugName() override; void setSymbol(DefinedRegular *S) { if (!Sym) Sym = S; } - // Returns true if the chunk was not dropped by GC or COMDAT deduplication. - bool isLive() { return Live && !Discarded; } - - // Used by the garbage collector. - void markLive() { - assert(Config->DoGC && "should only mark things live from GC"); - assert(!isLive() && "Cannot mark an already live section!"); - Live = true; - } - - // Returns true if this chunk was dropped by COMDAT deduplication. - bool isDiscarded() const { return Discarded; } - - // Used by the SymbolTable when discarding unused comdat sections. This is - // redundant when GC is enabled, as all comdat sections will start out dead. - void markDiscarded() { Discarded = true; } - // True if this is a codeview debug info chunk. These will not be laid out in // the image. Instead they will end up in the PDB, if one is requested. bool isCodeView() const { @@ -190,7 +196,7 @@ } // Allow iteration over the associated child chunks for this section. - ArrayRef children() const { return AssocChildren; } + ArrayRef children() const { return AssocChildren; } // A pointer pointing to a replacement for this chunk. // Initially it points to "this" object. If this chunk is merged @@ -209,16 +215,10 @@ private: StringRef SectionName; - std::vector AssocChildren; + std::vector AssocChildren; llvm::iterator_range Relocs; size_t NumRelocs; - // True if this chunk was discarded because it was a duplicate comdat section. - bool Discarded; - - // Used by the garbage collector. - bool Live; - // Used for ICF (Identical COMDAT Folding) void replace(SectionChunk *Other); uint32_t Class[2] = {0, 0}; Index: lld/COFF/Chunks.cpp =================================================================== --- lld/COFF/Chunks.cpp +++ lld/COFF/Chunks.cpp @@ -176,7 +176,7 @@ } } -void SectionChunk::addAssociative(SectionChunk *Child) { +void SectionChunk::addAssociative(Chunk *Child) { AssocChildren.push_back(Child); } Index: lld/COFF/MarkLive.cpp =================================================================== --- lld/COFF/MarkLive.cpp +++ lld/COFF/MarkLive.cpp @@ -59,8 +59,9 @@ AddSym(B); // Mark associative sections if any. - for (SectionChunk *C : SC->children()) - Enqueue(C); + for (Chunk *C : SC->children()) + if (auto *SC = dyn_cast(C)) + Enqueue(SC); } } Index: lld/COFF/SymbolTable.cpp =================================================================== --- lld/COFF/SymbolTable.cpp +++ lld/COFF/SymbolTable.cpp @@ -248,7 +248,7 @@ C->markDiscarded(); // Discard associative chunks that we've parsed so far. No need to recurse // because an associative section cannot have children. - for (SectionChunk *Child : C->children()) + for (Chunk *Child : C->children()) Child->markDiscarded(); } return S;