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/Chunks.cpp b/lld/COFF/Chunks.cpp
index 18963f2..b931d11 100644
--- a/lld/COFF/Chunks.cpp
+++ b/lld/COFF/Chunks.cpp
@@ -145,22 +145,8 @@
return Header->Characteristics & IMAGE_SCN_LNK_COMDAT;
}
-// Prints "Discarded <symbol>" for all external function symbols.
void SectionChunk::printDiscardedMessage() {
- uint32_t E = File->getCOFFObj()->getNumberOfSymbols();
- for (uint32_t I = 0; I < E; ++I) {
- auto SrefOrErr = File->getCOFFObj()->getSymbol(I);
- COFFSymbolRef Sym = SrefOrErr.get();
- if (uint32_t(Sym.getSectionNumber()) != SectionIndex)
- continue;
- if (!Sym.isFunctionDefinition())
- continue;
- StringRef SymbolName;
- File->getCOFFObj()->getSymbolName(Sym, SymbolName);
- llvm::outs() << "Discarded " << SymbolName << " from "
- << File->getShortName() << "\n";
- I += Sym.getNumberOfAuxSymbols();
- }
+ llvm::dbgs() << "Discarded " << Sym->getName() << "\n";
}
SectionRef SectionChunk::getSectionRef() {
@@ -169,6 +155,10 @@
return SectionRef(Ref, File->getCOFFObj());
}
+StringRef SectionChunk::getDebugName() {
+ return Sym->getName();
+}
+
CommonChunk::CommonChunk(const COFFSymbolRef S) : Sym(S) {
// Common symbols are aligned on natural boundaries up to 32 bytes.
// This is what MSVC link.exe does.