Skip to content

Commit 3f2921f

Browse files
committedNov 27, 2017
COFF: Do not create SectionChunks for discarded comdat sections.
With this change, instead of creating a SectionChunk for each section in the object file, we only create them when we encounter a prevailing comdat section. Also change how symbol resolution occurs between comdat symbols. Now only the comdat leader participates in comdat resolution, and not any other external associated symbols. This is more in line with how COFF semantics are defined, and should allow for a more straightforward implementation of non-ANY comdat types. On my machine, this change reduces our runtime linking a release build of chrome_child.dll with /nopdb from 5.65s to 4.54s (median of 50 runs). Differential Revision: https://reviews.llvm.org/D40238 llvm-svn: 319090
1 parent 1f34379 commit 3f2921f

File tree

10 files changed

+238
-164
lines changed

10 files changed

+238
-164
lines changed
 

‎lld/COFF/Chunks.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ SectionChunk::SectionChunk(ObjFile *F, const coff_section *H)
3838

3939
Alignment = Header->getAlignment();
4040

41-
// Chunks may be discarded during comdat merging.
42-
Discarded = false;
43-
4441
// If linker GC is disabled, every chunk starts out alive. If linker GC is
4542
// enabled, treat non-comdat sections as roots. Generally optimized object
4643
// files will be built with -ffunction-sections or /Gy, so most things worth
@@ -362,12 +359,8 @@ bool SectionChunk::isCOMDAT() const {
362359
void SectionChunk::printDiscardedMessage() const {
363360
// Removed by dead-stripping. If it's removed by ICF, ICF already
364361
// printed out the name, so don't repeat that here.
365-
if (Sym && this == Repl) {
366-
if (Discarded)
367-
message("Discarded comdat symbol " + Sym->getName());
368-
else if (!Live)
369-
message("Discarded " + Sym->getName());
370-
}
362+
if (Sym && this == Repl)
363+
message("Discarded " + Sym->getName());
371364
}
372365

373366
StringRef SectionChunk::getDebugName() {

‎lld/COFF/Chunks.h

+5-16
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,9 @@ class SectionChunk final : public Chunk {
159159
void addAssociative(SectionChunk *Child);
160160

161161
StringRef getDebugName() override;
162-
void setSymbol(DefinedRegular *S) { if (!Sym) Sym = S; }
163162

164-
// Returns true if the chunk was not dropped by GC or COMDAT deduplication.
165-
bool isLive() { return Live && !Discarded; }
163+
// Returns true if the chunk was not dropped by GC.
164+
bool isLive() { return Live; }
166165

167166
// Used by the garbage collector.
168167
void markLive() {
@@ -171,13 +170,6 @@ class SectionChunk final : public Chunk {
171170
Live = true;
172171
}
173172

174-
// Returns true if this chunk was dropped by COMDAT deduplication.
175-
bool isDiscarded() const { return Discarded; }
176-
177-
// Used by the SymbolTable when discarding unused comdat sections. This is
178-
// redundant when GC is enabled, as all comdat sections will start out dead.
179-
void markDiscarded() { Discarded = true; }
180-
181173
// True if this is a codeview debug info chunk. These will not be laid out in
182174
// the image. Instead they will end up in the PDB, if one is requested.
183175
bool isCodeView() const {
@@ -213,24 +205,21 @@ class SectionChunk final : public Chunk {
213205
// The file that this chunk was created from.
214206
ObjFile *File;
215207

208+
// The COMDAT leader symbol if this is a COMDAT chunk.
209+
DefinedRegular *Sym = nullptr;
210+
216211
private:
217212
StringRef SectionName;
218213
std::vector<SectionChunk *> AssocChildren;
219214
llvm::iterator_range<const coff_relocation *> Relocs;
220215
size_t NumRelocs;
221216

222-
// True if this chunk was discarded because it was a duplicate comdat section.
223-
bool Discarded;
224-
225217
// Used by the garbage collector.
226218
bool Live;
227219

228220
// Used for ICF (Identical COMDAT Folding)
229221
void replace(SectionChunk *Other);
230222
uint32_t Class[2] = {0, 0};
231-
232-
// Sym points to a section symbol if this is a COMDAT chunk.
233-
DefinedRegular *Sym = nullptr;
234223
};
235224

236225
// A chunk for common symbols. Common chunks don't have actual data.

0 commit comments

Comments
 (0)