1# RUN: yaml2obj %s --docnum=1 -o %t.i386 2# RUN: llvm-readobj -h %t.i386 | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.i386 --check-prefix I386 3# RUN: llvm-readobj --file-header %t.i386 | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.i386 --check-prefix I386 4# RUN: llvm-readobj --file-headers %t.i386 | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.i386 --check-prefix I386 5 6# I386:File: [[FILE]] 7# I386-NEXT:Format: elf32-i386 8# I386-NEXT:Arch: i386 9# I386-NEXT:AddressSize: 32bit 10# I386-NEXT:LoadName: <Not found> 11# I386-NEXT:ElfHeader { 12# I386-NEXT: Ident { 13# I386-NEXT: Magic: (7F 45 4C 46) 14# I386-NEXT: Class: 32-bit (0x1) 15# I386-NEXT: DataEncoding: LittleEndian (0x1) 16# I386-NEXT: FileVersion: 1 17# I386-NEXT: OS/ABI: GNU/Linux (0x3) 18# I386-NEXT: ABIVersion: 0 19# I386-NEXT: Unused: (00 00 00 00 00 00 00) 20# I386-NEXT: } 21# I386-NEXT: Type: Relocatable (0x1) 22# I386-NEXT: Machine: EM_386 (0x3) 23# I386-NEXT: Version: 1 24# I386-NEXT: Entry: 0x0 25# I386-NEXT: ProgramHeaderOffset: 0x0 26# I386-NEXT: SectionHeaderOffset: 0x48 27# I386-NEXT: Flags [ (0x0) 28# I386-NEXT: ] 29# I386-NEXT: HeaderSize: 52 30# I386-NEXT: ProgramHeaderEntrySize: 0 31# I386-NEXT: ProgramHeaderCount: 0 32# I386-NEXT: SectionHeaderEntrySize: 40 33# I386-NEXT: SectionHeaderCount: 3 34# I386-NEXT: StringTableSectionIndex: 2 35# I386-NEXT:} 36# I386-NOT:{{.}} 37 38--- !ELF 39FileHeader: 40 Class: ELFCLASS32 41 Data: ELFDATA2LSB 42 OSABI: ELFOSABI_GNU 43 Type: ET_REL 44 Machine: EM_386 45 46# RUN: yaml2obj %s --docnum=2 -o %t.x86-64 47# RUN: llvm-readobj -h %t.x86-64 \ 48# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.x86-64 --check-prefix X86-64 49# RUN: llvm-readobj --file-header %t.x86-64 \ 50# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.x86-64 --check-prefix X86-64 51# RUN: llvm-readobj --file-headers %t.x86-64 \ 52# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.x86-64 --check-prefix X86-64 53 54# X86-64:File: [[FILE]] 55# X86-64-NEXT:Format: elf64-x86-64 56# X86-64-NEXT:Arch: x86_64 57# X86-64-NEXT:AddressSize: 64bit 58# X86-64-NEXT:LoadName: <Not found> 59# X86-64-NEXT:ElfHeader { 60# X86-64-NEXT: Ident { 61# X86-64-NEXT: Magic: (7F 45 4C 46) 62# X86-64-NEXT: Class: 64-bit (0x2) 63# X86-64-NEXT: DataEncoding: LittleEndian (0x1) 64# X86-64-NEXT: FileVersion: 1 65# X86-64-NEXT: OS/ABI: GNU/Linux (0x3) 66# X86-64-NEXT: ABIVersion: 0 67# X86-64-NEXT: Unused: (00 00 00 00 00 00 00) 68# X86-64-NEXT: } 69# X86-64-NEXT: Type: Relocatable (0x1) 70# X86-64-NEXT: Machine: EM_X86_64 (0x3E) 71# X86-64-NEXT: Version: 1 72# X86-64-NEXT: Entry: 0x0 73# X86-64-NEXT: ProgramHeaderOffset: 0x0 74# X86-64-NEXT: SectionHeaderOffset: 0x58 75# X86-64-NEXT: Flags [ (0x0) 76# X86-64-NEXT: ] 77# X86-64-NEXT: HeaderSize: 64 78# X86-64-NEXT: ProgramHeaderEntrySize: 0 79# X86-64-NEXT: ProgramHeaderCount: 0 80# X86-64-NEXT: SectionHeaderEntrySize: 64 81# X86-64-NEXT: SectionHeaderCount: 3 82# X86-64-NEXT: StringTableSectionIndex: 2 83# X86-64-NEXT:} 84# X86-64-NOT:{{.}} 85 86--- !ELF 87FileHeader: 88 Class: ELFCLASS64 89 Data: ELFDATA2LSB 90 OSABI: ELFOSABI_GNU 91 Type: ET_REL 92 Machine: EM_X86_64 93 94# RUN: yaml2obj %s --docnum=3 -o %t.lanai 95# RUN: llvm-readobj -h %t.lanai \ 96# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.lanai --check-prefix LANAI 97# RUN: llvm-readobj --file-header %t.lanai \ 98# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.lanai --check-prefix LANAI 99# RUN: llvm-readobj --file-headers %t.lanai \ 100# RUN: | FileCheck %s --strict-whitespace --match-full-lines -DFILE=%t.lanai --check-prefix LANAI 101 102--- !ELF 103FileHeader: 104 Class: ELFCLASS32 105 Data: ELFDATA2MSB 106 Type: ET_REL 107 Machine: EM_LANAI 108 109# LANAI:File: [[FILE]] 110# LANAI-NEXT:Format: elf32-lanai 111# LANAI-NEXT:Arch: lanai 112# LANAI-NEXT:AddressSize: 32bit 113# LANAI-NEXT:LoadName: <Not found> 114# LANAI-NEXT:ElfHeader { 115# LANAI-NEXT: Ident { 116# LANAI-NEXT: Magic: (7F 45 4C 46) 117# LANAI-NEXT: Class: 32-bit (0x1) 118# LANAI-NEXT: DataEncoding: BigEndian (0x2) 119# LANAI-NEXT: FileVersion: 1 120# LANAI-NEXT: OS/ABI: SystemV (0x0) 121# LANAI-NEXT: ABIVersion: 0 122# LANAI-NEXT: Unused: (00 00 00 00 00 00 00) 123# LANAI-NEXT: } 124# LANAI-NEXT: Type: Relocatable (0x1) 125# LANAI-NEXT: Machine: EM_LANAI (0xF4) 126# LANAI-NEXT: Version: 1 127# LANAI-NEXT: Entry: 0x0 128# LANAI-NEXT: ProgramHeaderOffset: 0x0 129# LANAI-NEXT: SectionHeaderOffset: 0x48 130# LANAI-NEXT: Flags [ (0x0) 131# LANAI-NEXT: ] 132# LANAI-NEXT: HeaderSize: 52 133# LANAI-NEXT: ProgramHeaderEntrySize: 0 134# LANAI-NEXT: ProgramHeaderCount: 0 135# LANAI-NEXT: SectionHeaderEntrySize: 40 136# LANAI-NEXT: SectionHeaderCount: 3 137# LANAI-NEXT: StringTableSectionIndex: 2 138# LANAI-NEXT:} 139# LANAI-NOT:{{.}} 140 141## Check we are able to dump the file header when the section header table can't be read. 142 143# RUN: yaml2obj %s --docnum=4 -o %t.invalid1 144# RUN: not llvm-readobj --file-headers %t.invalid1 2>&1 \ 145# RUN: | FileCheck %s --implicit-check-not=warning: -DFILE=%t.invalid1 \ 146# RUN: -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-LLVM 147# RUN: not llvm-readelf --file-headers %t.invalid1 2>&1 \ 148# RUN: | FileCheck %s --implicit-check-not=warning: -DFILE=%t.invalid1 \ 149# RUN: -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-GNU 150 151# INVALID-LLVM: File: [[FILE]] 152# INVALID-LLVM-NEXT: Format: elf64-unknown 153# INVALID-LLVM-NEXT: Arch: unknown 154# INVALID-LLVM-NEXT: AddressSize: 64bit 155# INVALID-LLVM-NEXT: LoadName: <Not found> 156# INVALID-LLVM-NEXT: ElfHeader { 157# INVALID-LLVM-NEXT: Ident { 158# INVALID-LLVM-NEXT: Magic: (7F 45 4C 46) 159# INVALID-LLVM-NEXT: Class: 64-bit (0x2) 160# INVALID-LLVM-NEXT: DataEncoding: LittleEndian (0x1) 161# INVALID-LLVM-NEXT: FileVersion: 1 162# INVALID-LLVM-NEXT: OS/ABI: SystemV (0x0) 163# INVALID-LLVM-NEXT: ABIVersion: 0 164# INVALID-LLVM-NEXT: Unused: (00 00 00 00 00 00 00) 165# INVALID-LLVM-NEXT: } 166# INVALID-LLVM-NEXT: Type: Relocatable (0x1) 167# INVALID-LLVM-NEXT: Machine: EM_NONE (0x0) 168# INVALID-LLVM-NEXT: Version: 1 169# INVALID-LLVM-NEXT: Entry: 0x0 170# INVALID-LLVM-NEXT: ProgramHeaderOffset: 0x0 171# INVALID-LLVM-NEXT: SectionHeaderOffset: 0x1000 172# INVALID-LLVM-NEXT: Flags [ (0x0) 173# INVALID-LLVM-NEXT: ] 174# INVALID-LLVM-NEXT: HeaderSize: 64 175# INVALID-LLVM-NEXT: ProgramHeaderEntrySize: 0 176# INVALID-LLVM-NEXT: ProgramHeaderCount: 0 177# INVALID-LLVM-NEXT: SectionHeaderEntrySize: 64 178# INVALID-LLVM-NEXT: SectionHeaderCount: [[SECHDRCOUNT]] 179# INVALID-LLVM-NEXT: StringTableSectionIndex: [[SECHDRSTRTABINDEX]] 180# INVALID-LLVM-NEXT: } 181# 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 182 183# INVALID-GNU: ELF Header: 184# INVALID-GNU-NEXT: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 185# INVALID-GNU-NEXT: Class: ELF64 186# INVALID-GNU-NEXT: Data: 2's complement, little endian 187# INVALID-GNU-NEXT: Version: 1 (current) 188# INVALID-GNU-NEXT: OS/ABI: UNIX - System V 189# INVALID-GNU-NEXT: ABI Version: 0 190# INVALID-GNU-NEXT: Type: REL (Relocatable file) 191# INVALID-GNU-NEXT: Machine: None 192# INVALID-GNU-NEXT: Version: 0x1 193# INVALID-GNU-NEXT: Entry point address: 0x0 194# INVALID-GNU-NEXT: Start of program headers: 0 (bytes into file) 195# INVALID-GNU-NEXT: Start of section headers: 4096 (bytes into file) 196# INVALID-GNU-NEXT: Flags: 0x0 197# INVALID-GNU-NEXT: Size of this header: 64 (bytes) 198# INVALID-GNU-NEXT: Size of program headers: 0 (bytes) 199# INVALID-GNU-NEXT: Number of program headers: 0 200# INVALID-GNU-NEXT: Size of section headers: 64 (bytes) 201# INVALID-GNU-NEXT: Number of section headers: [[SECHDRCOUNT]] 202# INVALID-GNU-NEXT: Section header string table index: [[SECHDRSTRTABINDEX]] 203# 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 204 205--- !ELF 206FileHeader: 207 Class: ELFCLASS64 208 Data: ELFDATA2LSB 209 Type: ET_REL 210## The section header table offset goes past the EOF. 211 EShOff: 0x1000 212## The number of section headers is too large, the file is 213## too little to contain so many sections. 214 EShNum: [[SHNUM=0x2000]] 215## The index of the section name string table is too large. 216## The section would be past the EOF. 217 EShStrNdx: [[SHSTRNDX=0x3000]] 218SectionHeaderTable: 219 NoHeaders: true 220 221## Check we don't dump anything except the file header when the section header table can't be read. 222 223# RUN: not llvm-readobj -a %t.invalid1 2>&1 \ 224# RUN: | FileCheck %s -DFILE=%t.invalid1 -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-LLVM 225# RUN: not llvm-readelf -a %t.invalid1 2>&1 \ 226# RUN: | FileCheck %s -DFILE=%t.invalid1 -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-GNU 227 228## Check what we print when e_shnum == 0, e_shstrndx == SHN_XINDEX and the section header table can't be read. 229 230# RUN: yaml2obj %s -DSHNUM=0 -DSHSTRNDX=0xffff --docnum=4 -o %t.invalid2 231# RUN: not llvm-readobj --file-headers %t.invalid2 2>&1 \ 232# RUN: | FileCheck %s -DFILE=%t.invalid2 -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-LLVM 233# RUN: not llvm-readelf --file-headers %t.invalid2 2>&1 \ 234# RUN: | FileCheck %s -DFILE=%t.invalid2 -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-GNU 235