1## Test reading ELF with .dynsym under the following conditions: 2## * Section headers are available. 3## * Section headers are stripped but there is a DT_GNU_HASH dynamic tag. 4## * Section headers are stripped but there is a DT_HASH dynamic tag. 5 6## Test if llvm-ifs reads DT_SYMTAB size through section headers by puting the wrong terminator in DT_GNU_HASH. 7# RUN: yaml2obj %s -o %tfull -DGNUHASHVALUE="[0x9]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00" 8# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %tfull | FileCheck %s 9 10## Test if llvm-ifs fails to read DT_SYMTAB size through section headers when the value of sh_entsize is invalid. 11# RUN: yaml2obj %s -o %tfull -DGNUHASHVALUE="[0x9]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00" -DENTSIZE="0x19" 12# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=- %tfull 2>&1 | FileCheck %s --check-prefix=BADENTSIZE 13 14## Test if llvm-ifs reads DT_SYMTAB size through DT_GNU_HASH. 15# RUN: yaml2obj %s -o %tw.gnu.hash -DGNUHASHVALUE="[0x8, 0x9]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00" -DNOHEADER="true" 16# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %tw.gnu.hash | FileCheck %s 17 18## Test if llvm-ifs fails to read DT_SYMTAB size through DT_GNU_HASH when there is no terminator. 19# RUN: yaml2obj %s -o %tw.gnu.hash -DGNUHASHVALUE="[0x8, 0xA]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00" -DNOHEADER="true" 20# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=- %tw.gnu.hash 2>&1 | FileCheck %s --check-prefix=NOTERMINATOR 21 22# CHECK: --- !ifs-v1 23# CHECK-NEXT: IfsVersion: 3.0 24# CHECK-NEXT: Target: { ObjectFormat: ELF, Arch: AArch64, Endianness: little, BitWidth: 64 } 25# CHECK-NEXT: Symbols: 26# CHECK-NEXT: - { Name: bar, Type: Object, Size: 0, Undefined: true } 27# CHECK-NEXT: - { Name: foo, Type: Func, Undefined: true } 28# CHECK-NEXT: ... 29 30# BADENTSIZE: SHT_DYNSYM section has sh_size (72) % sh_entsize (25) that is not 0 31 32# NOTERMINATOR: error: no terminator found for GNU hash section before buffer end 33 34--- !ELF 35FileHeader: 36 Class: ELFCLASS64 37 Data: ELFDATA2LSB 38 Type: ET_DYN 39 Machine: EM_AARCH64 40Sections: 41 - Name: .text 42 Type: SHT_PROGBITS 43 - Name: .data 44 Type: SHT_PROGBITS 45 - Name: .strtab 46 Type: SHT_STRTAB 47 - Name: .shstrtab 48 Type: SHT_STRTAB 49 - Name: .dynsym 50 Type: SHT_DYNSYM 51 Flags: [ SHF_ALLOC ] 52 EntSize: [[ENTSIZE=0x18]] 53 Address: 0x400 54 AddressAlign: 0x400 55 - Name: .dynstr 56 Type: SHT_STRTAB 57 Flags: [ SHF_ALLOC ] 58 Address: 0x600 59 AddressAlign: 0x200 60 - Name: .dynamic 61 Type: SHT_DYNAMIC 62 Flags: [ SHF_ALLOC ] 63 Address: 0x800 64 AddressAlign: 0x200 65 Entries: 66 - Tag: DT_STRTAB 67 Value: 0x600 68 - Tag: DT_STRSZ 69 Value: 9 70 - Tag: DT_SYMTAB 71 Value: 0x400 72 - Tag: [[TAG1]] 73 Value: [[VAL1]] 74 - Tag: DT_NULL 75 Value: 0 76 - Name: .hash 77 Type: SHT_HASH 78 Flags: [ SHF_ALLOC ] 79 Address: 0xA00 80 AddressAlign: 0x200 81 Bucket: [ 1 ] 82 Chain: [ 1, 2, 3 ] 83 - Name: .gnu.hash 84 Type: SHT_GNU_HASH 85 Flags: [ SHF_ALLOC ] 86 Address: 0xC00 87 AddressAlign: 0x200 88 Header: 89 SymNdx: 0x1 90 Shift2: 0x2 91 MaskWords: 2 92 NBuckets: 2 93 BloomFilter: [0x3, 0x4] 94 HashBuckets: [0x0, 0x1] 95 HashValues: [[GNUHASHVALUE]] 96 - Type: SectionHeaderTable 97 NoHeaders: [[NOHEADER=false]] 98DynamicSymbols: 99 - Name: foo 100 Type: STT_FUNC 101 Value: 0x100 102 Binding: 1 103 - Name: bar 104 Type: STT_OBJECT 105 Value: 0x200 106 Binding: 1 107ProgramHeaders: 108 - Type: PT_LOAD 109 VAddr: 0x400 110 FirstSec: .dynsym 111 LastSec: .gnu.hash 112 - Type: PT_DYNAMIC 113 VAddr: 0x800 114 FirstSec: .dynamic 115 LastSec: .dynamic 116