diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-07-01 12:56:27 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-07-01 12:56:27 +0000 |
commit | 6def304209dd2152457c1ffda7330a6ac4e076f1 (patch) | |
tree | f0b47d1c1dcc683f50552e6850ac19aa6987ed58 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 6ae400d12256de0547c1b06919d126f664c78d7e (diff) | |
download | llvm-6def304209dd2152457c1ffda7330a6ac4e076f1.zip llvm-6def304209dd2152457c1ffda7330a6ac4e076f1.tar.gz llvm-6def304209dd2152457c1ffda7330a6ac4e076f1.tar.bz2 |
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
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
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<ELFT> *Obj, typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr; const ELFFile<ELFT> &EF = *Obj->getELFFile(); - const Elf_Shdr *sec = EF.getSection(Rel.d.a); - const Elf_Shdr *SymTab = EF.getSection(sec->sh_link); + ErrorOr<const Elf_Shdr *> SecOrErr = EF.getSection(Rel.d.a); + if (std::error_code EC = SecOrErr.getError()) + return EC; + const Elf_Shdr *Sec = *SecOrErr; + ErrorOr<const Elf_Shdr *> 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<StringRef> StrTabOrErr = EF.getStringTable(StrTabSec); + ErrorOr<const Elf_Shdr *> StrTabSec = EF.getSection(SymTab->sh_link); + if (std::error_code EC = StrTabSec.getError()) + return EC; + ErrorOr<StringRef> 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<ELFT> *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<ELFT> *Obj, } } const Elf_Sym *symb = - EF.template getEntry<Elf_Sym>(sec->sh_link, symbol_index); + EF.template getEntry<Elf_Sym>(Sec->sh_link, symbol_index); StringRef Target; - const Elf_Shdr *SymSec = EF.getSection(symb); + ErrorOr<const Elf_Shdr *> SymSec = EF.getSection(symb); + if (std::error_code EC = SymSec.getError()) + return EC; if (symb->getType() == ELF::STT_SECTION) { - ErrorOr<StringRef> SecName = EF.getSectionName(SymSec); + ErrorOr<StringRef> SecName = EF.getSectionName(*SymSec); if (std::error_code EC = SecName.getError()) return EC; Target = *SecName; |