[llvm] r285905 - Replace a report_fatal_error with an ErrorOr.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 3 06:43:30 PDT 2016
Author: rafael
Date: Thu Nov 3 08:43:30 2016
New Revision: 285905
URL: http://llvm.org/viewvc/llvm-project?rev=285905&view=rev
Log:
Replace a report_fatal_error with an ErrorOr.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
llvm/trunk/tools/obj2yaml/elf2yaml.cpp
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=285905&r1=285904&r2=285905&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Thu Nov 3 08:43:30 2016
@@ -111,13 +111,10 @@ public:
ErrorOr<Elf_Shdr_Range> sections() const;
- Elf_Sym_Range symbols(const Elf_Shdr *Sec) const {
+ ErrorOr<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
if (!Sec)
return makeArrayRef<Elf_Sym>(nullptr, nullptr);
- auto V = getSectionContentsAsArray<Elf_Sym>(Sec);
- if (!V)
- report_fatal_error(V.getError().message());
- return *V;
+ return getSectionContentsAsArray<Elf_Sym>(Sec);
}
Elf_Rela_Range relas(const Elf_Shdr *Sec) const {
@@ -164,7 +161,10 @@ public:
ErrorOr<const Elf_Sym *> getSymbol(const Elf_Shdr *Sec,
uint32_t Index) const {
- Elf_Sym_Range Symbols = symbols(Sec);
+ auto SymtabOrErr = symbols(Sec);
+ if (std::error_code EC = SymtabOrErr.getError())
+ return object_error::parse_failed;
+ Elf_Sym_Range Symbols = *SymtabOrErr;
if (Index >= Symbols.size())
return object_error::invalid_symbol_index;
return &Symbols[Index];
@@ -195,7 +195,10 @@ template <class ELFT>
uint32_t ELFFile<ELFT>::getExtendedSymbolTableIndex(
const Elf_Sym *Sym, const Elf_Shdr *SymTab,
ArrayRef<Elf_Word> ShndxTable) const {
- return getExtendedSymbolTableIndex(Sym, symbols(SymTab).begin(), ShndxTable);
+ auto SymsOrErr = symbols(SymTab);
+ if (std::error_code EC = SymsOrErr.getError())
+ report_fatal_error(EC.message());
+ return getExtendedSymbolTableIndex(Sym, SymsOrErr->begin(), ShndxTable);
}
template <class ELFT>
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=285905&r1=285904&r2=285905&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Thu Nov 3 08:43:30 2016
@@ -507,8 +507,8 @@ uint32_t ELFObjectFile<ELFT>::getSymbolF
Result |= SymbolRef::SF_Absolute;
if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION ||
- ESym == EF.symbols(DotSymtabSec).begin() ||
- ESym == EF.symbols(DotDynSymSec).begin())
+ ESym == (*EF.symbols(DotSymtabSec)).begin() ||
+ ESym == (*EF.symbols(DotDynSymSec)).begin())
Result |= SymbolRef::SF_FormatSpecific;
if (EF.getHeader()->e_machine == ELF::EM_ARM) {
Modified: llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h?rev=285905&r1=285904&r2=285905&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h (original)
+++ llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h Thu Nov 3 08:43:30 2016
@@ -353,7 +353,7 @@ PrinterContext<ET>::FunctionAtAddress(un
error(StrTableOrErr.getError());
StringRef StrTable = *StrTableOrErr;
- for (const Elf_Sym &Sym : ELF->symbols(Symtab))
+ for (const Elf_Sym &Sym : unwrapOrError(ELF->symbols(Symtab)))
if (Sym.st_shndx == Section && Sym.st_value == Address &&
Sym.getType() == ELF::STT_FUNC) {
auto NameOrErr = Sym.getName(StrTable);
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=285905&r1=285904&r2=285905&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Thu Nov 3 08:43:30 2016
@@ -246,7 +246,7 @@ void ELFDumper<ELFT>::printSymbolsHelper
if (!DotSymtabSec)
return;
StrTable = unwrapOrError(Obj->getStringTableForSymtab(*DotSymtabSec));
- Syms = Obj->symbols(DotSymtabSec);
+ Syms = unwrapOrError(Obj->symbols(DotSymtabSec));
SymtabName = unwrapOrError(Obj->getSectionName(DotSymtabSec));
Entries = DotSymtabSec->getEntityCount();
}
@@ -3494,11 +3494,12 @@ template <class ELFT> void LLVMStyle<ELF
const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec();
StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
- for (const Elf_Sym &Sym : Obj->symbols(Symtab)) {
+ for (const Elf_Sym &Sym : unwrapOrError(Obj->symbols(Symtab))) {
const Elf_Shdr *SymSec = unwrapOrError(
Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable()));
if (SymSec == &Sec)
- printSymbol(Obj, &Sym, Obj->symbols(Symtab).begin(), StrTable, false);
+ printSymbol(Obj, &Sym, unwrapOrError(Obj->symbols(Symtab)).begin(),
+ StrTable, false);
}
}
Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=285905&r1=285904&r2=285905&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Thu Nov 3 08:43:30 2016
@@ -145,7 +145,10 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELF
StringRef StrTable = *StrTableOrErr;
bool IsFirstSym = true;
- for (const Elf_Sym &Sym : Obj.symbols(Symtab)) {
+ auto SymtabOrErr = Obj.symbols(Symtab);
+ if (std::error_code EC = SymtabOrErr.getError())
+ return EC;
+ for (const Elf_Sym &Sym : *SymtabOrErr) {
if (IsFirstSym) {
IsFirstSym = false;
continue;
More information about the llvm-commits
mailing list