From 6def304209dd2152457c1ffda7330a6ac4e076f1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 1 Jul 2015 12:56:27 +0000 Subject: Return ErrorOr from getSection. This also improves the logic of what is an error: * getSection(uint_32): only return an error if the index is out of bounds. The index 0 corresponds to a perfectly valid entry. * getSection(Elf_Sym): Returns null for symbols that normally don't have sections and error for out of bound indexes. In many places this just moves the report_fatal_error up the stack, but those can then be fixed in smaller patches. llvm-svn: 241156 --- llvm/tools/llvm-objdump/llvm-objdump.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp') diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index dde7e55..6139cfb 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -319,12 +319,20 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, typedef typename ELFObjectFile::Elf_Shdr Elf_Shdr; const ELFFile &EF = *Obj->getELFFile(); - const Elf_Shdr *sec = EF.getSection(Rel.d.a); - const Elf_Shdr *SymTab = EF.getSection(sec->sh_link); + ErrorOr SecOrErr = EF.getSection(Rel.d.a); + if (std::error_code EC = SecOrErr.getError()) + return EC; + const Elf_Shdr *Sec = *SecOrErr; + ErrorOr SymTabOrErr = EF.getSection(Sec->sh_link); + if (std::error_code EC = SymTabOrErr.getError()) + return EC; + const Elf_Shdr *SymTab = *SymTabOrErr; assert(SymTab->sh_type == ELF::SHT_SYMTAB || SymTab->sh_type == ELF::SHT_DYNSYM); - const Elf_Shdr *StrTabSec = EF.getSection(SymTab->sh_link); - ErrorOr StrTabOrErr = EF.getStringTable(StrTabSec); + ErrorOr StrTabSec = EF.getSection(SymTab->sh_link); + if (std::error_code EC = StrTabSec.getError()) + return EC; + ErrorOr StrTabOrErr = EF.getStringTable(*StrTabSec); if (std::error_code EC = StrTabOrErr.getError()) return EC; StringRef StrTab = *StrTabOrErr; @@ -332,7 +340,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, StringRef res; int64_t addend = 0; uint16_t symbol_index = 0; - switch (sec->sh_type) { + switch (Sec->sh_type) { default: return object_error::parse_failed; case ELF::SHT_REL: { @@ -349,11 +357,13 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, } } const Elf_Sym *symb = - EF.template getEntry(sec->sh_link, symbol_index); + EF.template getEntry(Sec->sh_link, symbol_index); StringRef Target; - const Elf_Shdr *SymSec = EF.getSection(symb); + ErrorOr SymSec = EF.getSection(symb); + if (std::error_code EC = SymSec.getError()) + return EC; if (symb->getType() == ELF::STT_SECTION) { - ErrorOr SecName = EF.getSectionName(SymSec); + ErrorOr SecName = EF.getSectionName(*SymSec); if (std::error_code EC = SecName.getError()) return EC; Target = *SecName; -- cgit v1.1