From: Rafael Espindola Date: Thu, 3 Nov 2016 14:24:53 +0000 (+0000) Subject: Split out a getSectionIndex. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58c4c962e29fa0afd88d74abcdaf1d987d9fdea7;p=llvm Split out a getSectionIndex. That code is currently duplicated in lld. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285915 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 9420b1e7bd5..27cd7145a3e 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -154,6 +154,8 @@ public: getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Sym *FirstSym, ArrayRef ShndxTable) const; const Elf_Ehdr *getHeader() const { return Header; } + ErrorOr getSectionIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab, + ArrayRef ShndxTable) const; ErrorOr getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef ShndxTable) const; @@ -214,21 +216,31 @@ ErrorOr ELFFile::getExtendedSymbolTableIndex( } template -ErrorOr -ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, - ArrayRef ShndxTable) const { +ErrorOr +ELFFile::getSectionIndex(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) { auto ErrorOrIndex = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable); if (std::error_code EC = ErrorOrIndex.getError()) return EC; - Index = *ErrorOrIndex; + return *ErrorOrIndex; } + if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE) + return 0; + return Index; +} +template +ErrorOr +ELFFile::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, + ArrayRef ShndxTable) const { + ErrorOr IndexOrErr = getSectionIndex(Sym, SymTab, ShndxTable); + if (std::error_code EC = IndexOrErr.getError()) + return EC; + uint32_t Index = *IndexOrErr; + if (Index == 0) + return nullptr; auto SectionsOrErr = sections(); if (std::error_code EC = SectionsOrErr.getError()) return EC;