}
/// \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);
}
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 | \
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 ";
: 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;
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));
}
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())) {
};
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 {
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),