1## Check how obj2yaml produces SHT_GNU_HASH section descriptions. 2 3## Check that obj2yaml uses "Header", "BloomFilter", "HashBuckets" and "HashValues" 4## tags to describe a SHT_GNU_HASH section when it has content of a correct size. 5 6# RUN: yaml2obj --docnum=1 %s -o %t1 7# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=FIELDS 8 9# FIELDS: - Name: .gnu.hash 10# FIELDS-NEXT: Type: SHT_GNU_HASH 11# FIELDS-NEXT: Flags: [ SHF_ALLOC ] 12# FIELDS-NEXT: Header: 13# FIELDS-NEXT: SymNdx: 0x1 14# FIELDS-NEXT: Shift2: 0x2 15# FIELDS-NEXT: BloomFilter: [ 0x3, 0x4 ] 16# FIELDS-NEXT: HashBuckets: [ 0x5, 0x6, 0x7 ] 17# FIELDS-NEXT: HashValues: [ 0x8, 0x9, 0xA, 0xB ] 18 19--- !ELF 20FileHeader: 21 Class: ELFCLASS32 22 Data: ELFDATA2LSB 23 Type: ET_DYN 24Sections: 25 - Name: .gnu.hash 26 Type: SHT_GNU_HASH 27 Flags: [ SHF_ALLOC ] 28 Header: 29 SymNdx: 0x1 30 Shift2: 0x2 31 BloomFilter: [0x3, 0x4] 32 HashBuckets: [0x5, 0x6, 0x7] 33 HashValues: [0x8, 0x9, 0xA, 0xB] 34 35## Check how we handle broken cases. 36 37# RUN: yaml2obj --docnum=2 %s -o %t2 38# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=INVALID 39 40# INVALID: - Name: .gnu.hash.tooshort 41# INVALID-NEXT: Type: SHT_GNU_HASH 42# INVALID-NEXT: Flags: [ SHF_ALLOC ] 43# INVALID-NEXT: Content: 112233445566778899AABBCCDDEEFF 44# INVALID-NEXT: - Name: .gnu.hash.empty 45# INVALID-NEXT: Type: SHT_GNU_HASH 46# INVALID-NEXT: Flags: [ SHF_ALLOC ] 47# INVALID-NEXT: Address: 0xF 48# INVALID-NEXT: Header: 49# INVALID-NEXT: SymNdx: 0x0 50# INVALID-NEXT: Shift2: 0x0 51# INVALID-NEXT: BloomFilter: [ ] 52# INVALID-NEXT: HashBuckets: [ ] 53# INVALID-NEXT: HashValues: [ ] 54# INVALID-NEXT: - Name: .gnu.hash.broken.maskwords 55# INVALID-NEXT: Type: SHT_GNU_HASH 56# INVALID-NEXT: Content: '00000000000000000100000000000000' 57# INVALID-NEXT: - Name: .gnu.hash.broken.nbuckets 58# INVALID-NEXT: Type: SHT_GNU_HASH 59# INVALID-NEXT: Content: '01000000000000000000000000000000' 60# INVALID-NEXT: - Name: .gnu.hash.hashvalues.ok 61# INVALID-NEXT: Type: SHT_GNU_HASH 62# INVALID-NEXT: Header: 63# INVALID-NEXT: SymNdx: 0x0 64# INVALID-NEXT: Shift2: 0x0 65# INVALID-NEXT: BloomFilter: [ ] 66# INVALID-NEXT: HashBuckets: [ ] 67# INVALID-NEXT: HashValues: [ 0x0 ] 68# INVALID-NEXT: - Name: .gnu.hash.hashvalues.fail 69# INVALID-NEXT: Type: SHT_GNU_HASH 70# INVALID-NEXT: Content: '000000000000000000000000000000000000000000' 71 72--- !ELF 73FileHeader: 74 Class: ELFCLASS32 75 Data: ELFDATA2LSB 76 Type: ET_DYN 77Sections: 78## Case 1: Content is less than 16 bytes. 79 - Name: .gnu.hash.tooshort 80 Type: SHT_GNU_HASH 81 Flags: [ SHF_ALLOC ] 82 Content: "112233445566778899AABBCCDDEEFF" 83## Case2: Check how we handle a fully empty hash section. 84## It is almost technically valid, but uncommon. Modern linkers 85## create at least one entry in Bloom filter if they want to disable it. 86## Also, the dynamic symbol table has a null entry and having SymNdx = 0 87## here is at least strange. 88 - Name: .gnu.hash.empty 89 Type: SHT_GNU_HASH 90 Flags: [ SHF_ALLOC ] 91 Header: 92 SymNdx: 0x0 93 Shift2: 0x0 94 MaskWords: 0x0 95 NBuckets: 0x0 96 BloomFilter: [] 97 HashBuckets: [] 98 HashValues: [] 99## Case 3: MaskWords field is broken: it says that the number of entries 100## in the Bloom filter is 1, but the Bloom filter is empty. 101 - Name: .gnu.hash.broken.maskwords 102 Type: SHT_GNU_HASH 103 Header: 104 SymNdx: 0x0 105 Shift2: 0x0 106 MaskWords: 0x1 107 NBuckets: 0x0 108 BloomFilter: [] 109 HashBuckets: [] 110 HashValues: [] 111## Case 4: NBuckets field is broken, it says that the number of entries 112## in the hash buckets is 1, but it is empty. 113 - Name: .gnu.hash.broken.nbuckets 114 Type: SHT_GNU_HASH 115 Header: 116 SymNdx: 0x0 117 Shift2: 0x0 118 MaskWords: 0x0 119 NBuckets: 0x1 120 BloomFilter: [] 121 HashBuckets: [] 122 HashValues: [] 123## Case 5: Check that we use the various properties to dump the data when it 124## has a size that is a multiple of 4, but fallback to dumping the whole section 125## using the "Content" property otherwise. 126 - Name: .gnu.hash.hashvalues.ok 127 Type: SHT_GNU_HASH 128 Content: "0000000000000000000000000000000000000000" 129 - Name: .gnu.hash.hashvalues.fail 130 Type: SHT_GNU_HASH 131 Content: "000000000000000000000000000000000000000000" 132