diff options
-rw-r--r-- | lld/ELF/InputFiles.cpp | 16 | ||||
-rw-r--r-- | lld/ELF/InputFiles.h | 23 | ||||
-rw-r--r-- | lld/ELF/OutputSections.cpp | 2 |
3 files changed, 17 insertions, 24 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 40793161c3a..ca110cb436f 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -162,15 +162,9 @@ ObjFile<ELFT>::ObjFile(MemoryBufferRef M, StringRef ArchiveName) } template <class ELFT> ArrayRef<SymbolBody *> ObjFile<ELFT>::getLocalSymbols() { - if (this->SymbolBodies.empty()) - return this->SymbolBodies; - return makeArrayRef(this->SymbolBodies).slice(1, this->FirstNonLocal - 1); -} - -template <class ELFT> ArrayRef<SymbolBody *> ObjFile<ELFT>::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 <class ELFT> @@ -523,9 +517,9 @@ StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &Sec) { } template <class ELFT> void ObjFile<ELFT>::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 <class ELFT> diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index ba6679f4867..75cc0587dc9 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<SymbolBody *> 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<InputSectionBase *> Sections; + std::vector<SymbolBody *> Symbols; private: const Kind FileKind; @@ -157,7 +166,6 @@ public: static std::vector<ObjFile<ELFT> *> Instances; - ArrayRef<SymbolBody *> getSymbols(); ArrayRef<SymbolBody *> 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 <typename RelT> @@ -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<SymbolBody *> SymbolBodies; - // .shstrtab contents. StringRef SectionStringTable; @@ -258,7 +263,6 @@ public: explicit ArchiveFile(std::unique_ptr<Archive> &&File); static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; } template <class ELFT> void parse(); - ArrayRef<SymbolBody *> 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<Archive> File; llvm::DenseSet<uint64_t> Seen; - std::vector<SymbolBody *> Symbols; }; class BitcodeFile : public InputFile { @@ -279,12 +282,8 @@ public: static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } template <class ELFT> void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups); - ArrayRef<SymbolBody *> getSymbols() { return Symbols; } std::unique_ptr<llvm::lto::InputFile> Obj; static std::vector<BitcodeFile *> Instances; - -private: - std::vector<SymbolBody *> Symbols; }; // .so file. diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index c4fd7f1b9c9..0e5aa32d338 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<ELFT> *Obj = Sections[0]->getFile<ELFT>(); ArrayRef<SymbolBody *> Symbols = Obj->getSymbols(); - OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info - 1]); + OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info]); } template <class ELFT> void OutputSection::finalize() { |