[ELF] Convert ELF.h to Expected<T>.

This has two advantages:
1) We slowly move away from ErrorOr to the new handling interface,
in the hope of having an uniform error handling in LLVM, eventually.
2) We're starting to have *meaningful* error messages for invalid
object ELF files, rather than a generic "parse error". At some point
we should include also the offset to improve the quality of the
diagnostic.

llvm-svn: 287081
diff --git a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
index 78060e3..903a246 100644
--- a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
+++ b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
@@ -349,8 +349,9 @@
 ErrorOr<StringRef>
 PrinterContext<ET>::FunctionAtAddress(unsigned Section,
                                       uint64_t Address) const {
-  ErrorOr<StringRef> StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
-  error(StrTableOrErr.getError());
+  auto StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
+  if (!StrTableOrErr)
+    error(StrTableOrErr.takeError());
   StringRef StrTable = *StrTableOrErr;
 
   for (const Elf_Sym &Sym : unwrapOrError(ELF->symbols(Symtab)))
@@ -383,8 +384,9 @@
     if (Sec.sh_type != ELF::SHT_REL || Sec.sh_info != IndexSectionIndex)
       continue;
 
-    ErrorOr<const Elf_Shdr *> SymTabOrErr = ELF->getSection(Sec.sh_link);
-    error(SymTabOrErr.getError());
+    auto SymTabOrErr = ELF->getSection(Sec.sh_link);
+    if (!SymTabOrErr)
+      error(SymTabOrErr.takeError());
     const Elf_Shdr *SymTab = *SymTabOrErr;
 
     for (const Elf_Rel &R : unwrapOrError(ELF->rels(&Sec))) {
@@ -399,10 +401,9 @@
       const Elf_Sym *Symbol =
           unwrapOrError(ELF->getRelocationSymbol(&RelA, SymTab));
 
-      ErrorOr<const Elf_Shdr *> Ret =
-          ELF->getSection(Symbol, SymTab, ShndxTable);
-      if (std::error_code EC = Ret.getError())
-        report_fatal_error(EC.message());
+      auto Ret = ELF->getSection(Symbol, SymTab, ShndxTable);
+      if (!Ret)
+        report_fatal_error(errorToErrorCode(Ret.takeError()).message());
       return *Ret;
     }
   }
@@ -413,7 +414,7 @@
 void PrinterContext<ET>::PrintExceptionTable(const Elf_Shdr *IT,
                                              const Elf_Shdr *EHT,
                                              uint64_t TableEntryOffset) const {
-  ErrorOr<ArrayRef<uint8_t> > Contents = ELF->getSectionContents(EHT);
+  Expected<ArrayRef<uint8_t>> Contents = ELF->getSectionContents(EHT);
   if (!Contents)
     return;
 
@@ -480,7 +481,7 @@
 template <typename ET>
 void PrinterContext<ET>::PrintIndexTable(unsigned SectionIndex,
                                          const Elf_Shdr *IT) const {
-  ErrorOr<ArrayRef<uint8_t> > Contents = ELF->getSectionContents(IT);
+  Expected<ArrayRef<uint8_t>> Contents = ELF->getSectionContents(IT);
   if (!Contents)
     return;
 
@@ -533,7 +534,7 @@
       const Elf_Shdr *EHT =
         FindExceptionTable(SectionIndex, Entry * IndexTableEntrySize + 4);
 
-      if (ErrorOr<StringRef> Name = ELF->getSectionName(EHT))
+      if (auto Name = ELF->getSectionName(EHT))
         SW.printString("ExceptionHandlingTable", *Name);
 
       uint64_t TableEntryOffset = PREL31(Word1, IT->sh_addr);
@@ -554,7 +555,7 @@
       DictScope UIT(SW, "UnwindIndexTable");
 
       SW.printNumber("SectionIndex", SectionIndex);
-      if (ErrorOr<StringRef> SectionName = ELF->getSectionName(&Sec))
+      if (auto SectionName = ELF->getSectionName(&Sec))
         SW.printString("SectionName", *SectionName);
       SW.printHex("SectionOffset", Sec.sh_offset);