llvm.org GIT mirror llvm / cf3b55a
Teach llvm-readobj to print ELF program headers git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179363 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Rieck 7 years ago
5 changed file(s) with 136 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
7575
7676 Display the needed libraries (only for ELF object files).
7777
78 .. option:: -program-headers
79
80 Display the ELF program headers (only for ELF object files).
81
7882 EXIT STATUS
7983 -----------
8084
0 RUN: llvm-readobj -program-headers %p/../../Object/Inputs/program-headers.elf-i386 \
1 RUN: | FileCheck %s -check-prefix ELF-I386
2 RUN: llvm-readobj -program-headers %p/../../Object/Inputs/program-headers.elf-x86-64 \
3 RUN: | FileCheck %s -check-prefix ELF-X86-64
4
5 ELF-I386: ProgramHeaders [
6 ELF-I386-NEXT: ProgramHeader {
7 ELF-I386-NEXT: Type: PT_LOAD (0x1)
8 ELF-I386-NEXT: Offset: 0x0
9 ELF-I386-NEXT: VirtualAddress: 0x8048000
10 ELF-I386-NEXT: PhysicalAddress: 0x8048000
11 ELF-I386-NEXT: FileSize: 308
12 ELF-I386-NEXT: MemSize: 308
13 ELF-I386-NEXT: Flags [ (0x5)
14 ELF-I386-NEXT: PF_R (0x4)
15 ELF-I386-NEXT: PF_X (0x1)
16 ELF-I386-NEXT: ]
17 ELF-I386-NEXT: Alignment: 4096
18 ELF-I386-NEXT: }
19 ELF-I386-NEXT: ProgramHeader {
20 ELF-I386-NEXT: Type: PT_GNU_STACK (0x6474E551)
21 ELF-I386-NEXT: Offset: 0x0
22 ELF-I386-NEXT: VirtualAddress: 0x0
23 ELF-I386-NEXT: PhysicalAddress: 0x0
24 ELF-I386-NEXT: FileSize: 0
25 ELF-I386-NEXT: MemSize: 0
26 ELF-I386-NEXT: Flags [ (0x6)
27 ELF-I386-NEXT: PF_R (0x4)
28 ELF-I386-NEXT: PF_W (0x2)
29 ELF-I386-NEXT: ]
30 ELF-I386-NEXT: Alignment: 4
31 ELF-I386-NEXT: }
32 ELF-I386-NEXT: ]
33
34 ELF-X86-64: ProgramHeaders [
35 ELF-X86-64-NEXT: ProgramHeader {
36 ELF-X86-64-NEXT: Type: PT_LOAD (0x1)
37 ELF-X86-64-NEXT: Offset: 0x0
38 ELF-X86-64-NEXT: VirtualAddress: 0x400000
39 ELF-X86-64-NEXT: PhysicalAddress: 0x400000
40 ELF-X86-64-NEXT: FileSize: 312
41 ELF-X86-64-NEXT: MemSize: 312
42 ELF-X86-64-NEXT: Flags [ (0x5)
43 ELF-X86-64-NEXT: PF_R (0x4)
44 ELF-X86-64-NEXT: PF_X (0x1)
45 ELF-X86-64-NEXT: ]
46 ELF-X86-64-NEXT: Alignment: 2097152
47 ELF-X86-64-NEXT: }
48 ELF-X86-64-NEXT: ProgramHeader {
49 ELF-X86-64-NEXT: Type: PT_GNU_EH_FRAME (0x6474E550)
50 ELF-X86-64-NEXT: Offset: 0xF4
51 ELF-X86-64-NEXT: VirtualAddress: 0x4000F4
52 ELF-X86-64-NEXT: PhysicalAddress: 0x4000F4
53 ELF-X86-64-NEXT: FileSize: 20
54 ELF-X86-64-NEXT: MemSize: 20
55 ELF-X86-64-NEXT: Flags [ (0x4)
56 ELF-X86-64-NEXT: PF_R (0x4)
57 ELF-X86-64-NEXT: ]
58 ELF-X86-64-NEXT: Alignment: 4
59 ELF-X86-64-NEXT: }
60 ELF-X86-64-NEXT: ProgramHeader {
61 ELF-X86-64-NEXT: Type: PT_GNU_STACK (0x6474E551)
62 ELF-X86-64-NEXT: Offset: 0x0
63 ELF-X86-64-NEXT: VirtualAddress: 0x0
64 ELF-X86-64-NEXT: PhysicalAddress: 0x0
65 ELF-X86-64-NEXT: FileSize: 0
66 ELF-X86-64-NEXT: MemSize: 0
67 ELF-X86-64-NEXT: Flags [ (0x6)
68 ELF-X86-64-NEXT: PF_R (0x4)
69 ELF-X86-64-NEXT: PF_W (0x2)
70 ELF-X86-64-NEXT: ]
71 ELF-X86-64-NEXT: Alignment: 8
72 ELF-X86-64-NEXT: }
73 ELF-X86-64-NEXT: ]
4949
5050 virtual void printDynamicTable() LLVM_OVERRIDE;
5151 virtual void printNeededLibraries() LLVM_OVERRIDE;
52 virtual void printProgramHeaders() LLVM_OVERRIDE;
5253
5354 private:
54 typedef typename ELFObjectFile::Elf_Shdr Elf_Shdr;
55 typedef typename ELFObjectFile::Elf_Sym Elf_Sym;
55 typedef ELFObjectFile ELFO;
56 typedef typename ELFO::Elf_Shdr Elf_Shdr;
57 typedef typename ELFO::Elf_Sym Elf_Sym;
5658
5759 void printSymbol(symbol_iterator SymI, bool IsDynamic = false);
5860
5961 void printRelocation(section_iterator SecI, relocation_iterator RelI);
6062
61 const ELFObjectFile *Obj;
63 const ELFO *Obj;
6264 };
6365
6466 } // namespace
398400 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP )
399401 };
400402
403 static const EnumEntry ElfSegmentTypes[] = {
404 LLVM_READOBJ_ENUM_ENT(ELF, PT_NULL ),
405 LLVM_READOBJ_ENUM_ENT(ELF, PT_LOAD ),
406 LLVM_READOBJ_ENUM_ENT(ELF, PT_DYNAMIC),
407 LLVM_READOBJ_ENUM_ENT(ELF, PT_INTERP ),
408 LLVM_READOBJ_ENUM_ENT(ELF, PT_NOTE ),
409 LLVM_READOBJ_ENUM_ENT(ELF, PT_SHLIB ),
410 LLVM_READOBJ_ENUM_ENT(ELF, PT_PHDR ),
411 LLVM_READOBJ_ENUM_ENT(ELF, PT_TLS ),
412
413 LLVM_READOBJ_ENUM_ENT(ELF, PT_GNU_EH_FRAME),
414 LLVM_READOBJ_ENUM_ENT(ELF, PT_SUNW_EH_FRAME),
415 LLVM_READOBJ_ENUM_ENT(ELF, PT_SUNW_UNWIND),
416
417 LLVM_READOBJ_ENUM_ENT(ELF, PT_GNU_STACK),
418 LLVM_READOBJ_ENUM_ENT(ELF, PT_GNU_RELRO),
419
420 LLVM_READOBJ_ENUM_ENT(ELF, PT_ARM_EXIDX),
421 LLVM_READOBJ_ENUM_ENT(ELF, PT_ARM_UNWIND)
422 };
423
424 static const EnumEntry ElfSegmentFlags[] = {
425 LLVM_READOBJ_ENUM_ENT(ELF, PF_X),
426 LLVM_READOBJ_ENUM_ENT(ELF, PF_W),
427 LLVM_READOBJ_ENUM_ENT(ELF, PF_R)
428 };
429
401430
402431 template
403432 void ELFDumper::printFileHeaders() {
404433 error_code EC;
405 typedef ELFObjectFile ELFO;
406434
407435 const typename ELFO::Elf_Ehdr *Header = Obj->getElfHeader();
408436
744772
745773 template
746774 void ELFDumper::printDynamicTable() {
747 typedef ELFObjectFile ELFO;
748775 typedef typename ELFO::Elf_Dyn_iterator EDI;
749776 EDI Start = Obj->begin_dynamic_table(),
750777 End = Obj->end_dynamic_table(true);
807834 outs() << " " << Path << "\n";
808835 }
809836 }
837
838 template
839 void ELFDumper::printProgramHeaders() {
840 ListScope L(W, "ProgramHeaders");
841
842 for (typename ELFO::Elf_Phdr_Iter PI = Obj->begin_program_headers(),
843 PE = Obj->end_program_headers();
844 PI != PE; ++PI) {
845 DictScope P(W, "ProgramHeader");
846 W.printEnum ("Type", PI->p_type, makeArrayRef(ElfSegmentTypes));
847 W.printHex ("Offset", PI->p_offset);
848 W.printHex ("VirtualAddress", PI->p_vaddr);
849 W.printHex ("PhysicalAddress", PI->p_paddr);
850 W.printNumber("FileSize", PI->p_filesz);
851 W.printNumber("MemSize", PI->p_memsz);
852 W.printFlags ("Flags", PI->p_flags, makeArrayRef(ElfSegmentFlags));
853 W.printNumber("Alignment", PI->p_align);
854 }
855 }
3737 // Only implemented for ELF at this time.
3838 virtual void printDynamicTable() { }
3939 virtual void printNeededLibraries() { }
40 virtual void printProgramHeaders() { }
4041
4142 protected:
4243 StreamWriter& W;
119119 // -needed-libs
120120 cl::opt NeededLibraries("needed-libs",
121121 cl::desc("Display the needed libraries"));
122
123 // -program-headers
124 cl::opt ProgramHeaders("program-headers",
125 cl::desc("Display ELF program headers"));
122126
123127 // -expand-relocs
124128 cl::opt ExpandRelocs("expand-relocs",
214218 Dumper->printDynamicTable();
215219 if (opts::NeededLibraries)
216220 Dumper->printNeededLibraries();
221 if (opts::ProgramHeaders)
222 Dumper->printProgramHeaders();
217223 }
218224
219225