summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-11-03 02:24:59 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-11-03 02:24:59 +0000
commit203ff0d3c953f4802c6a89376991457b43ad099c (patch)
tree57581bf4178c4a16153cafc2d93e3f6efeb32b1d
parent70d15b36e5200b6a7abf58e411d651573b8a8080 (diff)
downloadbcm5719-llvm-203ff0d3c953f4802c6a89376991457b43ad099c.tar.gz
bcm5719-llvm-203ff0d3c953f4802c6a89376991457b43ad099c.zip
Split getSection in two.
This will allow avoiding repeated error checking in a few cases. llvm-svn: 285874
-rw-r--r--llvm/include/llvm/Object/ELF.h26
1 files changed, 18 insertions, 8 deletions
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index b23ec6cc319..71f30ab16dd 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -179,6 +179,14 @@ typedef ELFFile<ELFType<support::big, false>> ELF32BEFile;
typedef ELFFile<ELFType<support::big, true>> ELF64BEFile;
template <class ELFT>
+inline ErrorOr<const typename ELFT::Shdr *>
+getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
+ if (Index >= Sections.size())
+ return object_error::invalid_section_index;
+ return &Sections[Index];
+}
+
+template <class ELFT>
uint32_t ELFFile<ELFT>::getExtendedSymbolTableIndex(
const Elf_Sym *Sym, const Elf_Shdr *SymTab,
ArrayRef<Elf_Word> ShndxTable) const {
@@ -202,12 +210,17 @@ ErrorOr<const typename ELFT::Shdr *>
ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
ArrayRef<Elf_Word> 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<ELFT>(*SectionsOrErr, Index);
}
template <class ELFT>
@@ -387,10 +400,7 @@ ELFFile<ELFT>::getSection(uint32_t Index) const {
auto TableOrErr = sections();
if (std::error_code EC = TableOrErr.getError())
return EC;
- ArrayRef<Elf_Shdr> Table = *TableOrErr;
- if (Index >= Table.size())
- return object_error::invalid_section_index;
- return &Table[Index];
+ return object::getSection<ELFT>(*TableOrErr, Index);
}
template <class ELFT>
OpenPOWER on IntegriCloud