From a7616cd14c243957d674b0444e50f5d43152f803 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 23 Jul 2015 12:49:40 +0000 Subject: [PATCH] Add a version of getSymbol with an explicit symbol table. Use it. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243011 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 14 +++++++------- tools/obj2yaml/elf2yaml.cpp | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 22d14db4c13..2c3d841553e 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -268,7 +268,13 @@ public: const Elf_Ehdr *getHeader() const { return Header; } ErrorOr getSection(const Elf_Sym *symb) const; ErrorOr getSection(uint32_t Index) const; - const Elf_Sym *getSymbol(uint32_t index) const; + + const Elf_Sym *getSymbol(const Elf_Shdr *Sec, uint32_t Index) const { + return &*(symbol_begin(Sec) + Index); + } + const Elf_Sym *getSymbol(uint32_t Index) const { + return getSymbol(dot_symtab_sec, Index); + } ErrorOr getSectionName(const Elf_Shdr *Section) const; ErrorOr > getSectionContents(const Elf_Shdr *Sec) const; @@ -379,12 +385,6 @@ ELFFile::getSection(const Elf_Sym *symb) const { } template -const typename ELFFile::Elf_Sym * -ELFFile::getSymbol(uint32_t Index) const { - return &*(symbol_begin() + Index); -} - -template ErrorOr > ELFFile::getSectionContents(const Elf_Shdr *Sec) const { if (Sec->sh_offset + Sec->sh_size > Buf.size()) diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index def3981eae1..212e911452f 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -338,11 +338,12 @@ ErrorOr ELFDumper::dumpGroup(const Elf_Shdr *Shdr) { if (std::error_code EC = dumpCommonSection(Shdr, *S)) return EC; // Get sh_info which is the signature. - const Elf_Sym *symbol = Obj.getSymbol(Shdr->sh_info); - ErrorOr Symtab = Obj.getSection(Shdr->sh_link); - if (std::error_code EC = Symtab.getError()) + ErrorOr SymtabOrErr = Obj.getSection(Shdr->sh_link); + if (std::error_code EC = SymtabOrErr.getError()) return EC; - ErrorOr StrTabSec = Obj.getSection((*Symtab)->sh_link); + const Elf_Shdr *Symtab = *SymtabOrErr; + const Elf_Sym *symbol = Obj.getSymbol(Symtab, Shdr->sh_info); + ErrorOr StrTabSec = Obj.getSection(Symtab->sh_link); if (std::error_code EC = StrTabSec.getError()) return EC; ErrorOr StrTabOrErr = Obj.getStringTable(*StrTabSec); -- 2.11.0