| 1 | ## Check that obj2yaml is able to dump a normal object which |
| 2 | ## contains the SHT_SYMTAB_SHNDX section and symbols with |
| 3 | ## section index == SHN_XINDEX. |
| 4 | |
| 5 | # RUN: yaml2obj --docnum=1 %s -o %t1 |
| 6 | # RUN: obj2yaml %t1 | FileCheck %s --check-prefix=CASE1 |
| 7 | |
| 8 | # CASE1: --- !ELF |
| 9 | # CASE1-NEXT: FileHeader: |
| 10 | # CASE1-NEXT: Class: ELFCLASS64 |
| 11 | # CASE1-NEXT: Data: ELFDATA2LSB |
| 12 | # CASE1-NEXT: Type: ET_REL |
| 13 | # CASE1-NEXT: Sections: |
| 14 | # CASE1-NEXT: - Name: bar |
| 15 | # CASE1-NEXT: Type: SHT_PROGBITS |
| 16 | # CASE1-NEXT: - Name: .symtab_shndx |
| 17 | # CASE1-NEXT: Type: SHT_SYMTAB_SHNDX |
| 18 | # CASE1-NEXT: Link: .symtab |
| 19 | # CASE1-NEXT: Entries: [ 0, 1, 2 ] |
| 20 | # CASE1-NEXT: Symbols: |
| 21 | # CASE1-NEXT: - Name: bar |
| 22 | # CASE1-NEXT: Type: STT_SECTION |
| 23 | # CASE1-NEXT: Index: SHN_XINDEX |
| 24 | # CASE1-NEXT: - Name: .symtab_shndx |
| 25 | # CASE1-NEXT: Type: STT_SECTION |
| 26 | # CASE1-NEXT: Index: SHN_XINDEX |
| 27 | # CASE1-NEXT: ... |
| 28 | |
| 29 | --- !ELF |
| 30 | FileHeader: |
| 31 | Class: ELFCLASS64 |
| 32 | Data: ELFDATA2LSB |
| 33 | Type: ET_REL |
| 34 | Sections: |
| 35 | - Name: bar |
| 36 | Type: SHT_PROGBITS |
| 37 | - Name: .symtab_shndx |
| 38 | Type: SHT_SYMTAB_SHNDX |
| 39 | Entries: [ 0, 1, 2 ] |
| 40 | Link: .symtab |
| 41 | Symbols: |
| 42 | - Type: STT_SECTION |
| 43 | Index: SHN_XINDEX |
| 44 | - Type: STT_SECTION |
| 45 | Index: SHN_XINDEX |
| 46 | |
| 47 | ## Check that yaml2obj is unable to dump an object, which has |
| 48 | ## symbols with section index == SHN_XINDEX, but no SHT_SYMTAB_SHNDX section. |
| 49 | |
| 50 | # RUN: yaml2obj --docnum=2 %s -o %t2 |
| 51 | # RUN: not obj2yaml %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=CASE2 |
| 52 | |
| 53 | # CASE2: Error reading file: [[FILE]]: found an extended symbol index (1), but unable to locate the extended symbol index table |
| 54 | |
| 55 | --- !ELF |
| 56 | FileHeader: |
| 57 | Class: ELFCLASS64 |
| 58 | Data: ELFDATA2LSB |
| 59 | Type: ET_REL |
| 60 | Symbols: |
| 61 | - Type: STT_SECTION |
| 62 | Index: SHN_XINDEX |
| 63 | |
| 64 | ## Check that yaml2obj is unable to dump an object, which has symbols with |
| 65 | ## section index == SHN_XINDEX, but SHT_SYMTAB_SHNDX table contains invalid indices |
| 66 | ## that are larger than total number of the sections. |
| 67 | |
| 68 | # RUN: yaml2obj --docnum=3 %s -o %t3 |
| 69 | # RUN: not obj2yaml %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=CASE3 |
| 70 | |
| 71 | # CASE3: Error reading file: [[FILE]]: invalid section index: 254 |
| 72 | |
| 73 | --- !ELF |
| 74 | FileHeader: |
| 75 | Class: ELFCLASS64 |
| 76 | Data: ELFDATA2LSB |
| 77 | Type: ET_REL |
| 78 | Sections: |
| 79 | - Name: bar |
| 80 | Type: SHT_PROGBITS |
| 81 | - Name: .symtab_shndx |
| 82 | Type: SHT_SYMTAB_SHNDX |
| 83 | Entries: [ 0, 254 ] |
| 84 | Link: .symtab |
| 85 | Symbols: |
| 86 | - Type: STT_SECTION |
| 87 | Index: SHN_XINDEX |
| 88 | |
| 89 | ## Check that yaml2obj is unable to dump an object, which has symbols with |
| 90 | ## section index == SHN_XINDEX, but SHT_SYMTAB_SHNDX table contains more |
| 91 | ## entries than the number of symbols in .symtab. |
| 92 | |
| 93 | # RUN: yaml2obj --docnum=4 %s -o %t4 |
| 94 | # RUN: not obj2yaml %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=CASE4 |
| 95 | |
| 96 | ## CASE4: Error reading file: [[FILE]]: unable to read extended section indexes: SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2 |
| 97 | |
| 98 | --- !ELF |
| 99 | FileHeader: |
| 100 | Class: ELFCLASS64 |
| 101 | Data: ELFDATA2LSB |
| 102 | Type: ET_REL |
| 103 | Sections: |
| 104 | - Name: bar |
| 105 | Type: SHT_PROGBITS |
| 106 | - Name: .symtab_shndx |
| 107 | Type: SHT_SYMTAB_SHNDX |
| 108 | Entries: [ 0, 1, 2 ] |
| 109 | Link: .symtab |
| 110 | Symbols: |
| 111 | - Type: STT_SECTION |
| 112 | Index: SHN_XINDEX |
| 113 | |
| 114 | ## ELF gABI allows having multiple SHT_SYMTAB_SHNDX sections. |
| 115 | ## Only one is allowed to be linked with a corresponding symbol table section though. |
| 116 | ## Check we report an error when multiple SHT_SYMTAB_SHNDX sections are linked |
| 117 | ## to the same symbol table. |
| 118 | |
| 119 | # RUN: yaml2obj --docnum=5 %s -o %t5 |
| 120 | # RUN: not obj2yaml %t5 2>&1 | FileCheck %s -DFILE=%t5 --check-prefix=CASE5 |
| 121 | |
| 122 | # CASE5: Error reading file: [[FILE]]: multiple SHT_SYMTAB_SHNDX sections are linked to the same symbol table with index 5 |
| 123 | |
| 124 | --- !ELF |
| 125 | FileHeader: |
| 126 | Class: ELFCLASS64 |
| 127 | Data: ELFDATA2LSB |
| 128 | Type: ET_REL |
| 129 | Sections: |
| 130 | - Name: .symtab_shndx1 |
| 131 | Type: SHT_SYMTAB_SHNDX |
| 132 | Entries: [ 0, 1 ] |
| 133 | EntSize: 4 |
| 134 | Link: .symtab |
| 135 | - Name: .symtab_shndx2 |
| 136 | Type: SHT_SYMTAB_SHNDX |
| 137 | Entries: [ 0, 2 ] |
| 138 | Link: [[LINK=.symtab]] |
| 139 | Symbols: |
| 140 | - Type: STT_SECTION |
| 141 | Index: SHN_XINDEX |
| 142 | DynamicSymbols: |
| 143 | - Type: STT_SECTION |
| 144 | Index: SHN_XINDEX |
| 145 | |
| 146 | ## Check it is possible to dump an object that has multiple SHT_SYMTAB_SHNDX sections. |
| 147 | ## Check that yaml2obj can dump the object and dynamic symbols properly when |
| 148 | ## the SHT_SYMTAB_SHNDX section is associated with a SHT_DYNSYM section. |
| 149 | |
| 150 | # RUN: yaml2obj --docnum=5 -DLINK=.dynsym %s -o %t5.multiple |
| 151 | # RUN: obj2yaml %t5.multiple | FileCheck %s --check-prefix=MULTIPLE-SYMTAB |
| 152 | |
| 153 | # MULTIPLE-SYMTAB: - Name: .symtab_shndx1 |
| 154 | # MULTIPLE-SYMTAB-NEXT: Type: SHT_SYMTAB_SHNDX |
| 155 | # MULTIPLE-SYMTAB-NEXT: Link: .symtab |
| 156 | # MULTIPLE-SYMTAB: - Name: .symtab_shndx2 |
| 157 | # MULTIPLE-SYMTAB-NEXT: Type: SHT_SYMTAB_SHNDX |
| 158 | # MULTIPLE-SYMTAB-NEXT: Link: .dynsym |
| 159 | # MULTIPLE-SYMTAB: Symbols: |
| 160 | # MULTIPLE-SYMTAB-NEXT: - Name: .symtab_shndx1 |
| 161 | # MULTIPLE-SYMTAB-NEXT: Type: STT_SECTION |
| 162 | # MULTIPLE-SYMTAB-NEXT: Index: SHN_XINDEX |
| 163 | # MULTIPLE-SYMTAB-NEXT: DynamicSymbols: |
| 164 | # MULTIPLE-SYMTAB-NEXT: - Name: .symtab_shndx2 |
| 165 | # MULTIPLE-SYMTAB-NEXT: Type: STT_SECTION |
| 166 | # MULTIPLE-SYMTAB-NEXT: Index: SHN_XINDEX |
| 167 | |
| 168 | ## Check that yaml2obj can't dump the object if SHT_SYMTAB_SHNDX is |
| 169 | ## not associated with a SHT_SYMTAB section (this case is illegal). |
| 170 | |
| 171 | # RUN: yaml2obj --docnum=6 %s -o %t6 |
| 172 | # RUN: not obj2yaml %t6 2>&1 | FileCheck %s -DFILE=%t6 --check-prefix=CASE6 |
| 173 | |
| 174 | # CASE6: Error reading file: [[FILE]]: unable to read extended section indexes: SHT_SYMTAB_SHNDX section is linked with SHT_PROGBITS section (expected SHT_SYMTAB/SHT_DYNSYM) |
| 175 | |
| 176 | --- !ELF |
| 177 | FileHeader: |
| 178 | Class: ELFCLASS64 |
| 179 | Data: ELFDATA2LSB |
| 180 | Type: ET_REL |
| 181 | Sections: |
| 182 | - Name: .symtab_shndx |
| 183 | Type: SHT_SYMTAB_SHNDX |
| 184 | Entries: [ 0 ] |
| 185 | Link: .foo |
| 186 | - Name: .foo |
| 187 | Type: SHT_PROGBITS |
| 188 | |
| 189 | ## Check that we are unable to dump the SHT_SYMTAB_SHNDX section when its |
| 190 | ## sh_entsize has an unexpected value (not equal to 4). |
| 191 | |
| 192 | # RUN: yaml2obj -DENTSIZE=0xff --docnum=7 %s -o %t7.entsize.bad |
| 193 | # RUN: not obj2yaml %t7.entsize.bad 2>&1 | \ |
| 194 | # RUN: FileCheck %s -DFILE=%t7.entsize.bad --check-prefix=CASE7-BAD |
| 195 | |
| 196 | # CASE7-BAD: Error reading file: [[FILE]]: unable to read extended section indexes: section [index 1] has invalid sh_entsize: expected 4, but got 255 |
| 197 | |
| 198 | ## Check we don't print the "EntSize" field when the "sh_entsize" field has the default value. |
| 199 | |
| 200 | # RUN: yaml2obj -DENTSIZE=4 --docnum=7 %s -o %t7.entsize.ok |
| 201 | # RUN: obj2yaml %t7.entsize.ok | FileCheck %s -DFILE=%t7.entsize.ok --check-prefix=CASE7 |
| 202 | |
| 203 | # CASE7: - Name: .symtab_shndx |
| 204 | # CASE7-NEXT: Type: SHT_SYMTAB_SHNDX |
| 205 | # CASE7-NEXT: Link: .symtab |
| 206 | # CASE7-NEXT: Entries: [ 0 ] |
| 207 | # CASE7-NEXT: Symbols: |
| 208 | |
| 209 | --- !ELF |
| 210 | FileHeader: |
| 211 | Class: ELFCLASS64 |
| 212 | Data: ELFDATA2LSB |
| 213 | Type: ET_REL |
| 214 | Sections: |
| 215 | - Name: .symtab_shndx |
| 216 | Type: SHT_SYMTAB_SHNDX |
| 217 | EntSize: [[ENTSIZE]] |
| 218 | Entries: [ 0 ] |
| 219 | Link: .symtab |
| 220 | Symbols: [] |