Skip to content

Commit

Permalink
Replace another report_fatal_error with an ErrorOr.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285944 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Nov 3, 2016
1 parent 7446318 commit d77057e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 5 additions & 4 deletions include/llvm/Object/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class ELFFile {
const Elf_Ehdr *Header;

public:
template<typename T>
const T *getEntry(uint32_t Section, uint32_t Entry) const;
template <typename T>
ErrorOr<const T *> getEntry(uint32_t Section, uint32_t Entry) const;
template <typename T>
const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;

Expand Down Expand Up @@ -403,10 +403,11 @@ ErrorOr<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const {

template <class ELFT>
template <typename T>
const T *ELFFile<ELFT>::getEntry(uint32_t Section, uint32_t Entry) const {
ErrorOr<const T *> ELFFile<ELFT>::getEntry(uint32_t Section,
uint32_t Entry) const {
ErrorOr<const Elf_Shdr *> Sec = getSection(Section);
if (std::error_code EC = Sec.getError())
report_fatal_error(EC.message());
return EC;
return getEntry<T>(*Sec, Entry);
}

Expand Down
15 changes: 12 additions & 3 deletions include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
const Elf_Rela *getRela(DataRefImpl Rela) const;

const Elf_Sym *getSymbol(DataRefImpl Sym) const {
return EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
auto Ret = EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
if (std::error_code EC = Ret.getError())
report_fatal_error(EC.message());
return *Ret;
}

const Elf_Shdr *getSection(DataRefImpl Sec) const {
Expand Down Expand Up @@ -749,14 +752,20 @@ template <class ELFT>
const typename ELFObjectFile<ELFT>::Elf_Rel *
ELFObjectFile<ELFT>::getRel(DataRefImpl Rel) const {
assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
if (std::error_code EC = Ret.getError())
report_fatal_error(EC.message());
return *Ret;
}

template <class ELFT>
const typename ELFObjectFile<ELFT>::Elf_Rela *
ELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const {
assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
if (std::error_code EC = Ret.getError())
report_fatal_error(EC.message());
return *Ret;
}

template <class ELFT>
Expand Down

0 comments on commit d77057e

Please sign in to comment.