COFF: Add names for logging/debugging to COMDAT chunks.
Chunks are basically unnamed chunks of bytes, and we don't like
to give them names. However, for logging or debugging, we want to
know symbols names of functions for COMDAT chunks. (For example,
we want to print out "we have removed unreferenced COMDAT section
which contains a function FOOBAR.")
This patch is to do that.
llvm-svn: 240484
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index f2734ea..0c751e9 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -212,9 +212,14 @@
}
}
if (Chunk *C = SparseChunks[Sym.getSectionNumber()]) {
- if (C->isCOMDAT())
- return new (Alloc) DefinedCOMDAT(COFFObj.get(), Sym, C);
- return new (Alloc) DefinedRegular(COFFObj.get(), Sym, C);
+ if (!C->isCOMDAT())
+ return new (Alloc) DefinedRegular(COFFObj.get(), Sym, C);
+ auto *B = new (Alloc) DefinedCOMDAT(COFFObj.get(), Sym, C);
+ if (Sym.getValue() == 0 && !AuxP) {
+ auto *SC = reinterpret_cast<SectionChunk *>(C);
+ SC->setSymbol(B);
+ }
+ return B;
}
return nullptr;
}