From: Rafael Espindola Date: Thu, 3 Nov 2016 02:24:59 +0000 (+0000) Subject: Split getSection in two. X-Git-Tag: llvmorg-4.0.0-rc1~5575 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=203ff0d3c953f4802c6a89376991457b43ad099c;p=platform%2Fupstream%2Fllvm.git Split getSection in two. This will allow avoiding repeated error checking in a few cases. llvm-svn: 285874 --- diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h index b23ec6c..71f30ab 100644 --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -179,6 +179,14 @@ typedef ELFFile> ELF32BEFile; typedef ELFFile> ELF64BEFile; template +inline ErrorOr +getSection(typename ELFT::ShdrRange Sections, uint32_t Index) { + if (Index >= Sections.size()) + return object_error::invalid_section_index; + return &Sections[Index]; +} + +template uint32_t ELFFile::getExtendedSymbolTableIndex( const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef ShndxTable) const { @@ -202,12 +210,17 @@ ErrorOr ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef ShndxTable) const { uint32_t Index = Sym->st_shndx; + if (Index == ELF::SHN_UNDEF || + (Index >= ELF::SHN_LORESERVE && Index != ELF::SHN_XINDEX)) + return nullptr; + if (Index == ELF::SHN_XINDEX) - return getSection(getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable)); + Index = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable); - if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE) - return nullptr; - return getSection(Sym->st_shndx); + auto SectionsOrErr = sections(); + if (std::error_code EC = SectionsOrErr.getError()) + return EC; + return object::getSection(*SectionsOrErr, Index); } template @@ -387,10 +400,7 @@ ELFFile::getSection(uint32_t Index) const { auto TableOrErr = sections(); if (std::error_code EC = TableOrErr.getError()) return EC; - ArrayRef Table = *TableOrErr; - if (Index >= Table.size()) - return object_error::invalid_section_index; - return &Table[Index]; + return object::getSection(*TableOrErr, Index); } template