mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-04 06:51:56 +00:00
Replace a report_fatal_error with an ErrorOr.
llvm-svn: 285905
This commit is contained in:
parent
6d18d388c5
commit
9ea68341b9
@ -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>
|
||||
|
@ -507,8 +507,8 @@ uint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
|
||||
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) {
|
||||
|
@ -353,7 +353,7 @@ PrinterContext<ET>::FunctionAtAddress(unsigned Section,
|
||||
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);
|
||||
|
@ -246,7 +246,7 @@ void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
|
||||
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<ELFT>::printSections(const ELFO *Obj) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,10 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user