| ## Check how llvm-readelf dumps program headers and prints sections to segments mapping. |
| |
| ## Check that -l, --program-headers and --segments are the same option. |
| # RUN: yaml2obj --docnum=1 -DBITS=32 -DMACHINE=EM_386 %s -o %t32.elf |
| # RUN: llvm-readelf -l %t32.elf 2>&1 > %t.readelf-l.txt |
| # RUN: llvm-readelf --program-headers %t32.elf 2>&1 > %t.readelf-pheaders.txt |
| # RUN: cmp %t.readelf-l.txt %t.readelf-pheaders.txt |
| # RUN: llvm-readelf --segments %t32.elf 2>&1 > %t.readelf-segments.txt |
| # RUN: cmp %t.readelf-l.txt %t.readelf-segments.txt |
| |
| ## Check we are able to print program headers of different types. |
| # RUN: llvm-readelf -l %t32.elf | \ |
| # RUN: FileCheck %s --check-prefixes=ELF32,MAPPING --strict-whitespace --match-full-lines |
| |
| # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 %s -o %t64.elf |
| # RUN: llvm-readelf -l %t64.elf | \ |
| # RUN: FileCheck %s --check-prefixes=ELF64,MAPPING --strict-whitespace --match-full-lines |
| |
| # ELF32:There are 23 program headers, starting at offset 52 |
| # ELF32-EMPTY: |
| # ELF32-NEXT:Program Headers: |
| # ELF32-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align |
| # ELF32-NEXT: PHDR 0x000314 0x00001000 0x00001000 0x00003 0x00003 W 0x1 |
| # ELF32-NEXT: PHDR 0x000317 0x00002000 0x00002000 0x00007 0x00007 E 0x1 |
| # ELF32-NEXT: NULL 0x000317 0x00002000 0x00002000 0x00007 0x00007 E 0x1 |
| # ELF32-NEXT: DYNAMIC 0x000314 0x00001000 0x00001000 0x00003 0x00003 RWE 0x1 |
| # ELF32-NEXT: INTERP 0x00031e 0x00003000 0x00003000 0x00004 0x00004 RW 0x1 |
| # ELF32-NEXT: [Requesting program interpreter: ABC] |
| # ELF32-NEXT: NOTE 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: SHLIB 0x000314 0x00001000 0x00001000 0x00001 0x00001 0x1 |
| # ELF32-NEXT: TLS 0x000322 0x00004000 0x00004000 0x00001 0x00001 0x1 |
| # ELF32-NEXT: <unknown>: 0x60000000 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: GNU_EH_FRAME 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: SUNW_UNWIND 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: GNU_STACK 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: GNU_RELRO 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: GNU_PROPERTY 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x65a3dbe6 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x65a3dbe7 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x65a41be6 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x6fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x70000000 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x70000001 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x70000002 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x70000003 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-NEXT: <unknown>: 0x7fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 |
| # ELF32-EMPTY: |
| |
| # ELF64:There are 23 program headers, starting at offset 64 |
| # ELF64-EMPTY: |
| # ELF64-NEXT:Program Headers: |
| # ELF64-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align |
| # ELF64-NEXT: PHDR 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 W 0x1 |
| # ELF64-NEXT: PHDR 0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 |
| # ELF64-NEXT: NULL 0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 |
| # ELF64-NEXT: DYNAMIC 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 RWE 0x1 |
| # ELF64-NEXT: INTERP 0x000552 0x0000000000003000 0x0000000000003000 0x000004 0x000004 RW 0x1 |
| # ELF64-NEXT: [Requesting program interpreter: ABC] |
| # ELF64-NEXT: NOTE 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: SHLIB 0x000548 0x0000000000001000 0x0000000000001000 0x000001 0x000001 0x1 |
| # ELF64-NEXT: TLS 0x000556 0x0000000000004000 0x0000000000004000 0x000001 0x000001 0x1 |
| # ELF64-NEXT: <unknown>: 0x60000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: GNU_EH_FRAME 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: SUNW_UNWIND 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: GNU_STACK 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: GNU_RELRO 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: GNU_PROPERTY 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x65a3dbe6 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x65a3dbe7 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x65a41be6 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x6fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x70000001 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x70000003 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-NEXT: <unknown>: 0x7fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ELF64-EMPTY: |
| |
| # MAPPING: Section to Segment mapping: |
| # MAPPING-NEXT: Segment Sections... |
| # MAPPING-NEXT: 00 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 01 .bar.begin .bar.end {{$}} |
| # MAPPING-NEXT: 02 .bar.begin .bar.end {{$}} |
| # MAPPING-NEXT: 03 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 04 .interp {{$}} |
| # MAPPING-NEXT: 05 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 06 .foo.begin {{$}} |
| # MAPPING-NEXT: 07 .tls {{$}} |
| # MAPPING-NEXT: 08 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 09 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 10 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 11 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 12 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 13 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 14 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 15 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 16 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 17 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 18 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 19 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 20 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 21 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: 22 .foo.begin .foo.end {{$}} |
| # MAPPING-NEXT: None .unused .strtab .shstrtab {{$}} |
| |
| --- !ELF |
| FileHeader: |
| Class: ELFCLASS[[BITS]] |
| Data: ELFDATA2LSB |
| Type: ET_EXEC |
| Machine: [[MACHINE]] |
| Entry: 0x12345678 |
| Sections: |
| - Name: .foo.begin |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| Address: 0x1000 |
| Size: 0x1 |
| - Name: .foo.end |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| Size: 0x2 |
| - Name: .bar.begin |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| Address: 0x2000 |
| Size: 0x3 |
| - Name: .bar.end |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| Size: 0x4 |
| - Name: .interp |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| Address: 0x3000 |
| Content: "41424300" ## "ABC" |
| - Name: .tls |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC, SHF_TLS ] |
| Address: 0x4000 |
| Size: 0x1 |
| - Name: .unused |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC, SHF_TLS ] |
| Address: 0x5000 |
| Size: 0x1 |
| ProgramHeaders: |
| ## Case 1: an arbitrary segment with sections. |
| - Type: PT_PHDR |
| Flags: [ PF_W ] |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 2: another segment with different sections. |
| - Type: PT_PHDR |
| Flags: [ PF_X ] |
| VAddr: 0x2000 |
| Sections: |
| - Section: .bar.begin |
| - Section: .bar.end |
| ## Case 3: the PT_NULL segment. |
| - Type: PT_NULL |
| Flags: [ PF_X ] |
| VAddr: 0x2000 |
| Sections: |
| - Section: .bar.begin |
| - Section: .bar.end |
| ## Case 4: the PT_DYNAMIC segment. |
| - Type: PT_DYNAMIC |
| Flags: [ PF_R, PF_W, PF_X ] |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 5: the PT_INTERP segment. |
| - Type: PT_INTERP |
| Flags: [ PF_R, PF_W ] |
| VAddr: 0x3000 |
| Sections: |
| - Section: .interp |
| ## Case 6: the PT_NOTE segment. |
| - Type: PT_NOTE |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 7: the PT_SHLIB segment. |
| - Type: PT_SHLIB |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| ## Case 8: the PT_TLS segment. |
| - Type: PT_TLS |
| VAddr: 0x4000 |
| Sections: |
| - Section: .tls |
| ## Case 9: the PT_LOOS segment. |
| - Type: 0x60000000 ## PT_LOOS |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 10: the PT_GNU_EH_FRAME segment. |
| - Type: PT_GNU_EH_FRAME |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 11: the PT_SUNW_UNWIND segment. |
| - Type: 0x6464e550 ## PT_SUNW_UNWIND |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 12: the PT_GNU_STACK segment. |
| - Type: PT_GNU_STACK |
| Sections: |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 13: the PT_GNU_RELRO segment. |
| - Type: PT_GNU_RELRO |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 14: the PT_GNU_PROPERTY segment. |
| - Type: PT_GNU_PROPERTY |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 15: the PT_OPENBSD_RANDOMIZE segment. |
| - Type: 0x65a3dbe6 ## PT_OPENBSD_RANDOMIZE |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 16: the PT_OPENBSD_WXNEEDED segment. |
| - Type: 0x65a3dbe7 ## PT_OPENBSD_WXNEEDED |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 17: the PT_OPENBSD_BOOTDATA segment. |
| - Type: 0x65a41be6 ## PT_OPENBSD_BOOTDATA |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 18: the PT_HIOS segment. |
| - Type: 0x6fffffff ## PT_HIOS |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 19: the PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO segment. |
| - Type: 0x70000000 ## PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 20: the PT_ARM_EXIDX/PT_MIPS_RTPROC segment. |
| - Type: 0x70000001 ## PT_ARM_EXIDX, PT_MIPS_RTPROC |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 20: the PT_MIPS_OPTIONS segment. |
| - Type: 0x70000002 ## PT_MIPS_OPTIONS |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 21: the PT_MIPS_ABIFLAGS segment. |
| - Type: 0x70000003 ## PT_MIPS_ABIFLAGS |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| ## Case 22: the PT_HIPROC segment. |
| - Type: 0x7fffffff ## PT_HIPROC |
| VAddr: 0x1000 |
| Sections: |
| - Section: .foo.begin |
| - Section: .foo.end |
| |
| ## Check how we dump ARM specific program headers. |
| # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_ARM %s -o %tarm.elf |
| # RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM |
| |
| # ARM: <unknown>: 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ARM-NEXT: EXIDX 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # ARM-NEXT: <unknown>: 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| |
| ## Check how we dump MIPS specific program headers. |
| # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf |
| # RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS |
| |
| # MIPS: REGINFO 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # MIPS-NEXT: RTPROC 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # MIPS-NEXT: OPTIONS 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| # MIPS-NEXT: ABIFLAGS 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 |
| |
| ## Check we report a warning when a program interpreter name is non-null-terminated or when |
| ## PT_INTERP has an offset that goes past the end of the file. |
| # RUN: yaml2obj --docnum=2 %s -o %t.err |
| |
| ## Show the size of the output produced. It is used in the YAML below. |
| # RUN: wc -c < %t.err | FileCheck %s --check-prefix=SIZE |
| # SIZE: 560 |
| |
| ## Write the additional 'C', '\0, 'C' bytes to the end. |
| # RUN: echo -n -e "C\x00C" >> %t.err |
| |
| # RUN: llvm-readelf --program-headers %t.err 2>&1 | \ |
| # RUN: FileCheck %s -DFILE=%t.err --check-prefix=ERROR-INTERP |
| |
| # ERROR-INTERP: Type Offset |
| # ERROR-INTERP-NEXT: INTERP 0x000[[#%x,OFFSET:0x230]] |
| # ERROR-INTERP-NEXT: [Requesting program interpreter: C] |
| # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 1]] |
| # ERROR-INTERP-NEXT: [Requesting program interpreter: ] |
| # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 2]] |
| # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+2]]: it is not null-terminated |
| # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 3]] |
| # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+3]]: it goes past the end of the file (0x[[#OFFSET + 3]]) |
| # ERROR-INTERP-NEXT: INTERP 0xaabbccddeeff1122 |
| # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0xaabbccddeeff1122: it goes past the end of the file (0x[[#OFFSET + 3]]) |
| |
| --- !ELF |
| FileHeader: |
| Class: ELFCLASS64 |
| Data: ELFDATA2LSB |
| Type: ET_EXEC |
| Machine: EM_X86_64 |
| ProgramHeaders: |
| ## Case 1: the offset points to the first additional byte. |
| - Type: PT_INTERP |
| Offset: 560 |
| ## Case 1: the offset points to the second additional byte, |
| ## which is a null byte. |
| - Type: PT_INTERP |
| Offset: 561 |
| ## Case 3: the offset points to the third additional |
| ## byte, which is the last byte in the file. |
| - Type: PT_INTERP |
| Offset: 562 |
| ## Case 4: the offset goes 1 byte past the end of the file. |
| - Type: PT_INTERP |
| Offset: 563 |
| ## Case 5: an arbitrary large offset that goes past the end of the file. |
| - Type: PT_INTERP |
| Offset: 0xAABBCCDDEEFF1122 |