1dbf520f6SGeorgii Rymar# RUN: yaml2obj %s --docnum=1 -o %t.i386 2dbf520f6SGeorgii Rymar# RUN: llvm-readobj -h %t.i386 | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.i386 --check-prefix I386 3dbf520f6SGeorgii Rymar# RUN: llvm-readobj --file-header %t.i386 | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.i386 --check-prefix I386 4dbf520f6SGeorgii Rymar# RUN: llvm-readobj --file-headers %t.i386 | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.i386 --check-prefix I386 5dbf520f6SGeorgii Rymar 6dbf520f6SGeorgii Rymar# I386:File: [[FILE]] 7536ba637SFangrui Song# I386-NEXT:Format: elf32-i386 8dbf520f6SGeorgii Rymar# I386-NEXT:Arch: i386 9dbf520f6SGeorgii Rymar# I386-NEXT:AddressSize: 32bit 10dbf520f6SGeorgii Rymar# I386-NEXT:LoadName: <Not found> 11dbf520f6SGeorgii Rymar# I386-NEXT:ElfHeader { 12dbf520f6SGeorgii Rymar# I386-NEXT: Ident { 13dbf520f6SGeorgii Rymar# I386-NEXT: Magic: (7F 45 4C 46) 14dbf520f6SGeorgii Rymar# I386-NEXT: Class: 32-bit (0x1) 15dbf520f6SGeorgii Rymar# I386-NEXT: DataEncoding: LittleEndian (0x1) 16dbf520f6SGeorgii Rymar# I386-NEXT: FileVersion: 1 17dbf520f6SGeorgii Rymar# I386-NEXT: OS/ABI: GNU/Linux (0x3) 18dbf520f6SGeorgii Rymar# I386-NEXT: ABIVersion: 0 19dbf520f6SGeorgii Rymar# I386-NEXT: Unused: (00 00 00 00 00 00 00) 20dbf520f6SGeorgii Rymar# I386-NEXT: } 21dbf520f6SGeorgii Rymar# I386-NEXT: Type: Relocatable (0x1) 22dbf520f6SGeorgii Rymar# I386-NEXT: Machine: EM_386 (0x3) 23dbf520f6SGeorgii Rymar# I386-NEXT: Version: 1 24dbf520f6SGeorgii Rymar# I386-NEXT: Entry: 0x0 25dbf520f6SGeorgii Rymar# I386-NEXT: ProgramHeaderOffset: 0x0 26dbf520f6SGeorgii Rymar# I386-NEXT: SectionHeaderOffset: 0x48 27dbf520f6SGeorgii Rymar# I386-NEXT: Flags [ (0x0) 28dbf520f6SGeorgii Rymar# I386-NEXT: ] 29dbf520f6SGeorgii Rymar# I386-NEXT: HeaderSize: 52 30dbf520f6SGeorgii Rymar# I386-NEXT: ProgramHeaderEntrySize: 0 31dbf520f6SGeorgii Rymar# I386-NEXT: ProgramHeaderCount: 0 32dbf520f6SGeorgii Rymar# I386-NEXT: SectionHeaderEntrySize: 40 33dbf520f6SGeorgii Rymar# I386-NEXT: SectionHeaderCount: 3 34dbf520f6SGeorgii Rymar# I386-NEXT: StringTableSectionIndex: 2 35dbf520f6SGeorgii Rymar# I386-NEXT:} 36dbf520f6SGeorgii Rymar# I386-NOT:{{.}} 37dbf520f6SGeorgii Rymar 38dbf520f6SGeorgii Rymar--- !ELF 39dbf520f6SGeorgii RymarFileHeader: 40dbf520f6SGeorgii Rymar Class: ELFCLASS32 41dbf520f6SGeorgii Rymar Data: ELFDATA2LSB 42dbf520f6SGeorgii Rymar OSABI: ELFOSABI_GNU 43dbf520f6SGeorgii Rymar Type: ET_REL 44dbf520f6SGeorgii Rymar Machine: EM_386 45dbf520f6SGeorgii Rymar 46dbf520f6SGeorgii Rymar# RUN: yaml2obj %s --docnum=2 -o %t.x86-64 47dbf520f6SGeorgii Rymar# RUN: llvm-readobj -h %t.x86-64 \ 48dbf520f6SGeorgii Rymar# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.x86-64 --check-prefix X86-64 49dbf520f6SGeorgii Rymar# RUN: llvm-readobj --file-header %t.x86-64 \ 50dbf520f6SGeorgii Rymar# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.x86-64 --check-prefix X86-64 51dbf520f6SGeorgii Rymar# RUN: llvm-readobj --file-headers %t.x86-64 \ 52dbf520f6SGeorgii Rymar# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.x86-64 --check-prefix X86-64 53dbf520f6SGeorgii Rymar 54dbf520f6SGeorgii Rymar# X86-64:File: [[FILE]] 55536ba637SFangrui Song# X86-64-NEXT:Format: elf64-x86-64 56dbf520f6SGeorgii Rymar# X86-64-NEXT:Arch: x86_64 57dbf520f6SGeorgii Rymar# X86-64-NEXT:AddressSize: 64bit 58dbf520f6SGeorgii Rymar# X86-64-NEXT:LoadName: <Not found> 59dbf520f6SGeorgii Rymar# X86-64-NEXT:ElfHeader { 60dbf520f6SGeorgii Rymar# X86-64-NEXT: Ident { 61dbf520f6SGeorgii Rymar# X86-64-NEXT: Magic: (7F 45 4C 46) 62dbf520f6SGeorgii Rymar# X86-64-NEXT: Class: 64-bit (0x2) 63dbf520f6SGeorgii Rymar# X86-64-NEXT: DataEncoding: LittleEndian (0x1) 64dbf520f6SGeorgii Rymar# X86-64-NEXT: FileVersion: 1 65dbf520f6SGeorgii Rymar# X86-64-NEXT: OS/ABI: GNU/Linux (0x3) 66dbf520f6SGeorgii Rymar# X86-64-NEXT: ABIVersion: 0 67dbf520f6SGeorgii Rymar# X86-64-NEXT: Unused: (00 00 00 00 00 00 00) 68dbf520f6SGeorgii Rymar# X86-64-NEXT: } 69dbf520f6SGeorgii Rymar# X86-64-NEXT: Type: Relocatable (0x1) 70dbf520f6SGeorgii Rymar# X86-64-NEXT: Machine: EM_X86_64 (0x3E) 71dbf520f6SGeorgii Rymar# X86-64-NEXT: Version: 1 72dbf520f6SGeorgii Rymar# X86-64-NEXT: Entry: 0x0 73dbf520f6SGeorgii Rymar# X86-64-NEXT: ProgramHeaderOffset: 0x0 74dbf520f6SGeorgii Rymar# X86-64-NEXT: SectionHeaderOffset: 0x58 75dbf520f6SGeorgii Rymar# X86-64-NEXT: Flags [ (0x0) 76dbf520f6SGeorgii Rymar# X86-64-NEXT: ] 77dbf520f6SGeorgii Rymar# X86-64-NEXT: HeaderSize: 64 78dbf520f6SGeorgii Rymar# X86-64-NEXT: ProgramHeaderEntrySize: 0 79dbf520f6SGeorgii Rymar# X86-64-NEXT: ProgramHeaderCount: 0 80dbf520f6SGeorgii Rymar# X86-64-NEXT: SectionHeaderEntrySize: 64 81dbf520f6SGeorgii Rymar# X86-64-NEXT: SectionHeaderCount: 3 82dbf520f6SGeorgii Rymar# X86-64-NEXT: StringTableSectionIndex: 2 83dbf520f6SGeorgii Rymar# X86-64-NEXT:} 84dbf520f6SGeorgii Rymar# X86-64-NOT:{{.}} 85dbf520f6SGeorgii Rymar 86dbf520f6SGeorgii Rymar--- !ELF 87dbf520f6SGeorgii RymarFileHeader: 88dbf520f6SGeorgii Rymar Class: ELFCLASS64 89dbf520f6SGeorgii Rymar Data: ELFDATA2LSB 90dbf520f6SGeorgii Rymar OSABI: ELFOSABI_GNU 91dbf520f6SGeorgii Rymar Type: ET_REL 92dbf520f6SGeorgii Rymar Machine: EM_X86_64 93dbf520f6SGeorgii Rymar 94dbf520f6SGeorgii Rymar# RUN: yaml2obj %s --docnum=3 -o %t.lanai 95dbf520f6SGeorgii Rymar# RUN: llvm-readobj -h %t.lanai \ 96dbf520f6SGeorgii Rymar# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.lanai --check-prefix LANAI 97dbf520f6SGeorgii Rymar# RUN: llvm-readobj --file-header %t.lanai \ 98dbf520f6SGeorgii Rymar# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.lanai --check-prefix LANAI 99dbf520f6SGeorgii Rymar# RUN: llvm-readobj --file-headers %t.lanai \ 100dbf520f6SGeorgii Rymar# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.lanai --check-prefix LANAI 101dbf520f6SGeorgii Rymar 102dbf520f6SGeorgii Rymar--- !ELF 103dbf520f6SGeorgii RymarFileHeader: 104dbf520f6SGeorgii Rymar Class: ELFCLASS32 105dbf520f6SGeorgii Rymar Data: ELFDATA2MSB 106dbf520f6SGeorgii Rymar Type: ET_REL 107dbf520f6SGeorgii Rymar Machine: EM_LANAI 108dbf520f6SGeorgii Rymar 109dbf520f6SGeorgii Rymar# LANAI:File: [[FILE]] 110536ba637SFangrui Song# LANAI-NEXT:Format: elf32-lanai 111dbf520f6SGeorgii Rymar# LANAI-NEXT:Arch: lanai 112dbf520f6SGeorgii Rymar# LANAI-NEXT:AddressSize: 32bit 113dbf520f6SGeorgii Rymar# LANAI-NEXT:LoadName: <Not found> 114dbf520f6SGeorgii Rymar# LANAI-NEXT:ElfHeader { 115dbf520f6SGeorgii Rymar# LANAI-NEXT: Ident { 116dbf520f6SGeorgii Rymar# LANAI-NEXT: Magic: (7F 45 4C 46) 117dbf520f6SGeorgii Rymar# LANAI-NEXT: Class: 32-bit (0x1) 118dbf520f6SGeorgii Rymar# LANAI-NEXT: DataEncoding: BigEndian (0x2) 119dbf520f6SGeorgii Rymar# LANAI-NEXT: FileVersion: 1 120dbf520f6SGeorgii Rymar# LANAI-NEXT: OS/ABI: SystemV (0x0) 121dbf520f6SGeorgii Rymar# LANAI-NEXT: ABIVersion: 0 122dbf520f6SGeorgii Rymar# LANAI-NEXT: Unused: (00 00 00 00 00 00 00) 123dbf520f6SGeorgii Rymar# LANAI-NEXT: } 124dbf520f6SGeorgii Rymar# LANAI-NEXT: Type: Relocatable (0x1) 125dbf520f6SGeorgii Rymar# LANAI-NEXT: Machine: EM_LANAI (0xF4) 126dbf520f6SGeorgii Rymar# LANAI-NEXT: Version: 1 127dbf520f6SGeorgii Rymar# LANAI-NEXT: Entry: 0x0 128dbf520f6SGeorgii Rymar# LANAI-NEXT: ProgramHeaderOffset: 0x0 129dbf520f6SGeorgii Rymar# LANAI-NEXT: SectionHeaderOffset: 0x48 130dbf520f6SGeorgii Rymar# LANAI-NEXT: Flags [ (0x0) 131dbf520f6SGeorgii Rymar# LANAI-NEXT: ] 132dbf520f6SGeorgii Rymar# LANAI-NEXT: HeaderSize: 52 133dbf520f6SGeorgii Rymar# LANAI-NEXT: ProgramHeaderEntrySize: 0 134dbf520f6SGeorgii Rymar# LANAI-NEXT: ProgramHeaderCount: 0 135dbf520f6SGeorgii Rymar# LANAI-NEXT: SectionHeaderEntrySize: 40 136dbf520f6SGeorgii Rymar# LANAI-NEXT: SectionHeaderCount: 3 137dbf520f6SGeorgii Rymar# LANAI-NEXT: StringTableSectionIndex: 2 138dbf520f6SGeorgii Rymar# LANAI-NEXT:} 139dbf520f6SGeorgii Rymar# LANAI-NOT:{{.}} 14099a6401aSGeorgii Rymar 14199a6401aSGeorgii Rymar## Check we are able to dump the file header when the section header table can't be read. 14299a6401aSGeorgii Rymar 14399a6401aSGeorgii Rymar# RUN: yaml2obj %s --docnum=4 -o %t.invalid1 14499a6401aSGeorgii Rymar# RUN: not llvm-readobj --file-headers %t.invalid1 2>&1 \ 14599a6401aSGeorgii Rymar# RUN: | FileCheck %s --implicit-check-not=warning: -DFILE=%t.invalid1 \ 14699a6401aSGeorgii Rymar# RUN: -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-LLVM 14799a6401aSGeorgii Rymar# RUN: not llvm-readelf --file-headers %t.invalid1 2>&1 \ 14899a6401aSGeorgii Rymar# RUN: | FileCheck %s --implicit-check-not=warning: -DFILE=%t.invalid1 \ 14999a6401aSGeorgii Rymar# RUN: -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-GNU 15099a6401aSGeorgii Rymar 15199a6401aSGeorgii Rymar# INVALID-LLVM: File: [[FILE]] 15299a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Format: elf64-unknown 15399a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Arch: unknown 15499a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: AddressSize: 64bit 15599a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: LoadName: <Not found> 15699a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: ElfHeader { 15799a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Ident { 15899a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Magic: (7F 45 4C 46) 15999a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Class: 64-bit (0x2) 16099a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: DataEncoding: LittleEndian (0x1) 16199a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: FileVersion: 1 16299a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: OS/ABI: SystemV (0x0) 16399a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: ABIVersion: 0 16499a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Unused: (00 00 00 00 00 00 00) 16599a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: } 16699a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Type: Relocatable (0x1) 16799a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Machine: EM_NONE (0x0) 16899a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Version: 1 16999a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Entry: 0x0 17099a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: ProgramHeaderOffset: 0x0 17199a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: SectionHeaderOffset: 0x1000 17299a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: Flags [ (0x0) 17399a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: ] 17499a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: HeaderSize: 64 17599a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: ProgramHeaderEntrySize: 0 17699a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: ProgramHeaderCount: 0 17799a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: SectionHeaderEntrySize: 64 17899a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: SectionHeaderCount: [[SECHDRCOUNT]] 17999a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: StringTableSectionIndex: [[SECHDRSTRTABINDEX]] 18099a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: } 18199a6401aSGeorgii Rymar# INVALID-LLVM-NEXT: error: '[[FILE]]': unable to continue dumping, the file is corrupt: section header table goes past the end of the file: e_shoff = 0x1000 18299a6401aSGeorgii Rymar 18399a6401aSGeorgii Rymar# INVALID-GNU: ELF Header: 18499a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 18599a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Class: ELF64 18699a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Data: 2's complement, little endian 18799a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Version: 1 (current) 18899a6401aSGeorgii Rymar# INVALID-GNU-NEXT: OS/ABI: UNIX - System V 18999a6401aSGeorgii Rymar# INVALID-GNU-NEXT: ABI Version: 0 19099a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Type: REL (Relocatable file) 19199a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Machine: None 19299a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Version: 0x1 19399a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Entry point address: 0x0 19499a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Start of program headers: 0 (bytes into file) 19599a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Start of section headers: 4096 (bytes into file) 19699a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Flags: 0x0 19799a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Size of this header: 64 (bytes) 19899a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Size of program headers: 0 (bytes) 19999a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Number of program headers: 0 20099a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Size of section headers: 64 (bytes) 20199a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Number of section headers: [[SECHDRCOUNT]] 20299a6401aSGeorgii Rymar# INVALID-GNU-NEXT: Section header string table index: [[SECHDRSTRTABINDEX]] 20399a6401aSGeorgii Rymar# INVALID-GNU-NEXT: error: '[[FILE]]': unable to continue dumping, the file is corrupt: section header table goes past the end of the file: e_shoff = 0x1000 20499a6401aSGeorgii Rymar 20599a6401aSGeorgii Rymar--- !ELF 20699a6401aSGeorgii RymarFileHeader: 20799a6401aSGeorgii Rymar Class: ELFCLASS64 20899a6401aSGeorgii Rymar Data: ELFDATA2LSB 20999a6401aSGeorgii Rymar Type: ET_REL 21099a6401aSGeorgii Rymar## The section header table offset goes past the EOF. 21199a6401aSGeorgii Rymar EShOff: 0x1000 21299a6401aSGeorgii Rymar## The number of section headers is too large, the file is 21399a6401aSGeorgii Rymar## too little to contain so many sections. 21499a6401aSGeorgii Rymar EShNum: [[SHNUM=0x2000]] 21599a6401aSGeorgii Rymar## The index of the section name string table is too large. 21699a6401aSGeorgii Rymar## The section would be past the EOF. 21799a6401aSGeorgii Rymar EShStrNdx: [[SHSTRNDX=0x3000]] 218*9c89dcf8SGeorgii RymarSections: 219*9c89dcf8SGeorgii Rymar - Type: SectionHeaderTable 22099a6401aSGeorgii Rymar NoHeaders: true 22199a6401aSGeorgii Rymar 22299a6401aSGeorgii Rymar## Check we don't dump anything except the file header when the section header table can't be read. 22399a6401aSGeorgii Rymar 22499a6401aSGeorgii Rymar# RUN: not llvm-readobj -a %t.invalid1 2>&1 \ 22599a6401aSGeorgii Rymar# RUN: | FileCheck %s -DFILE=%t.invalid1 -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-LLVM 22699a6401aSGeorgii Rymar# RUN: not llvm-readelf -a %t.invalid1 2>&1 \ 22799a6401aSGeorgii Rymar# RUN: | FileCheck %s -DFILE=%t.invalid1 -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-GNU 22899a6401aSGeorgii Rymar 22999a6401aSGeorgii Rymar## Check what we print when e_shnum == 0, e_shstrndx == SHN_XINDEX and the section header table can't be read. 23099a6401aSGeorgii Rymar 23199a6401aSGeorgii Rymar# RUN: yaml2obj %s -DSHNUM=0 -DSHSTRNDX=0xffff --docnum=4 -o %t.invalid2 23299a6401aSGeorgii Rymar# RUN: not llvm-readobj --file-headers %t.invalid2 2>&1 \ 23399a6401aSGeorgii Rymar# RUN: | FileCheck %s -DFILE=%t.invalid2 -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-LLVM 23499a6401aSGeorgii Rymar# RUN: not llvm-readelf --file-headers %t.invalid2 2>&1 \ 23599a6401aSGeorgii Rymar# RUN: | FileCheck %s -DFILE=%t.invalid2 -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-GNU 236