--- !ELF
FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_EXEC
- Machine: EM_X86_64
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+ EPhEntSize: [[PHENTSIZE=56]]
Sections:
- Name: .dynstr
Type: SHT_STRTAB
Value: 0x1
- Tag: DT_NULL
Value: 0x0
+
+## Check how we dump dynamic tags when we are unable to read program headers.
+# RUN: yaml2obj --docnum=1 -DPHENTSIZE=1 %s -o %t-phentsize-err
+# RUN: llvm-readobj --dynamic-table %t-phentsize-err 2>&1 | \
+# RUN: FileCheck %s --implicit-check-not=warning: -DFILE=%t-phentsize-err \
+# RUN: --check-prefixes=PHENTSIZE-WARN,PHENTSIZE-LLVM
+# RUN: llvm-readelf --dynamic-table %t-phentsize-err 2>&1 | \
+# RUN: FileCheck %s --implicit-check-not=warning: -DFILE=%t-phentsize-err \
+# RUN: --check-prefixes=PHENTSIZE-WARN,PHENTSIZE-GNU
+
+# PHENTSIZE-WARN: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_HASH: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_STRTAB: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_SYMTAB: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_RELA: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': DT_SYMENT value of 0x987 is not the size of a symbol (0x18)
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_REL: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_JMPREL: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_RELR: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_ANDROID_RELR: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_GNU_HASH: invalid e_phentsize: 1
+# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': string table was not found
+
+# PHENTSIZE-LLVM: DynamicSection [ (61 entries)
+# PHENTSIZE-LLVM-NEXT: Tag Type Name/Value
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000002 PLTRELSZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000003 PLTGOT 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000004 HASH 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000005 STRTAB 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000006 SYMTAB 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000007 RELA 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000008 RELASZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000009 RELAENT 1929 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x000000000000000A STRSZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x000000000000000B SYMENT 2439 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x000000000000000C INIT 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000000000000D FINI 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000000000000E SONAME Library soname: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000010 SYMBOLIC 0x1234567890ABCDEF
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000011 REL 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000012 RELSZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000013 RELENT 291 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000014 PLTREL RELA
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000015 DEBUG 0xFEDCBA0987654321
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000016 TEXTREL 0x1122334455667788
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000017 JMPREL 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000018 BIND_NOW 0x8877665544332211
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000019 INIT_ARRAY 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000000000001A FINI_ARRAY 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000000000001B INIT_ARRAYSZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x000000000000001C FINI_ARRAYSZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x000000000000001D RUNPATH Library runpath: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x000000000000001E FLAGS ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000020 PREINIT_ARRAY 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000021 PREINIT_ARRAYSZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000022 SYMTAB_SHNDX 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000023 RELRSZ 0x10
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000024 RELR 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000025 RELRENT 0x4321
+# PHENTSIZE-LLVM-NEXT: 0x000000006000000F ANDROID_REL 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000060000010 ANDROID_RELSZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x0000000060000011 ANDROID_RELA 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x0000000060000012 ANDROID_RELASZ 16 (bytes)
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFE000 ANDROID_RELR 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFE001 ANDROID_RELRSZ 0x10
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFE003 ANDROID_RELRENT 0x1234
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFEF5 GNU_HASH 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFEF6 TLSDESC_PLT 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFEF7 TLSDESC_GOT 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFF9 RELACOUNT 0
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFA RELCOUNT 0
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON PIE {{$}}
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFF0 VERSYM 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFC VERDEF 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFD VERDEFNUM 0
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFE VERNEED 0x1000
+# PHENTSIZE-LLVM-NEXT: 0x000000006FFFFFFF VERNEEDNUM 0
+# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [<?>]
+# PHENTSIZE-LLVM-NEXT: 0x0000000012345678 <unknown:>0x12345678 0x8765432187654321
+# PHENTSIZE-LLVM-NEXT: 0x000000006ABCDEF0 <unknown:>0x6abcdef0 0x9988776655443322
+# PHENTSIZE-LLVM-NEXT: 0x0000000076543210 <unknown:>0x76543210 0x5555666677778888
+# PHENTSIZE-LLVM-NEXT: 0x0000000000000000 NULL 0x0
+# PHENTSIZE-LLVM-NEXT: ]
+
+# PHENTSIZE-GNU: Dynamic section at offset 0xc0 contains 61 entries:
+# PHENTSIZE-GNU-NEXT: Tag Type Name/Value
+# PHENTSIZE-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000004 (HASH) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000006 (SYMTAB) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000007 (RELA) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000008 (RELASZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x0000000000000009 (RELAENT) 1929 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x000000000000000a (STRSZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x000000000000000b (SYMENT) 2439 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x000000000000000c (INIT) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000000000000d (FINI) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef
+# PHENTSIZE-GNU-NEXT: 0x0000000000000011 (REL) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x0000000000000013 (RELENT) 291 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x0000000000000014 (PLTREL) RELA
+# PHENTSIZE-GNU-NEXT: 0x0000000000000015 (DEBUG) 0xfedcba0987654321
+# PHENTSIZE-GNU-NEXT: 0x0000000000000016 (TEXTREL) 0x1122334455667788
+# PHENTSIZE-GNU-NEXT: 0x0000000000000017 (JMPREL) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000018 (BIND_NOW) 0x8877665544332211
+# PHENTSIZE-GNU-NEXT: 0x0000000000000019 (INIT_ARRAY) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x000000000000001e (FLAGS) ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS
+# PHENTSIZE-GNU-NEXT: 0x0000000000000020 (PREINIT_ARRAY) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000021 (PREINIT_ARRAYSZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x0000000000000022 (SYMTAB_SHNDX) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000023 (RELRSZ) 0x10
+# PHENTSIZE-GNU-NEXT: 0x0000000000000024 (RELR) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000000000025 (RELRENT) 0x4321
+# PHENTSIZE-GNU-NEXT: 0x000000006000000f (ANDROID_REL) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000060000010 (ANDROID_RELSZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x0000000060000011 (ANDROID_RELA) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x0000000060000012 (ANDROID_RELASZ) 16 (bytes)
+# PHENTSIZE-GNU-NEXT: 0x000000006fffe000 (ANDROID_RELR) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000006fffe001 (ANDROID_RELRSZ) 0x10
+# PHENTSIZE-GNU-NEXT: 0x000000006fffe003 (ANDROID_RELRENT) 0x1234
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffef5 (GNU_HASH) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffef6 (TLSDESC_PLT) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffef7 (TLSDESC_GOT) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffff9 (RELACOUNT) 0
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffffa (RELCOUNT) 0
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffffb (FLAGS_1) NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON PIE
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffff0 (VERSYM) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffffc (VERDEF) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffffd (VERDEFNUM) 0
+# PHENTSIZE-GNU-NEXT: 0x000000006ffffffe (VERNEED) 0x1000
+# PHENTSIZE-GNU-NEXT: 0x000000006fffffff (VERNEEDNUM) 0
+# PHENTSIZE-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [<?>]
+# PHENTSIZE-GNU-NEXT: 0x0000000012345678 (<unknown:>0x12345678) 0x8765432187654321
+# PHENTSIZE-GNU-NEXT: 0x000000006abcdef0 (<unknown:>0x6abcdef0) 0x9988776655443322
+# PHENTSIZE-GNU-NEXT: 0x0000000076543210 (<unknown:>0x76543210) 0x5555666677778888
+# PHENTSIZE-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
// Try to locate the PT_DYNAMIC header.
const Elf_Phdr *DynamicPhdr = nullptr;
- for (const Elf_Phdr &Phdr :
- unwrapOrError(ObjF->getFileName(), Obj->program_headers())) {
- if (Phdr.p_type != ELF::PT_DYNAMIC)
- continue;
- DynamicPhdr = &Phdr;
- break;
+ if (Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj->program_headers()) {
+ for (const Elf_Phdr &Phdr : *PhdrsOrErr) {
+ if (Phdr.p_type != ELF::PT_DYNAMIC)
+ continue;
+ DynamicPhdr = &Phdr;
+ break;
+ }
+ } else {
+ this->reportUniqueWarning(createError(
+ "unable to read program headers to locate the PT_DYNAMIC segment: " +
+ toString(PhdrsOrErr.takeError())));
}
// Try to locate the .dynamic section in the sections header table.
unsigned Width = ELFT::Is64Bits ? 18 : 10;
unsigned SizeWidth = ELFT::Is64Bits ? 8 : 7;
- for (const auto &Phdr :
- unwrapOrError(this->FileName, Obj->program_headers())) {
+
+ Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj->program_headers();
+ if (!PhdrsOrErr) {
+ this->reportUniqueWarning(createError("unable to dump program headers: " +
+ toString(PhdrsOrErr.takeError())));
+ return;
+ }
+
+ for (const Elf_Phdr &Phdr : *PhdrsOrErr) {
Fields[0].Str = getElfPtType(Header->e_machine, Phdr.p_type);
Fields[1].Str = to_string(format_hex(Phdr.p_offset, 8));
Fields[2].Str = to_string(format_hex(Phdr.p_vaddr, Width));
OS << "\n Section to Segment mapping:\n Segment Sections...\n";
DenseSet<const Elf_Shdr *> BelongsToSegment;
int Phnum = 0;
- for (const Elf_Phdr &Phdr :
- unwrapOrError(this->FileName, Obj->program_headers())) {
+
+ Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj->program_headers();
+ if (!PhdrsOrErr) {
+ this->reportUniqueWarning(createError(
+ "can't read program headers to build section to segment mapping: " +
+ toString(PhdrsOrErr.takeError())));
+ return;
+ }
+
+ for (const Elf_Phdr &Phdr : *PhdrsOrErr) {
std::string Sections;
OS << format(" %2.2d ", Phnum++);
// Check if each section is in a segment and then print mapping.
reportError(std::move(Err), this->FileName);
}
} else {
- for (const auto &P :
- unwrapOrError(this->FileName, Obj->program_headers())) {
+ Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj->program_headers();
+ if (!PhdrsOrErr) {
+ this->reportUniqueWarning(createError(
+ "unable to read program headers to locate the PT_NOTE segment: " +
+ toString(PhdrsOrErr.takeError())));
+ return;
+ }
+
+ for (const Elf_Phdr &P : *PhdrsOrErr) {
if (P.p_type != PT_NOTE)
continue;
PrintHeader(/*SecName=*/None, P.p_offset, P.p_filesz);
void LLVMStyle<ELFT>::printProgramHeaders(const ELFO *Obj) {
ListScope L(W, "ProgramHeaders");
- for (const Elf_Phdr &Phdr :
- unwrapOrError(this->FileName, Obj->program_headers())) {
+ Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj->program_headers();
+ if (!PhdrsOrErr) {
+ this->reportUniqueWarning(createError("unable to dump program headers: " +
+ toString(PhdrsOrErr.takeError())));
+ return;
+ }
+
+ for (const Elf_Phdr &Phdr : *PhdrsOrErr) {
DictScope P(W, "ProgramHeader");
W.printHex("Type",
getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type),
reportError(std::move(Err), this->FileName);
}
} else {
- for (const auto &P :
- unwrapOrError(this->FileName, Obj->program_headers())) {
+ Expected<ArrayRef<Elf_Phdr>> PhdrsOrErr = Obj->program_headers();
+ if (!PhdrsOrErr) {
+ this->reportUniqueWarning(createError(
+ "unable to read program headers to locate the PT_NOTE segment: " +
+ toString(PhdrsOrErr.takeError())));
+ return;
+ }
+
+ for (const Elf_Phdr &P : *PhdrsOrErr) {
if (P.p_type != PT_NOTE)
continue;
DictScope D(W, "NoteSection");