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