1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
## In this file we have tests for the SHT_SYMTAB_SHNDX section
## and the DT_SYMTAB_SHNDX dynamic tag.
## Check that different SHT_SYMTAB_SHNDX sections can be used with different symbol tables.
## In this test we check that we print different section indexes for regular and dynamic
## symbol tables that are linked to different SHT_SYMTAB_SHNDX sections.
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readelf --symbols --dyn-syms %t1 2>&1 | FileCheck %s --check-prefix=GNU
# RUN: llvm-readobj --symbols --dyn-syms %t1 2>&1 | FileCheck %s --check-prefix=LLVM
# GNU: Symbol table '.dynsym' contains 3 entries:
# GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
# GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 3 dynsym1
# GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 dynsym2
# GNU: Symbol table '.symtab' contains 3 entries:
# GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
# GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 2 sym1
# GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 1 sym2
# LLVM: Symbols [
# LLVM-NEXT: Symbol {
# LLVM-NEXT: Name: (0)
# LLVM: Section: Undefined (0x0)
# LLVM-NEXT: }
# LLVM-NEXT: Symbol {
# LLVM-NEXT: Name: sym1 (6)
# LLVM: Section: .section2 (0x2)
# LLVM-NEXT: }
# LLVM-NEXT: Symbol {
# LLVM-NEXT: Name: sym2 (1)
# LLVM: Section: .section1 (0x1)
# LLVM-NEXT: }
# LLVM-NEXT: ]
# LLVM: DynamicSymbols [
# LLVM-NEXT: Symbol {
# LLVM-NEXT: Name: (0)
# LLVM: Section: Undefined (0x0)
# LLVM-NEXT: }
# LLVM-NEXT: Symbol {
# LLVM-NEXT: Name: dynsym1 (9)
# LLVM: Section: .section3 (0x3)
# LLVM-NEXT: }
# LLVM-NEXT: Symbol {
# LLVM-NEXT: Name: dynsym2 (1)
# LLVM: Section: .section2 (0x2)
# LLVM-NEXT: }
# LLVM-NEXT: ]
--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .section1
Type: SHT_PROGBITS
- Name: .section2
Type: SHT_PROGBITS
- Name: .section3
Type: SHT_PROGBITS
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Address: 0x1000
Offset: 0x1000
Entries:
- Tag: [[TAGNAME=DT_SYMTAB_SHNDX]]
Value: [[SYMTABSHNDX=0x2100]] ## Address of .bar section.
- Tag: DT_NULL
Value: 0
## By naming the SHT_SYMTAB_SHNDX sections to .foo and .bar we verify that we
## don't use their names to locate them.
- Name: .foo
Type: SHT_SYMTAB_SHNDX
Flags: [ SHF_ALLOC ]
Link: [[SHNDXLINK=.symtab]]
Entries: [ 0, 2, 1 ]
Offset: 0x2000
Address: 0x2000
- Name: .bar
Type: SHT_SYMTAB_SHNDX
Flags: [ SHF_ALLOC ]
Link: .dynsym
Entries: [ 0, 3, 2 ]
Offset: 0x2100
Address: 0x2100
Symbols:
- Name: sym1
Index: SHN_XINDEX
- Name: sym2
Index: SHN_XINDEX
DynamicSymbols:
- Name: dynsym1
Index: SHN_XINDEX
- Name: dynsym2
Index: SHN_XINDEX
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
FirstSec: .dynamic
LastSec: .bar
- Type: PT_DYNAMIC
VAddr: 0x1000
FirstSec: .dynamic
LastSec: .dynamic
## Check that we locate the SHT_SYMTAB_SHNDX section using the DT_SYMTAB_SHNDX
## dynamic tag when dumping dynamic symbols. In this case we make the value of
## DT_SYMTAB_SHNDX point to the SHT_SYMTAB_SHNDX section that is
## linked with the static symbol table and check that we use it.
# RUN: yaml2obj --docnum=1 -DSYMTABSHNDX=0x2000 %s -o %t2
# RUN: llvm-readelf --dyn-syms %t2 2>&1 | FileCheck %s --check-prefix=DYNTAG-GNU
# RUN: llvm-readobj --dyn-syms %t2 2>&1 | FileCheck %s --check-prefix=DYNTAG-LLVM
# DYNTAG-GNU: Symbol table '.dynsym' contains 3 entries:
# DYNTAG-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
# DYNTAG-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# DYNTAG-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 2 dynsym1
# DYNTAG-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 1 dynsym2
# DYNTAG-LLVM: Name: dynsym1 (9)
# DYNTAG-LLVM: Section: .section2 (0x2)
# DYNTAG-LLVM-NEXT: }
# DYNTAG-LLVM-NEXT: Symbol {
# DYNTAG-LLVM-NEXT: Name: dynsym2 (1)
# DYNTAG-LLVM: Section: .section1 (0x1)
# DYNTAG-LLVM-NEXT: }
# DYNTAG-LLVM-NEXT: ]
## Check that we report a warning when we dump a dynamic symbol table that
## contains symbols with extended indices, but we don't have a DT_SYMTAB_SHNDX tag to locate
## the corresponding extended indexes table.
# RUN: yaml2obj --docnum=1 -DTAGNAME=0x0 -DSYMTABSHNDX=0x0 %s -o %t3
# RUN: llvm-readelf --symbols --dyn-syms %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=NOTAG-GNU
# RUN: llvm-readobj --symbols --dyn-syms %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=NOTAG-LLVM
# NOTAG-GNU: Symbol table '.dynsym' contains 3 entries:
# NOTAG-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
# NOTAG-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# NOTAG-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
# NOTAG-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] dynsym1
# NOTAG-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table
# NOTAG-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] dynsym2
# NOTAG-LLVM: Symbol {
# NOTAG-LLVM: Name: dynsym1 (9)
# NOTAG-LLVM-NEXT: Value: 0x0
# NOTAG-LLVM-NEXT: Size: 0
# NOTAG-LLVM-NEXT: Binding: Local (0x0)
# NOTAG-LLVM-NEXT: Type: None (0x0)
# NOTAG-LLVM-NEXT: Other: 0
# NOTAG-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
# NOTAG-LLVM-NEXT: Section: Reserved (0xFFFF)
# NOTAG-LLVM-NEXT: }
# NOTAG-LLVM-NEXT: Symbol {
# NOTAG-LLVM-NEXT: Name: dynsym2 (1)
# NOTAG-LLVM-NEXT: Value: 0x0
# NOTAG-LLVM-NEXT: Size: 0
# NOTAG-LLVM-NEXT: Binding: Local (0x0)
# NOTAG-LLVM-NEXT: Type: None (0x0)
# NOTAG-LLVM-NEXT: Other: 0
# NOTAG-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table
# NOTAG-LLVM-NEXT: Section: Reserved (0xFFFF)
# NOTAG-LLVM-NEXT: }
## In this case we have a SHT_SYMTAB_SHNDX section with a sh_link field that has a
## value that is larger than the number of sections. Check we report a warning.
# RUN: yaml2obj --docnum=1 -DSHNDXLINK=0xFF %s -o %t4
# RUN: llvm-readelf --symbols --dyn-syms %t4 2>&1 | \
# RUN: FileCheck %s -DFILE=%t4 --check-prefixes=BROKENLINK,BROKENLINK-GNU --implicit-check-not=warning:
# RUN: llvm-readobj --symbols --dyn-syms %t4 2>&1 | \
# RUN: FileCheck %s -DFILE=%t4 --check-prefixes=BROKENLINK,BROKENLINK-LLVM --implicit-check-not=warning:
# BROKENLINK: warning: '[[FILE]]': unable to get the associated symbol table for SHT_SYMTAB_SHNDX section with index 5: sh_link (255) is greater than or equal to the total number of sections (12)
# BROKENLINK-GNU: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
# BROKENLINK-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] sym1
# BROKENLINK-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table
# BROKENLINK-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] sym2
# BROKENLINK-LLVM: Symbol {
# BROKENLINK-LLVM: Name: sym1 (6)
# BROKENLINK-LLVM: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
# BROKENLINK-LLVM-NEXT: Section: Reserved (0xFFFF)
# BROKENLINK-LLVM-NEXT: }
# BROKENLINK-LLVM-NEXT: Symbol {
# BROKENLINK-LLVM-NEXT: Name: sym2 (1)
# BROKENLINK-LLVM: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table
# BROKENLINK-LLVM-NEXT: Section: Reserved (0xFFFF)
# BROKENLINK-LLVM-NEXT: }
## Check we report a warning when multiple SHT_SYMTAB_SHNDX sections are linked to a symbol table.
## In this case, 2 sections are linked to the dynamic symbol table. Check it doesn't affect
## anything, because the SHT_SYMTAB_SHNDX section specified by the DT_SYMTAB_SHNDX tag is still used.
# RUN: yaml2obj --docnum=1 -DSHNDXLINK=.dynsym %s -o %t.multiple
# RUN: llvm-readelf --symbols --dyn-syms %t.multiple 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.multiple --check-prefix=MULTIPLE-GNU
# RUN: llvm-readobj --symbols --dyn-syms %t.multiple 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.multiple --check-prefix=MULTIPLE-LLVM
# MULTIPLE-GNU: warning: '[[FILE]]': multiple SHT_SYMTAB_SHNDX sections are linked to SHT_SYMTAB_SHNDX section with index 6
# MULTIPLE-GNU: Symbol table '.dynsym' contains 3 entries:
# MULTIPLE-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
# MULTIPLE-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# MULTIPLE-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 3 dynsym1
# MULTIPLE-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 dynsym2
# MULTIPLE-LLVM: Symbol {
# MULTIPLE-LLVM: Name: dynsym1 (9)
# MULTIPLE-LLVM-NEXT: Value: 0x0
# MULTIPLE-LLVM-NEXT: Size: 0
# MULTIPLE-LLVM-NEXT: Binding: Local (0x0)
# MULTIPLE-LLVM-NEXT: Type: None (0x0)
# MULTIPLE-LLVM-NEXT: Other: 0
# MULTIPLE-LLVM-NEXT: Section: .section3 (0x3)
# MULTIPLE-LLVM-NEXT: }
# MULTIPLE-LLVM-NEXT: Symbol {
# MULTIPLE-LLVM-NEXT: Name: dynsym2 (1)
# MULTIPLE-LLVM-NEXT: Value: 0x0
# MULTIPLE-LLVM-NEXT: Size: 0
# MULTIPLE-LLVM-NEXT: Binding: Local (0x0)
# MULTIPLE-LLVM-NEXT: Type: None (0x0)
# MULTIPLE-LLVM-NEXT: Other: 0
# MULTIPLE-LLVM-NEXT: Section: .section2 (0x2)
# MULTIPLE-LLVM-NEXT: }
## In this case we have a SHT_SYMTAB_SHNDX section placed right before
## the end of the file. This table is broken: it contains fewer entries than
## the number of dynamic symbols.
## Check we report a warning when trying to read an extended symbol index past
## the end of the file.
# RUN: yaml2obj --docnum=2 %s -o %t.pastend
# RUN: llvm-readelf --dyn-syms %t.pastend 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.pastend --check-prefix=PASTEND-GNU --implicit-check-not=warning:
# RUN: llvm-readobj --dyn-syms %t.pastend 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.pastend --check-prefix=PASTEND-LLVM --implicit-check-not=warning:
# PASTEND-GNU: 1: 00000000 0 NOTYPE LOCAL DEFAULT 1 dynsym1
# PASTEND-GNU-NEXT: warning: '[[FILE]]': unable to read an extended symbol table at index 2: can't read past the end of the file
# PASTEND-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] dynsym2
# PASTEND-LLVM: Symbol {
# PASTEND-LLVM: Name: dynsym2 (1)
# PASTEND-LLVM-NEXT: Value: 0x0
# PASTEND-LLVM-NEXT: Size: 0
# PASTEND-LLVM-NEXT: Binding: Local (0x0)
# PASTEND-LLVM-NEXT: Type: None (0x0)
# PASTEND-LLVM-NEXT: Other: 0
# PASTEND-LLVM-NEXT: warning: '[[FILE]]': unable to read an extended symbol table at index 2: can't read past the end of the file
# PASTEND-LLVM-NEXT: Section: Reserved (0xFFFF)
# PASTEND-LLVM-NEXT: }
--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .section1
Type: SHT_PROGBITS
- Name: .section2
Type: SHT_PROGBITS
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Address: 0x1000
Offset: 0x1000
Entries:
- Tag: DT_SYMTAB
Value: 0x1500
- Tag: DT_HASH
Value: 0x1600
- Tag: DT_STRTAB
Value: 0x1700
- Tag: DT_STRSZ
Value: 17 ## ".dynsym1.dynsym2."
- Tag: DT_SYMTAB_SHNDX
Value: 0x2000
- Tag: DT_NULL
Value: 0
- Name: .dynsym
Type: SHT_DYNSYM
Flags: [ SHF_ALLOC ]
Offset: 0x1500
Address: 0x1500
## We need the .hash table to infer the number
## of dynamic symbols.
- Name: .hash
Type: SHT_HASH
Flags: [ SHF_ALLOC ]
Offset: 0x1600
Address: 0x1600
Bucket: [ 1 ]
Chain: [ 1, 2, 3 ]
- Name: .dynstr
Type: SHT_STRTAB
Flags: [ SHF_ALLOC ]
Offset: 0x1700
Address: 0x1700
- Name: .strtab
Type: SHT_STRTAB
- Name: .symtab_shndx
Type: SHT_SYMTAB_SHNDX
Flags: [ SHF_ALLOC ]
Entries: [ 0, 1 ]
Offset: 0x2000
Address: 0x2000
- Type: SectionHeaderTable
NoHeaders: true
DynamicSymbols:
- Name: dynsym1
Index: SHN_XINDEX
- Name: dynsym2
Index: SHN_XINDEX
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
FirstSec: .dynamic
LastSec: .symtab_shndx
- Type: PT_DYNAMIC
VAddr: 0x1000
FirstSec: .dynamic
LastSec: .dynamic
|