COFF: Remove the SymbolBodies vector, and rename SparseSymbolBodies to Symbols.

Differential Revision: https://reviews.llvm.org/D40237

llvm-svn: 318683
This commit is contained in:
Peter Collingbourne 2017-11-20 18:52:53 +00:00
parent d01571353d
commit 80f961ab66
4 changed files with 11 additions and 18 deletions

View File

@ -172,8 +172,7 @@ void ObjFile::initializeChunks() {
void ObjFile::initializeSymbols() { void ObjFile::initializeSymbols() {
uint32_t NumSymbols = COFFObj->getNumberOfSymbols(); uint32_t NumSymbols = COFFObj->getNumberOfSymbols();
SymbolBodies.reserve(NumSymbols); Symbols.resize(NumSymbols);
SparseSymbolBodies.resize(NumSymbols);
SmallVector<std::pair<Symbol *, uint32_t>, 8> WeakAliases; SmallVector<std::pair<Symbol *, uint32_t>, 8> WeakAliases;
int32_t LastSectionNumber = 0; int32_t LastSectionNumber = 0;
@ -197,10 +196,7 @@ void ObjFile::initializeSymbols() {
} else { } else {
Sym = createDefined(COFFSym, AuxP, IsFirst); Sym = createDefined(COFFSym, AuxP, IsFirst);
} }
if (Sym) { Symbols[I] = Sym;
SymbolBodies.push_back(Sym);
SparseSymbolBodies[I] = Sym;
}
I += COFFSym.getNumberOfAuxSymbols(); I += COFFSym.getNumberOfAuxSymbols();
LastSectionNumber = COFFSym.getSectionNumber(); LastSectionNumber = COFFSym.getSectionNumber();
} }
@ -208,7 +204,7 @@ void ObjFile::initializeSymbols() {
for (auto &KV : WeakAliases) { for (auto &KV : WeakAliases) {
Symbol *Sym = KV.first; Symbol *Sym = KV.first;
uint32_t Idx = KV.second; uint32_t Idx = KV.second;
checkAndSetWeakAlias(Symtab, this, Sym, SparseSymbolBodies[Idx]); checkAndSetWeakAlias(Symtab, this, Sym, Symbols[Idx]);
} }
} }
@ -301,7 +297,7 @@ void ObjFile::initializeSEH() {
auto *I = reinterpret_cast<const ulittle32_t *>(A.data()); auto *I = reinterpret_cast<const ulittle32_t *>(A.data());
auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size()); auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size());
for (; I != E; ++I) for (; I != E; ++I)
SEHandlers.insert(SparseSymbolBodies[*I]); SEHandlers.insert(Symbols[*I]);
} }
MachineTypes ObjFile::getMachineType() { MachineTypes ObjFile::getMachineType() {

View File

@ -110,12 +110,12 @@ public:
MachineTypes getMachineType() override; MachineTypes getMachineType() override;
std::vector<Chunk *> &getChunks() { return Chunks; } std::vector<Chunk *> &getChunks() { return Chunks; }
std::vector<SectionChunk *> &getDebugChunks() { return DebugChunks; } std::vector<SectionChunk *> &getDebugChunks() { return DebugChunks; }
std::vector<Symbol *> &getSymbols() { return SymbolBodies; } std::vector<Symbol *> &getSymbols() { return Symbols; }
// Returns a Symbol object for the SymbolIndex'th symbol in the // Returns a Symbol object for the SymbolIndex'th symbol in the
// underlying object file. // underlying object file.
Symbol *getSymbol(uint32_t SymbolIndex) { Symbol *getSymbol(uint32_t SymbolIndex) {
return SparseSymbolBodies[SymbolIndex]; return Symbols[SymbolIndex];
} }
// Returns the underying COFF file. // Returns the underying COFF file.
@ -162,14 +162,11 @@ private:
// null pointer.) // null pointer.)
std::vector<SectionChunk *> SparseChunks; std::vector<SectionChunk *> SparseChunks;
// List of all symbols referenced or defined by this file. // This vector contains a list of all symbols defined or referenced by this
std::vector<Symbol *> SymbolBodies; // file. They are indexed such that you can get a Symbol by symbol
// This vector contains the same symbols as SymbolBodies, but they
// are indexed such that you can get a Symbol by symbol
// index. Nonexistent indices (which are occupied by auxiliary // index. Nonexistent indices (which are occupied by auxiliary
// symbols in the real symbol table) are filled with null pointers. // symbols in the real symbol table) are filled with null pointers.
std::vector<Symbol *> SparseSymbolBodies; std::vector<Symbol *> Symbols;
}; };
// This type represents import library members that contain DLL names // This type represents import library members that contain DLL names

View File

@ -50,7 +50,7 @@ static std::vector<DefinedRegular *> getSymbols() {
std::vector<DefinedRegular *> V; std::vector<DefinedRegular *> V;
for (ObjFile *File : ObjFile::Instances) for (ObjFile *File : ObjFile::Instances)
for (Symbol *B : File->getSymbols()) for (Symbol *B : File->getSymbols())
if (auto *Sym = dyn_cast<DefinedRegular>(B)) if (auto *Sym = dyn_cast_or_null<DefinedRegular>(B))
if (Sym && !Sym->getCOFFSymbol().isSectionDefinition()) if (Sym && !Sym->getCOFFSymbol().isSectionDefinition())
V.push_back(Sym); V.push_back(Sym);
return V; return V;

View File

@ -148,7 +148,7 @@ void SymbolTable::reportRemainingUndefines() {
for (ObjFile *File : ObjFile::Instances) for (ObjFile *File : ObjFile::Instances)
for (Symbol *Sym : File->getSymbols()) for (Symbol *Sym : File->getSymbols())
if (Undefs.count(Sym)) if (Sym && Undefs.count(Sym))
errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName()); errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName());
} }