Index: lld/trunk/COFF/InputFiles.h =================================================================== --- lld/trunk/COFF/InputFiles.h +++ lld/trunk/COFF/InputFiles.h @@ -110,12 +110,12 @@ MachineTypes getMachineType() override; std::vector &getChunks() { return Chunks; } std::vector &getDebugChunks() { return DebugChunks; } - std::vector &getSymbols() { return SymbolBodies; } + std::vector &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. @@ -162,14 +162,11 @@ // null pointer.) std::vector SparseChunks; - // List of all symbols referenced or defined by this file. - std::vector 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 SparseSymbolBodies; + std::vector Symbols; }; // This type represents import library members that contain DLL names Index: lld/trunk/COFF/InputFiles.cpp =================================================================== --- lld/trunk/COFF/InputFiles.cpp +++ lld/trunk/COFF/InputFiles.cpp @@ -172,8 +172,7 @@ void ObjFile::initializeSymbols() { uint32_t NumSymbols = COFFObj->getNumberOfSymbols(); - SymbolBodies.reserve(NumSymbols); - SparseSymbolBodies.resize(NumSymbols); + Symbols.resize(NumSymbols); SmallVector, 8> WeakAliases; int32_t LastSectionNumber = 0; @@ -197,10 +196,7 @@ } else { Sym = createDefined(COFFSym, AuxP, IsFirst); } - if (Sym) { - SymbolBodies.push_back(Sym); - SparseSymbolBodies[I] = Sym; - } + Symbols[I] = Sym; I += COFFSym.getNumberOfAuxSymbols(); LastSectionNumber = COFFSym.getSectionNumber(); } @@ -208,7 +204,7 @@ 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]); } } @@ -301,7 +297,7 @@ auto *I = reinterpret_cast(A.data()); auto *E = reinterpret_cast(A.data() + A.size()); for (; I != E; ++I) - SEHandlers.insert(SparseSymbolBodies[*I]); + SEHandlers.insert(Symbols[*I]); } MachineTypes ObjFile::getMachineType() { Index: lld/trunk/COFF/MapFile.cpp =================================================================== --- lld/trunk/COFF/MapFile.cpp +++ lld/trunk/COFF/MapFile.cpp @@ -50,7 +50,7 @@ std::vector V; for (ObjFile *File : ObjFile::Instances) for (Symbol *B : File->getSymbols()) - if (auto *Sym = dyn_cast(B)) + if (auto *Sym = dyn_cast_or_null(B)) if (Sym && !Sym->getCOFFSymbol().isSectionDefinition()) V.push_back(Sym); return V; Index: lld/trunk/COFF/SymbolTable.cpp =================================================================== --- lld/trunk/COFF/SymbolTable.cpp +++ lld/trunk/COFF/SymbolTable.cpp @@ -148,7 +148,7 @@ 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()); }