From a625bffced27a7cb7e8bcf9d02e1c7494589ee7c Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 3 Nov 2016 19:07:15 +0000 Subject: [PATCH] Remove the last use of report_fatal_error from ELF.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285955 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 14 ++++---------- tools/llvm-readobj/ARMEHABIPrinter.h | 2 +- tools/llvm-readobj/ELFDumper.cpp | 12 ++++++------ tools/obj2yaml/elf2yaml.cpp | 10 ++++++++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 33a3b75b47b..8b5c12b0a74 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -117,18 +117,12 @@ public: return getSectionContentsAsArray(Sec); } - Elf_Rela_Range relas(const Elf_Shdr *Sec) const { - auto V = getSectionContentsAsArray(Sec); - if (!V) - report_fatal_error(V.getError().message()); - return *V; + ErrorOr relas(const Elf_Shdr *Sec) const { + return getSectionContentsAsArray(Sec); } - Elf_Rel_Range rels(const Elf_Shdr *Sec) const { - auto V = getSectionContentsAsArray(Sec); - if (!V) - report_fatal_error(V.getError().message()); - return *V; + ErrorOr rels(const Elf_Shdr *Sec) const { + return getSectionContentsAsArray(Sec); } /// \brief Iterate over program header table. diff --git a/tools/llvm-readobj/ARMEHABIPrinter.h b/tools/llvm-readobj/ARMEHABIPrinter.h index 2e10d8a917f..78060e3abcd 100644 --- a/tools/llvm-readobj/ARMEHABIPrinter.h +++ b/tools/llvm-readobj/ARMEHABIPrinter.h @@ -387,7 +387,7 @@ PrinterContext::FindExceptionTable(unsigned IndexSectionIndex, error(SymTabOrErr.getError()); const Elf_Shdr *SymTab = *SymTabOrErr; - for (const Elf_Rel &R : ELF->rels(&Sec)) { + for (const Elf_Rel &R : unwrapOrError(ELF->rels(&Sec))) { if (R.r_offset != static_cast(IndexTableOffset)) continue; diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index bde7a6ebbea..0fdf3919470 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -2067,7 +2067,7 @@ template void MipsGOTParser::parsePLT() { switch (PLTRelShdr->sh_type) { case ELF::SHT_REL: - for (const Elf_Rel &Rel : Obj->rels(PLTRelShdr)) { + for (const Elf_Rel &Rel : unwrapOrError(Obj->rels(PLTRelShdr))) { const Elf_Sym *Sym = unwrapOrError(Obj->getRelocationSymbol(&Rel, SymTable)); printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, StrTable, Sym); @@ -2076,7 +2076,7 @@ template void MipsGOTParser::parsePLT() { } break; case ELF::SHT_RELA: - for (const Elf_Rela &Rel : Obj->relas(PLTRelShdr)) { + for (const Elf_Rela &Rel : unwrapOrError(Obj->relas(PLTRelShdr))) { const Elf_Sym *Sym = unwrapOrError(Obj->getRelocationSymbol(&Rel, SymTable)); printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, StrTable, Sym); @@ -2531,7 +2531,7 @@ template void GNUStyle::printRelocations(const ELFO *Obj) { printRelocHeader(OS, ELFT::Is64Bits, (Sec.sh_type == ELF::SHT_RELA)); const Elf_Shdr *SymTab = unwrapOrError(Obj->getSection(Sec.sh_link)); if (Sec.sh_type == ELF::SHT_REL) { - for (const auto &R : Obj->rels(&Sec)) { + for (const auto &R : unwrapOrError(Obj->rels(&Sec))) { Elf_Rela Rela; Rela.r_offset = R.r_offset; Rela.r_info = R.r_info; @@ -2539,7 +2539,7 @@ template void GNUStyle::printRelocations(const ELFO *Obj) { printRelocation(Obj, SymTab, Rela, false); } } else { - for (const auto &R : Obj->relas(&Sec)) + for (const auto &R : unwrapOrError(Obj->relas(&Sec))) printRelocation(Obj, SymTab, R, true); } } @@ -3388,7 +3388,7 @@ void LLVMStyle::printRelocations(const Elf_Shdr *Sec, const ELFO *Obj) { switch (Sec->sh_type) { case ELF::SHT_REL: - for (const Elf_Rel &R : Obj->rels(Sec)) { + for (const Elf_Rel &R : unwrapOrError(Obj->rels(Sec))) { Elf_Rela Rela; Rela.r_offset = R.r_offset; Rela.r_info = R.r_info; @@ -3397,7 +3397,7 @@ void LLVMStyle::printRelocations(const Elf_Shdr *Sec, const ELFO *Obj) { } break; case ELF::SHT_RELA: - for (const Elf_Rela &R : Obj->relas(Sec)) + for (const Elf_Rela &R : unwrapOrError(Obj->relas(Sec))) printRelocation(Obj, R, SymTab); break; } diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index dbb8c7d436b..ffcb2d0ece4 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -295,7 +295,10 @@ ELFDumper::dumpRelSection(const Elf_Shdr *Shdr) { return EC; const Elf_Shdr *SymTab = *SymTabOrErr; - for (const Elf_Rel &Rel : Obj.rels(Shdr)) { + auto Rels = Obj.rels(Shdr); + if (std::error_code EC = Rels.getError()) + return EC; + for (const Elf_Rel &Rel : *Rels) { ELFYAML::Relocation R; if (std::error_code EC = dumpRelocation(&Rel, SymTab, R)) return EC; @@ -319,7 +322,10 @@ ELFDumper::dumpRelaSection(const Elf_Shdr *Shdr) { return EC; const Elf_Shdr *SymTab = *SymTabOrErr; - for (const Elf_Rela &Rel : Obj.relas(Shdr)) { + auto Rels = Obj.relas(Shdr); + if (std::error_code EC = Rels.getError()) + return EC; + for (const Elf_Rela &Rel : *Rels) { ELFYAML::Relocation R; if (std::error_code EC = dumpRelocation(&Rel, SymTab, R)) return EC; -- 2.40.0