diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index fe56c39d768..d8adb30ee32 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -72,8 +72,8 @@ private: const Elf_Ehdr *Header; public: - template - const T *getEntry(uint32_t Section, uint32_t Entry) const; + template + ErrorOr getEntry(uint32_t Section, uint32_t Entry) const; template const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const; @@ -403,10 +403,11 @@ ErrorOr ELFFile::sections() const { template template -const T *ELFFile::getEntry(uint32_t Section, uint32_t Entry) const { +ErrorOr ELFFile::getEntry(uint32_t Section, + uint32_t Entry) const { ErrorOr Sec = getSection(Section); if (std::error_code EC = Sec.getError()) - report_fatal_error(EC.message()); + return EC; return getEntry(*Sec, Entry); } diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index ad1c2e12ce1..f7e9cb9a89f 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -317,7 +317,10 @@ public: const Elf_Rela *getRela(DataRefImpl Rela) const; const Elf_Sym *getSymbol(DataRefImpl Sym) const { - return EF.template getEntry(Sym.d.a, Sym.d.b); + auto Ret = EF.template getEntry(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 { @@ -749,14 +752,20 @@ template const typename ELFObjectFile::Elf_Rel * ELFObjectFile::getRel(DataRefImpl Rel) const { assert(getRelSection(Rel)->sh_type == ELF::SHT_REL); - return EF.template getEntry(Rel.d.a, Rel.d.b); + auto Ret = EF.template getEntry(Rel.d.a, Rel.d.b); + if (std::error_code EC = Ret.getError()) + report_fatal_error(EC.message()); + return *Ret; } template const typename ELFObjectFile::Elf_Rela * ELFObjectFile::getRela(DataRefImpl Rela) const { assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA); - return EF.template getEntry(Rela.d.a, Rela.d.b); + auto Ret = EF.template getEntry(Rela.d.a, Rela.d.b); + if (std::error_code EC = Ret.getError()) + report_fatal_error(EC.message()); + return *Ret; } template