}
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>
}
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>
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.
protected:
InputFile(Kind K, MemoryBufferRef M);
std::vector<InputSectionBase *> Sections;
+ std::vector<SymbolBody *> Symbols;
private:
const Kind FileKind;
static std::vector<ObjFile<ELFT> *> Instances;
- ArrayRef<SymbolBody *> getSymbols();
ArrayRef<SymbolBody *> getLocalSymbols();
ObjFile(MemoryBufferRef M, StringRef ArchiveName);
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>
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;
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
private:
std::unique_ptr<Archive> File;
llvm::DenseSet<uint64_t> Seen;
- std::vector<SymbolBody *> Symbols;
};
class BitcodeFile : public InputFile {
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.