diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-11-03 16:51:44 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-11-03 16:51:44 +0000 |
| commit | 2a6eb47202b66fe0526e8eb174e94ce30e915dea (patch) | |
| tree | 6a5d57cd2a1f916d25bd09792781f81a720b4c38 /llvm/include | |
| parent | a1f241d1c33c1c10e57521f99ec8e712a807c96b (diff) | |
| download | bcm5719-llvm-2a6eb47202b66fe0526e8eb174e94ce30e915dea.tar.gz bcm5719-llvm-2a6eb47202b66fe0526e8eb174e94ce30e915dea.zip | |
Add lower level versions of some functions.
This adds versions of getSectionIndex, getSection and getSymbol that
instead of a Elf_Shdr take the content of that section.
llvm-svn: 285932
Diffstat (limited to 'llvm/include')
| -rw-r--r-- | llvm/include/llvm/Object/ELF.h | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h index 998e693770d..8391724ad94 100644 --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -150,9 +150,13 @@ public: const Elf_Ehdr *getHeader() const { return Header; } ErrorOr<uint32_t> getSectionIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef<Elf_Word> ShndxTable) const; + ErrorOr<uint32_t> getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms, + ArrayRef<Elf_Word> ShndxTable) const; ErrorOr<const Elf_Shdr *> getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef<Elf_Word> ShndxTable) const; + ErrorOr<const Elf_Shdr *> getSection(const Elf_Sym *Sym, Elf_Sym_Range Symtab, + ArrayRef<Elf_Word> ShndxTable) const; ErrorOr<const Elf_Shdr *> getSection(uint32_t Index) const; ErrorOr<const Elf_Sym *> getSymbol(const Elf_Shdr *Sec, @@ -199,11 +203,17 @@ ELFFile<ELFT>::getSectionIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab, auto SymsOrErr = symbols(SymTab); if (std::error_code EC = SymsOrErr.getError()) return EC; + return getSectionIndex(Sym, *SymsOrErr, ShndxTable); +} +template <class ELFT> +ErrorOr<uint32_t> +ELFFile<ELFT>::getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms, + ArrayRef<Elf_Word> ShndxTable) const { uint32_t Index = Sym->st_shndx; if (Index == ELF::SHN_XINDEX) { auto ErrorOrIndex = object::getExtendedSymbolTableIndex<ELFT>( - Sym, SymsOrErr->begin(), ShndxTable); + Sym, Syms.begin(), ShndxTable); if (std::error_code EC = ErrorOrIndex.getError()) return EC; return *ErrorOrIndex; @@ -217,7 +227,17 @@ template <class ELFT> ErrorOr<const typename ELFT::Shdr *> ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef<Elf_Word> ShndxTable) const { - ErrorOr<uint32_t> IndexOrErr = getSectionIndex(Sym, SymTab, ShndxTable); + auto SymsOrErr = symbols(SymTab); + if (std::error_code EC = SymsOrErr.getError()) + return EC; + return getSection(Sym, *SymsOrErr, ShndxTable); +} + +template <class ELFT> +ErrorOr<const typename ELFT::Shdr *> +ELFFile<ELFT>::getSection(const Elf_Sym *Sym, Elf_Sym_Range Symbols, + ArrayRef<Elf_Word> ShndxTable) const { + ErrorOr<uint32_t> IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable); if (std::error_code EC = IndexOrErr.getError()) return EC; uint32_t Index = *IndexOrErr; @@ -230,15 +250,20 @@ ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, } template <class ELFT> +inline ErrorOr<const typename ELFT::Sym *> +getSymbol(typename ELFT::SymRange Symbols, uint32_t Index) { + if (Index >= Symbols.size()) + return object_error::invalid_symbol_index; + return &Symbols[Index]; +} + +template <class ELFT> ErrorOr<const typename ELFT::Sym *> ELFFile<ELFT>::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const { auto SymtabOrErr = symbols(Sec); if (std::error_code EC = SymtabOrErr.getError()) return EC; - Elf_Sym_Range Symbols = *SymtabOrErr; - if (Index >= Symbols.size()) - return object_error::invalid_symbol_index; - return &Symbols[Index]; + return object::getSymbol<ELFT>(*SymtabOrErr, Index); } template <class ELFT> |

