From: Rafael Espindola Date: Fri, 26 Jun 2015 18:42:17 +0000 (+0000) Subject: Fix error handling in getString and simplify callers. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=aaaa38cb955ea2ab1c60ade6f5288e49dbfd6b48 Fix error handling in getString and simplify callers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240810 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index a9bee0ac77c..e0aefe2f348 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -304,7 +304,7 @@ public: const T *getEntry(uint32_t Section, uint32_t Entry) const; template const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const; - const char *getString(const Elf_Shdr *section, uint32_t offset) const; + ErrorOr getString(const Elf_Shdr *Section, uint32_t Offset) const; const char *getDynamicString(uintX_t Offset) const; ErrorOr getSymbolVersion(const Elf_Shdr *section, const Elf_Sym *Symb, @@ -934,13 +934,12 @@ ELFFile::getSection(uint32_t index) const { } template -const char *ELFFile::getString(const Elf_Shdr *section, - ELF::Elf32_Word offset) const { - assert(section && section->sh_type == ELF::SHT_STRTAB && "Invalid section!"); - if (offset >= section->sh_size) - // FIXME: Proper error handling. - report_fatal_error("Symbol name offset outside of string table!"); - return (const char *)base() + section->sh_offset + offset; +ErrorOr ELFFile::getString(const Elf_Shdr *Section, + ELF::Elf32_Word Offset) const { + assert(Section && Section->sh_type == ELF::SHT_STRTAB && "Invalid section!"); + if (Offset >= Section->sh_size) + return object_error::parse_failed; + return StringRef((const char *)base() + Section->sh_offset + Offset); } template @@ -969,21 +968,14 @@ ELFFile::getStaticSymbolName(const Elf_Sym *Symb) const { template ErrorOr ELFFile::getSymbolName(const Elf_Shdr *Section, const Elf_Sym *Symb) const { - if (Symb->st_name == 0) - return StringRef(""); - const Elf_Shdr *StrTab = getSection(Section->sh_link); - if (Symb->st_name >= StrTab->sh_size) - return object_error::parse_failed; - return StringRef(getString(StrTab, Symb->st_name)); + return getString(StrTab, Symb->st_name); } template ErrorOr ELFFile::getSectionName(const Elf_Shdr *Section) const { - if (Section->sh_name >= dot_shstrtab_sec->sh_size) - return object_error::parse_failed; - return StringRef(getString(dot_shstrtab_sec, Section->sh_name)); + return getString(dot_shstrtab_sec, Section->sh_name); } template