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: EntSize: 0x4 20# CASE1-NEXT: Entries: [ 0, 1, 2 ] 21# CASE1-NEXT: Symbols: 22# CASE1-NEXT: - Name: bar 23# CASE1-NEXT: Type: STT_SECTION 24# CASE1-NEXT: Index: SHN_XINDEX 25# CASE1-NEXT: - Name: .symtab_shndx 26# CASE1-NEXT: Type: STT_SECTION 27# CASE1-NEXT: Index: SHN_XINDEX 28# CASE1-NEXT: ... 29 30--- !ELF 31FileHeader: 32 Class: ELFCLASS64 33 Data: ELFDATA2LSB 34 Type: ET_REL 35Sections: 36 - Name: bar 37 Type: SHT_PROGBITS 38 - Name: .symtab_shndx 39 Type: SHT_SYMTAB_SHNDX 40 Entries: [ 0, 1, 2 ] 41 Link: .symtab 42Symbols: 43 - Type: STT_SECTION 44 Index: SHN_XINDEX 45 - Type: STT_SECTION 46 Index: SHN_XINDEX 47 48## Check that yaml2obj is unable to dump an object, which has 49## symbols with section index == SHN_XINDEX, but no SHT_SYMTAB_SHNDX section. 50 51# RUN: yaml2obj --docnum=2 %s -o %t2 52# RUN: not obj2yaml %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=CASE2 53 54# CASE2: Error reading file: [[FILE]]: extended symbol index (1) is past the end of the SHT_SYMTAB_SHNDX section of size 0 55 56--- !ELF 57FileHeader: 58 Class: ELFCLASS64 59 Data: ELFDATA2LSB 60 Type: ET_REL 61Symbols: 62 - Type: STT_SECTION 63 Index: SHN_XINDEX 64 65## Check that yaml2obj is unable to dump an object, which has symbols with 66## section index == SHN_XINDEX, but SHT_SYMTAB_SHNDX table contains invalid indices 67## that are larger than total number of the sections. 68 69# RUN: yaml2obj --docnum=3 %s -o %t3 70# RUN: not obj2yaml %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=CASE3 71 72# CASE3: Error reading file: [[FILE]]: invalid section index: 254 73 74--- !ELF 75FileHeader: 76 Class: ELFCLASS64 77 Data: ELFDATA2LSB 78 Type: ET_REL 79Sections: 80 - Name: bar 81 Type: SHT_PROGBITS 82 - Name: .symtab_shndx 83 Type: SHT_SYMTAB_SHNDX 84 Entries: [ 0, 254 ] 85 Link: .symtab 86Symbols: 87 - Type: STT_SECTION 88 Index: SHN_XINDEX 89 90## Check that yaml2obj is unable to dump an object, which has symbols with 91## section index == SHN_XINDEX, but SHT_SYMTAB_SHNDX table contains more 92## entries than the number of symbols in .symtab. 93 94# RUN: yaml2obj --docnum=4 %s -o %t4 95# RUN: not obj2yaml %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=CASE4 96 97## CASE4: Error reading file: [[FILE]]: unable to read extended section indexes: SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2 98 99--- !ELF 100FileHeader: 101 Class: ELFCLASS64 102 Data: ELFDATA2LSB 103 Type: ET_REL 104Sections: 105 - Name: bar 106 Type: SHT_PROGBITS 107 - Name: .symtab_shndx 108 Type: SHT_SYMTAB_SHNDX 109 Entries: [ 0, 1, 2 ] 110 Link: .symtab 111Symbols: 112 - Type: STT_SECTION 113 Index: SHN_XINDEX 114 115## ELF gABI allows having multiple SHT_SYMTAB_SHNDX sections. 116## Only one is allowed to be linked with a corresponding symbol table section though. 117## Check we report an error when multiple SHT_SYMTAB_SHNDX sections are linked 118## to the same symbol table. 119 120# RUN: yaml2obj --docnum=5 %s -o %t5 121# RUN: not obj2yaml %t5 2>&1 | FileCheck %s -DFILE=%t5 --check-prefix=CASE5 122 123# CASE5: Error reading file: [[FILE]]: multiple SHT_SYMTAB_SHNDX sections are linked to the same symbol table with index 5 124 125--- !ELF 126FileHeader: 127 Class: ELFCLASS64 128 Data: ELFDATA2LSB 129 Type: ET_REL 130Sections: 131 - Name: .symtab_shndx1 132 Type: SHT_SYMTAB_SHNDX 133 Entries: [ 0, 1 ] 134 EntSize: 4 135 Link: .symtab 136 - Name: .symtab_shndx2 137 Type: SHT_SYMTAB_SHNDX 138 Entries: [ 0, 2 ] 139 Link: [[LINK=.symtab]] 140Symbols: 141 - Type: STT_SECTION 142 Index: SHN_XINDEX 143DynamicSymbols: 144 - Type: STT_SECTION 145 Index: SHN_XINDEX 146 147## Check it is possible to dump an object that has multiple SHT_SYMTAB_SHNDX sections. 148## Check that yaml2obj can dump the object and dynamic symbols properly when 149## the SHT_SYMTAB_SHNDX section is associated with a SHT_DYNSYM section. 150 151# RUN: yaml2obj --docnum=5 -DLINK=.dynsym %s -o %t5.multiple 152# RUN: obj2yaml %t5.multiple | FileCheck %s --check-prefix=MULTIPLE-SYMTAB 153 154# MULTIPLE-SYMTAB: - Name: .symtab_shndx1 155# MULTIPLE-SYMTAB-NEXT: Type: SHT_SYMTAB_SHNDX 156# MULTIPLE-SYMTAB-NEXT: Link: .symtab 157# MULTIPLE-SYMTAB: - Name: .symtab_shndx2 158# MULTIPLE-SYMTAB-NEXT: Type: SHT_SYMTAB_SHNDX 159# MULTIPLE-SYMTAB-NEXT: Link: .dynsym 160# MULTIPLE-SYMTAB: Symbols: 161# MULTIPLE-SYMTAB-NEXT: - Name: .symtab_shndx1 162# MULTIPLE-SYMTAB-NEXT: Type: STT_SECTION 163# MULTIPLE-SYMTAB-NEXT: Index: SHN_XINDEX 164# MULTIPLE-SYMTAB-NEXT: DynamicSymbols: 165# MULTIPLE-SYMTAB-NEXT: - Name: .symtab_shndx2 166# MULTIPLE-SYMTAB-NEXT: Type: STT_SECTION 167# MULTIPLE-SYMTAB-NEXT: Index: SHN_XINDEX 168 169## Check that yaml2obj can't dump the object if SHT_SYMTAB_SHNDX is 170## not associated with a SHT_SYMTAB section (this case is illegal). 171 172# RUN: yaml2obj --docnum=6 %s -o %t6 173# RUN: not obj2yaml %t6 2>&1 | FileCheck %s -DFILE=%t6 --check-prefix=CASE6 174 175# 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) 176 177--- !ELF 178FileHeader: 179 Class: ELFCLASS64 180 Data: ELFDATA2LSB 181 Type: ET_REL 182Sections: 183 - Name: .symtab_shndx 184 Type: SHT_SYMTAB_SHNDX 185 Entries: [ 0 ] 186 Link: .foo 187 - Name: .foo 188 Type: SHT_PROGBITS 189