[llvm] r285942 - Replace a report_fatal_error with an ErrorOr.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 3 10:28:33 PDT 2016
Author: rafael
Date: Thu Nov 3 12:28:33 2016
New Revision: 285942
URL: http://llvm.org/viewvc/llvm-project?rev=285942&view=rev
Log:
Replace a report_fatal_error with an ErrorOr.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/test/Object/corrupt.test
llvm/trunk/tools/llvm-objdump/ELFDump.cpp
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=285942&r1=285941&r2=285942&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Thu Nov 3 12:28:33 2016
@@ -132,9 +132,9 @@ public:
}
/// \brief Iterate over program header table.
- const Elf_Phdr_Range program_headers() const {
+ ErrorOr<Elf_Phdr_Range> program_headers() const {
if (Header->e_phnum && Header->e_phentsize != sizeof(Elf_Phdr))
- report_fatal_error("Invalid program header size");
+ return object_error::parse_failed;
auto *Begin = reinterpret_cast<const Elf_Phdr *>(base() + Header->e_phoff);
return makeArrayRef(Begin, Begin+Header->e_phnum);
}
Modified: llvm/trunk/test/Object/corrupt.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/corrupt.test?rev=285942&r1=285941&r2=285942&view=diff
==============================================================================
--- llvm/trunk/test/Object/corrupt.test (original)
+++ llvm/trunk/test/Object/corrupt.test Thu Nov 3 12:28:33 2016
@@ -36,7 +36,7 @@ RUN: not llvm-readobj -program-headers \
RUN: %p/Inputs/corrupt-invalid-phentsize.elf.x86-64 2>&1 | \
RUN: FileCheck --check-prefix=PHENTSIZE %s
-PHENTSIZE: Invalid program header size
+PHENTSIZE: Invalid data was encountered while parsing the file.
RUN: not llvm-readobj -dynamic-table \
RUN: %p/Inputs/corrupt-invalid-virtual-addr.elf.x86-64 2>&1 | \
Modified: llvm/trunk/tools/llvm-objdump/ELFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/ELFDump.cpp?rev=285942&r1=285941&r2=285942&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/ELFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/ELFDump.cpp Thu Nov 3 12:28:33 2016
@@ -24,7 +24,10 @@ using namespace llvm::object;
template <class ELFT> void printProgramHeaders(const ELFFile<ELFT> *o) {
typedef ELFFile<ELFT> ELFO;
outs() << "Program Header:\n";
- for (const typename ELFO::Elf_Phdr &Phdr : o->program_headers()) {
+ auto ProgramHeaderOrError = o->program_headers();
+ if (std::error_code EC = ProgramHeaderOrError.getError())
+ report_fatal_error(EC.message());
+ for (const typename ELFO::Elf_Phdr &Phdr : *ProgramHeaderOrError) {
switch (Phdr.p_type) {
case ELF::PT_LOAD:
outs() << " LOAD ";
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=285942&r1=285941&r2=285942&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Thu Nov 3 12:28:33 2016
@@ -1305,7 +1305,7 @@ ELFDumper<ELFT>::ELFDumper(const ELFFile
: ObjDumper(Writer), Obj(Obj) {
SmallVector<const Elf_Phdr *, 4> LoadSegments;
- for (const Elf_Phdr &Phdr : Obj->program_headers()) {
+ for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
if (Phdr.p_type == ELF::PT_DYNAMIC) {
DynamicTable = createDRIFrom(&Phdr, sizeof(Elf_Dyn));
continue;
@@ -2910,7 +2910,7 @@ void GNUStyle<ELFT>::printProgramHeaders
else
OS << " Type Offset VirtAddr PhysAddr FileSiz "
<< "MemSiz Flg Align\n";
- for (const auto &Phdr : Obj->program_headers()) {
+ for (const auto &Phdr : unwrapOrError(Obj->program_headers())) {
Type = getElfPtType(Header->e_machine, Phdr.p_type);
Offset = to_string(format_hex(Phdr.p_offset, 8));
VMA = to_string(format_hex(Phdr.p_vaddr, Width));
@@ -2937,7 +2937,7 @@ void GNUStyle<ELFT>::printProgramHeaders
}
OS << "\n Section to Segment mapping:\n Segment Sections...\n";
int Phnum = 0;
- for (const Elf_Phdr &Phdr : Obj->program_headers()) {
+ for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
std::string Sections;
OS << format(" %2.2d ", Phnum++);
for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
@@ -3268,7 +3268,7 @@ void GNUStyle<ELFT>::printNotes(const EL
};
if (IsCore) {
- for (const auto &P : Obj->program_headers())
+ for (const auto &P : unwrapOrError(Obj->program_headers()))
if (P.p_type == PT_NOTE)
process(P.p_offset, P.p_filesz);
} else {
@@ -3630,7 +3630,7 @@ template <class ELFT>
void LLVMStyle<ELFT>::printProgramHeaders(const ELFO *Obj) {
ListScope L(W, "ProgramHeaders");
- for (const Elf_Phdr &Phdr : Obj->program_headers()) {
+ for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
DictScope P(W, "ProgramHeader");
W.printHex("Type",
getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type),
More information about the llvm-commits
mailing list