]> granicus.if.org Git - llvm/commitdiff
Add lower level versions of some functions.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Nov 2016 16:51:44 +0000 (16:51 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Nov 2016 16:51:44 +0000 (16:51 +0000)
This adds versions of getSectionIndex, getSection and getSymbol that
instead of a Elf_Shdr take the content of that section.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285932 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h

index 998e693770d6e7029e9ed3a730bf5daf61c086d2..8391724ad941e229f14c5f5d7ab0ca77e5707509 100644 (file)
@@ -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;
@@ -229,16 +249,21 @@ ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
   return object::getSection<ELFT>(*SectionsOrErr, Index);
 }
 
+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>