From: George Rimar Date: Fri, 4 Aug 2017 11:07:42 +0000 (+0000) Subject: [ELF] - Move getSymbols() methods to InputFile. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=70ecb827b48957a6aeb3fe72930e824693a48c91;p=platform%2Fupstream%2Fllvm.git [ELF] - Move getSymbols() methods to InputFile. It can help to detemplate code. Differential revision: https://reviews.llvm.org/D35936 llvm-svn: 310049 --- diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 4079316..ca110cb 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -162,15 +162,9 @@ ObjFile::ObjFile(MemoryBufferRef M, StringRef ArchiveName) } 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 @@ StringRef ObjFile::getSectionName(const Elf_Shdr &Sec) { } 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 diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index ba6679f..75cc058 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -83,6 +83,14 @@ public: 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 @@ public: protected: InputFile(Kind K, MemoryBufferRef M); std::vector Sections; + std::vector Symbols; private: const Kind FileKind; @@ -157,7 +166,6 @@ public: static std::vector *> Instances; - ArrayRef getSymbols(); ArrayRef getLocalSymbols(); ObjFile(MemoryBufferRef M, StringRef ArchiveName); @@ -166,9 +174,9 @@ public: 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 @@ private: 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 @@ public: 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 @@ public: private: std::unique_ptr File; llvm::DenseSet Seen; - std::vector Symbols; }; class BitcodeFile : public InputFile { @@ -279,12 +282,8 @@ public: 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. diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index c4fd7f1..0e5aa32 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -435,7 +435,7 @@ static void finalizeShtGroup(OutputSection *OS, // 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() {