Index: lld/trunk/ELF/InputFiles.h =================================================================== --- lld/trunk/ELF/InputFiles.h +++ lld/trunk/ELF/InputFiles.h @@ -83,6 +83,14 @@ return Sections; } + // Returns object file symbols. It is a runtime error to call this + // function on files of other types. + ArrayRef getSymbols() { + assert(FileKind == ObjectKind || FileKind == BitcodeKind || + FileKind == ArchiveKind); + return Symbols; + } + // Filename of .a which contained this file. If this file was // not in an archive file, it is the empty string. We use this // string for creating error messages. @@ -100,6 +108,7 @@ protected: InputFile(Kind K, MemoryBufferRef M); std::vector Sections; + std::vector Symbols; private: const Kind FileKind; @@ -157,7 +166,6 @@ static std::vector *> Instances; - ArrayRef getSymbols(); ArrayRef getLocalSymbols(); ObjFile(MemoryBufferRef M, StringRef ArchiveName); @@ -166,9 +174,9 @@ InputSectionBase *getSection(const Elf_Sym &Sym) const; SymbolBody &getSymbolBody(uint32_t SymbolIndex) const { - if (SymbolIndex >= SymbolBodies.size()) + if (SymbolIndex >= this->Symbols.size()) fatal(toString(this) + ": invalid symbol index"); - return *SymbolBodies[SymbolIndex]; + return *this->Symbols[SymbolIndex]; } template @@ -204,9 +212,6 @@ bool shouldMerge(const Elf_Shdr &Sec); SymbolBody *createSymbolBody(const Elf_Sym *Sym); - // List of all symbols referenced or defined by this file. - std::vector SymbolBodies; - // .shstrtab contents. StringRef SectionStringTable; @@ -258,7 +263,6 @@ explicit ArchiveFile(std::unique_ptr &&File); static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; } template void parse(); - ArrayRef getSymbols() { return Symbols; } // Returns a memory buffer for a given symbol and the offset in the archive // for the member. An empty memory buffer and an offset of zero @@ -269,7 +273,6 @@ private: std::unique_ptr File; llvm::DenseSet Seen; - std::vector Symbols; }; class BitcodeFile : public InputFile { @@ -279,12 +282,8 @@ static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } template void parse(llvm::DenseSet &ComdatGroups); - ArrayRef getSymbols() { return Symbols; } std::unique_ptr Obj; static std::vector Instances; - -private: - std::vector Symbols; }; // .so file. Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -162,15 +162,9 @@ } template ArrayRef ObjFile::getLocalSymbols() { - if (this->SymbolBodies.empty()) - return this->SymbolBodies; - return makeArrayRef(this->SymbolBodies).slice(1, this->FirstNonLocal - 1); -} - -template ArrayRef ObjFile::getSymbols() { - if (this->SymbolBodies.empty()) - return this->SymbolBodies; - return makeArrayRef(this->SymbolBodies).slice(1); + if (this->Symbols.empty()) + return {}; + return makeArrayRef(this->Symbols).slice(1, this->FirstNonLocal - 1); } template @@ -523,9 +517,9 @@ } template void ObjFile::initializeSymbols() { - SymbolBodies.reserve(this->ELFSyms.size()); + this->Symbols.reserve(this->ELFSyms.size()); for (const Elf_Sym &Sym : this->ELFSyms) - SymbolBodies.push_back(createSymbolBody(&Sym)); + this->Symbols.push_back(createSymbolBody(&Sym)); } template Index: lld/trunk/ELF/OutputSections.cpp =================================================================== --- lld/trunk/ELF/OutputSections.cpp +++ lld/trunk/ELF/OutputSections.cpp @@ -435,7 +435,7 @@ // provides signature of the section group. ObjFile *Obj = Sections[0]->getFile(); ArrayRef Symbols = Obj->getSymbols(); - OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info - 1]); + OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info]); } template void OutputSection::finalize() {