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
This commit is contained in:
parent
0d2e999050
commit
6a60be7749
|
|
@ -145,22 +145,8 @@ bool SectionChunk::isCOMDAT() const {
|
|||
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 @@ SectionRef SectionChunk::getSectionRef() {
|
|||
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.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ using llvm::object::coff_section;
|
|||
using llvm::sys::fs::file_magic;
|
||||
|
||||
class Defined;
|
||||
class DefinedCOMDAT;
|
||||
class DefinedImportData;
|
||||
class ObjectFile;
|
||||
class OutputSection;
|
||||
|
|
@ -96,6 +97,10 @@ public:
|
|||
// Collect all locations that contain absolute addresses for base relocations.
|
||||
virtual void getBaserels(std::vector<uint32_t> *Res, Defined *ImageBase) {}
|
||||
|
||||
// Returns a human-readable name of this chunk. Chunks are unnamed chunks of
|
||||
// bytes, so this is used only for logging or debugging.
|
||||
virtual StringRef getDebugName() { return ""; }
|
||||
|
||||
protected:
|
||||
// The RVA of this chunk in the output. The writer sets a value.
|
||||
uint64_t RVA = 0;
|
||||
|
|
@ -133,6 +138,9 @@ public:
|
|||
// and its children are treated as a group by the garbage collector.
|
||||
void addAssociative(SectionChunk *Child);
|
||||
|
||||
StringRef getDebugName() override;
|
||||
void setSymbol(DefinedCOMDAT *S) { if (!Sym) Sym = S; }
|
||||
|
||||
private:
|
||||
void mark() override;
|
||||
SectionRef getSectionRef();
|
||||
|
|
@ -145,6 +153,10 @@ private:
|
|||
uint32_t SectionIndex;
|
||||
StringRef SectionName;
|
||||
std::vector<Chunk *> AssocChildren;
|
||||
|
||||
// Chunks are basically unnamed chunks of bytes.
|
||||
// Symbols are associated for debugging and logging purposs only.
|
||||
DefinedCOMDAT *Sym = nullptr;
|
||||
};
|
||||
|
||||
// A chunk for common symbols. Common chunks don't have actual data.
|
||||
|
|
|
|||
|
|
@ -212,9 +212,14 @@ SymbolBody *ObjectFile::createSymbolBody(COFFSymbolRef Sym, const void *AuxP,
|
|||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue