]> granicus.if.org Git - llvm/commitdiff
replace a report_fatal_error with a ErrorOr.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Nov 2016 13:58:15 +0000 (13:58 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Nov 2016 13:58:15 +0000 (13:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285910 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h
test/Object/invalid.test
tools/llvm-readobj/ELFDumper.cpp

index d5ce410d58c3668f44e6c739d3ecdf19977ac48c..9420b1e7bd53972033057b964ca46c905f468fb2 100644 (file)
@@ -147,12 +147,12 @@ public:
   }
 
   ErrorOr<StringRef> getSectionStringTable(Elf_Shdr_Range Sections) const;
-  uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
-                                       const Elf_Shdr *SymTab,
-                                       ArrayRef<Elf_Word> ShndxTable) const;
-  uint32_t getExtendedSymbolTableIndex(const Elf_Sym *Sym,
-                                       const Elf_Sym *FirstSym,
-                                       ArrayRef<Elf_Word> ShndxTable) const;
+  ErrorOr<uint32_t>
+  getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
+                              ArrayRef<Elf_Word> ShndxTable) const;
+  ErrorOr<uint32_t>
+  getExtendedSymbolTableIndex(const Elf_Sym *Sym, const Elf_Sym *FirstSym,
+                              ArrayRef<Elf_Word> ShndxTable) const;
   const Elf_Ehdr *getHeader() const { return Header; }
   ErrorOr<const Elf_Shdr *> getSection(const Elf_Sym *Sym,
                                        const Elf_Shdr *SymTab,
@@ -192,23 +192,23 @@ getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
 }
 
 template <class ELFT>
-uint32_t ELFFile<ELFT>::getExtendedSymbolTableIndex(
+ErrorOr<uint32_t> ELFFile<ELFT>::getExtendedSymbolTableIndex(
     const Elf_Sym *Sym, const Elf_Shdr *SymTab,
     ArrayRef<Elf_Word> ShndxTable) const {
   auto SymsOrErr = symbols(SymTab);
   if (std::error_code EC = SymsOrErr.getError())
-    report_fatal_error(EC.message());
+    return EC;
   return getExtendedSymbolTableIndex(Sym, SymsOrErr->begin(), ShndxTable);
 }
 
 template <class ELFT>
-uint32_t ELFFile<ELFT>::getExtendedSymbolTableIndex(
+ErrorOr<uint32_t> ELFFile<ELFT>::getExtendedSymbolTableIndex(
     const Elf_Sym *Sym, const Elf_Sym *FirstSym,
     ArrayRef<Elf_Word> ShndxTable) const {
   assert(Sym->st_shndx == ELF::SHN_XINDEX);
   unsigned Index = Sym - FirstSym;
   if (Index >= ShndxTable.size())
-    report_fatal_error("Invalid symbol table index");
+    return object_error::parse_failed;
   // The size of the table was checked in getSHNDXTable.
   return ShndxTable[Index];
 }
@@ -222,8 +222,12 @@ ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
       (Index >= ELF::SHN_LORESERVE && Index != ELF::SHN_XINDEX))
     return nullptr;
 
-  if (Index == ELF::SHN_XINDEX)
-    Index = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable);
+  if (Index == ELF::SHN_XINDEX) {
+    auto ErrorOrIndex = getExtendedSymbolTableIndex(Sym, SymTab, ShndxTable);
+    if (std::error_code EC = ErrorOrIndex.getError())
+      return EC;
+    Index = *ErrorOrIndex;
+  }
 
   auto SectionsOrErr = sections();
   if (std::error_code EC = SectionsOrErr.getError())
index 43fccccdc06be081ceb25868bf10e5c6795393e5..c124ff05ed59f55d93931426a4aa860cb3eb8c73 100644 (file)
@@ -60,7 +60,7 @@ INVALID-SH-NUM: Invalid data was encountered while parsing the file.
 
 RUN: not llvm-readobj -t %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \
 RUN:   FileCheck --check-prefix=INVALID-EXT-SYMTAB-INDEX %s
-INVALID-EXT-SYMTAB-INDEX: Invalid symbol table index
+INVALID-EXT-SYMTAB-INDEX: Invalid data was encountered while parsing the file.
 
 RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-i386 2>&1 | \
 RUN:   FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s
index f50ecc157d52df99063b7095ae4a852111be281a..e6041530b06c911613b4700c4c77c331bf7beaef 100644 (file)
@@ -717,8 +717,8 @@ getSectionNameIndex(const ELFO &Obj, const typename ELFO::Elf_Sym *Symbol,
     SectionName = "Reserved";
   else {
     if (SectionIndex == SHN_XINDEX)
-      SectionIndex =
-          Obj.getExtendedSymbolTableIndex(Symbol, FirstSym, ShndxTable);
+      SectionIndex = unwrapOrError(
+          Obj.getExtendedSymbolTableIndex(Symbol, FirstSym, ShndxTable));
     const typename ELFO::Elf_Shdr *Sec =
         unwrapOrError(Obj.getSection(SectionIndex));
     SectionName = unwrapOrError(Obj.getSectionName(Sec));
@@ -2737,8 +2737,8 @@ std::string GNUStyle<ELFT>::getSymbolSectionNdx(const ELFO *Obj,
   case ELF::SHN_COMMON:
     return "COM";
   case ELF::SHN_XINDEX:
-    SectionIndex = Obj->getExtendedSymbolTableIndex(
-        Symbol, FirstSym, this->dumper()->getShndxTable());
+    SectionIndex = unwrapOrError(Obj->getExtendedSymbolTableIndex(
+        Symbol, FirstSym, this->dumper()->getShndxTable()));
   default:
     // Find if:
     // Processor specific