void ObjFile::initializeSymbols() {
uint32_t NumSymbols = COFFObj->getNumberOfSymbols();
- SymbolBodies.reserve(NumSymbols);
- SparseSymbolBodies.resize(NumSymbols);
+ Symbols.resize(NumSymbols);
SmallVector<std::pair<Symbol *, uint32_t>, 8> WeakAliases;
int32_t LastSectionNumber = 0;
} else {
Sym = createDefined(COFFSym, AuxP, IsFirst);
}
- if (Sym) {
- SymbolBodies.push_back(Sym);
- SparseSymbolBodies[I] = Sym;
- }
+ Symbols[I] = Sym;
I += COFFSym.getNumberOfAuxSymbols();
LastSectionNumber = COFFSym.getSectionNumber();
}
for (auto &KV : WeakAliases) {
Symbol *Sym = KV.first;
uint32_t Idx = KV.second;
- checkAndSetWeakAlias(Symtab, this, Sym, SparseSymbolBodies[Idx]);
+ checkAndSetWeakAlias(Symtab, this, Sym, Symbols[Idx]);
}
}
auto *I = reinterpret_cast<const ulittle32_t *>(A.data());
auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size());
for (; I != E; ++I)
- SEHandlers.insert(SparseSymbolBodies[*I]);
+ SEHandlers.insert(Symbols[*I]);
}
MachineTypes ObjFile::getMachineType() {
MachineTypes getMachineType() override;
std::vector<Chunk *> &getChunks() { return Chunks; }
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
// underlying object file.
Symbol *getSymbol(uint32_t SymbolIndex) {
- return SparseSymbolBodies[SymbolIndex];
+ return Symbols[SymbolIndex];
}
// Returns the underying COFF file.
// null pointer.)
std::vector<SectionChunk *> SparseChunks;
- // List of all symbols referenced or defined by this file.
- std::vector<Symbol *> SymbolBodies;
-
- // This vector contains the same symbols as SymbolBodies, but they
- // are indexed such that you can get a Symbol by symbol
+ // This vector contains a list of all symbols defined or referenced by this
+ // file. They are indexed such that you can get a Symbol by symbol
// index. Nonexistent indices (which are occupied by auxiliary
// 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
std::vector<DefinedRegular *> V;
for (ObjFile *File : ObjFile::Instances)
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())
V.push_back(Sym);
return V;
for (ObjFile *File : ObjFile::Instances)
for (Symbol *Sym : File->getSymbols())
- if (Undefs.count(Sym))
+ if (Sym && Undefs.count(Sym))
errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName());
}