verneed-invalid.test 20.2 KB
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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_verneed sections.

## In the first case we have a SHT_GNU_versym section that refers to
## a version listed in a SHT_GNU_verneed section. That version has an
## empty name, making it invalid.

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readelf -V %t1 | FileCheck %s --check-prefix=GNU-VERNEED-NAME
# RUN: llvm-readobj -V %t1 | FileCheck %s --check-prefix=LLVM-VERNEED-NAME

# GNU-VERNEED-NAME:      Version symbols section '.gnu.version' contains 2 entries:
# GNU-VERNEED-NAME-NEXT:  Addr: 0000000000200210  Offset: 0x000040  Link: 3 (.dynsym)
# GNU-VERNEED-NAME-NEXT:   000:   0 (*local*)       2 ()

# GNU-VERNEED-NAME:      Version needs section '.gnu.version_r' contains 1 entries:
# GNU-VERNEED-NAME-NEXT:  Addr: 0000000000200214  Offset: 0x000044  Link: 4 (.dynstr)
# GNU-VERNEED-NAME-NEXT:   0x0000: Version: 1  File: somefile  Cnt: 1
# GNU-VERNEED-NAME-NEXT:   0x0010:   Name:   Flags: none  Version: 2

# LLVM-VERNEED-NAME:      VersionSymbols [
# LLVM-VERNEED-NAME:        Symbol {
# LLVM-VERNEED-NAME-NEXT:     Version: 0
# LLVM-VERNEED-NAME-NEXT:     Name:
# LLVM-VERNEED-NAME-NEXT:   }
# LLVM-VERNEED-NAME-NEXT:   Symbol {
# LLVM-VERNEED-NAME-NEXT:     Version: 2
# LLVM-VERNEED-NAME-NEXT:     Name: foo
# LLVM-VERNEED-NAME-NEXT:   }
# LLVM-VERNEED-NAME-NEXT: ]

# LLVM-VERNEED-NAME:      VersionRequirements [
# LLVM-VERNEED-NAME-NEXT:   Dependency {
# LLVM-VERNEED-NAME-NEXT:     Version: 1
# LLVM-VERNEED-NAME-NEXT:     Count: 1
# LLVM-VERNEED-NAME-NEXT:     FileName: somefile
# LLVM-VERNEED-NAME-NEXT:     Entries [
# LLVM-VERNEED-NAME-NEXT:       Entry {
# LLVM-VERNEED-NAME-NEXT:         Hash:  0
# LLVM-VERNEED-NAME-NEXT:         Flags [ (0x0)
# LLVM-VERNEED-NAME-NEXT:         ]
# LLVM-VERNEED-NAME-NEXT:         Index: 2
# LLVM-VERNEED-NAME-NEXT:         Name: {{$}}
# LLVM-VERNEED-NAME-NEXT:       }
# LLVM-VERNEED-NAME-NEXT:     ]
# LLVM-VERNEED-NAME-NEXT:   }
# LLVM-VERNEED-NAME-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Flags:   [ SHF_ALLOC ]
    Address: 0x200210
    Link:    .dynsym
    Entries: [ 0, 2 ]
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Link:  .dynstr
    Info:  1
    AddressAlign: 4
    Dependencies:
      - Version:   1
        File:      somefile
        Entries:
          - Name:  '' ## invalid name
            Hash:  0
            Flags: 0
            Other: 2
DynamicSymbols:
  - Name:    foo
    Binding: STB_GLOBAL
...

## In this case SHT_GNU_verneed is not linked to a dynamic string table. We check we handle
## this situation properly.

# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readelf -V %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=GNU-NOLINK
# RUN: llvm-readobj -V %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=LLVM-NOLINK

# GNU-NOLINK:      Version symbols section '.gnu.version' contains 2 entries:
# GNU-NOLINK-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 3 (.dynsym)
# GNU-NOLINK-NEXT: warning: '[[FILE]]': invalid string table linked to SHT_GNU_verneed section with index 2: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
# GNU-NOLINK-NEXT:   000:   0 (*local*) 2 (<corrupt>)
# GNU-NOLINK:      Version needs section '.gnu.version_r' contains 1 entries:
# GNU-NOLINK-NEXT:  Addr: 0000000000000004  Offset: 0x000044  Link: 0 ()
# GNU-NOLINK-NEXT:   0x0000: Version: 1  File: <corrupt vn_file: 9>  Cnt: 1
# GNU-NOLINK-NEXT:   0x0010:   Name: <corrupt>  Flags: none Version: 2

# LLVM-NOLINK:      VersionSymbols [
# LLVM-NOLINK:        Symbol {
# LLVM-NOLINK-NEXT:     Version: 0
# LLVM-NOLINK-NEXT:     Name:
# LLVM-NOLINK-NEXT:   }
# LLVM-NOLINK-NEXT:   Symbol {
# LLVM-NOLINK-NEXT:     Version: 2
# LLVM-NOLINK-NEXT:  warning: '[[FILE]]': invalid string table linked to SHT_GNU_verneed section with index 2: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
# LLVM-NOLINK-NEXT:     Name: foo@<corrupt>
# LLVM-NOLINK-NEXT:   }
# LLVM-NOLINK-NEXT: ]

# LLVM-NOLINK:      VersionRequirements [
# LLVM-NOLINK-NEXT:   Dependency {
# LLVM-NOLINK-NEXT:     Version: 1
# LLVM-NOLINK-NEXT:     Count: 1
# LLVM-NOLINK-NEXT:     FileName: <corrupt vn_file: 9>
# LLVM-NOLINK-NEXT:     Entries [
# LLVM-NOLINK-NEXT:       Entry {
# LLVM-NOLINK-NEXT:         Hash: 0
# LLVM-NOLINK-NEXT:         Flags [ (0x0)
# LLVM-NOLINK-NEXT:         ]
# LLVM-NOLINK-NEXT:         Index: 2
# LLVM-NOLINK-NEXT:         Name: <corrupt>
# LLVM-NOLINK-NEXT:       }
# LLVM-NOLINK-NEXT:     ]
# LLVM-NOLINK-NEXT:   }
# LLVM-NOLINK-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Flags:   [ SHF_ALLOC ]
    Link:    .dynsym
    Entries: [ 0, 2 ]
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Link:  0
    Info:  1
    AddressAlign: 4
    Dependencies:
      - Version: 1
        File:    somefile
        Entries:
          - Name:  'bar'
            Hash:  0
            Flags: 0
            Other: 2
DynamicSymbols:
  - Name:    foo
    Binding: STB_GLOBAL

## We can't parse misaligned auxiliary version records.

# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-readelf -V %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=BROKEN-AUX-GNU
# RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=BROKEN-AUX-LLVM

# BROKEN-AUX-GNU:      Version symbols section '.gnu.version' contains 1 entries:
# BROKEN-AUX-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 3 (.dynsym)
# BROKEN-AUX-GNU-NEXT: warning: '[[FILE]]': unable to get a version for entry 0 of SHT_GNU_versym section with index 1: invalid SHT_GNU_verneed section with index 2: found a misaligned auxiliary entry at offset 0x11
# BROKEN-AUX-GNU-NEXT:  000:   2 (<corrupt>)

# BROKEN-AUX-LLVM:      VersionSymbols [
# BROKEN-AUX-LLVM-NEXT:   Symbol {
# BROKEN-AUX-LLVM-NEXT:     Version: 2
# BROKEN-AUX-LLVM-NEXT: warning: '[[FILE]]': invalid SHT_GNU_verneed section with index 2: found a misaligned auxiliary entry at offset 0x11
# BROKEN-AUX-LLVM-NEXT:     Name: @<corrupt>
# BROKEN-AUX-LLVM-NEXT:   }
# BROKEN-AUX-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Flags:   [ SHF_ALLOC ]
    Link:    .dynsym
    Entries: [ 2 ]
  - Name:         .gnu.version_r
    Type:         SHT_GNU_verneed
    Flags:        [ SHF_ALLOC ]
    Info:         1
    Link:         .dynstr
    AddressAlign: 4
## The byte offset to the auxiliary entry is 0x11, i.e. it is not correctly aligned in memory.
    Content: "0100010001000000110000000000000000000000"
DynamicSymbols: []

## Here we check that we can properly dump the case when a dependency file name
## and/or a dependency name string offset is equal to the string table size.
##
## We set the version dependency vn_file field to the offset of string 'foo' in
## the .dynstr, which is 1. We create a custom string table .mystrtab of size 1
## and link it with the .gnu.version_r section. For the vna_name we use the same trick.

# RUN: yaml2obj --docnum=4 %s -o %t4
# RUN: llvm-readobj --sections --section-data -V %t4 | FileCheck %s --check-prefix=LLVM-OFFSET-EQ
# RUN: llvm-readelf --sections -V %t4 | FileCheck %s --check-prefix=GNU-OFFSET-EQ

# LLVM-OFFSET-EQ: Name: .mystrtab
# LLVM-OFFSET-EQ: Size:
# LLVM-OFFSET-EQ-SAME:  1

# LLVM-OFFSET-EQ:      Name: .dynstr
# LLVM-OFFSET-EQ:      SectionData (
# LLVM-OFFSET-EQ-NEXT:   0000: 00666F6F 00 |.foo.|
# LLVM-OFFSET-EQ-NEXT: )

# LLVM-OFFSET-EQ:      VersionRequirements [
# LLVM-OFFSET-EQ-NEXT:   Dependency {
# LLVM-OFFSET-EQ-NEXT:     Version: 1
# LLVM-OFFSET-EQ-NEXT:     Count: 1
# LLVM-OFFSET-EQ-NEXT:     FileName: <corrupt vn_file: 1>
# LLVM-OFFSET-EQ-NEXT:     Entries [
# LLVM-OFFSET-EQ-NEXT:       Entry {
# LLVM-OFFSET-EQ-NEXT:         Hash: 0
# LLVM-OFFSET-EQ-NEXT:         Flags [ (0x0)
# LLVM-OFFSET-EQ-NEXT:         ]
# LLVM-OFFSET-EQ-NEXT:         Index: 0
# LLVM-OFFSET-EQ-NEXT:         Name: <corrupt>
# LLVM-OFFSET-EQ-NEXT:       }
# LLVM-OFFSET-EQ-NEXT:     ]
# LLVM-OFFSET-EQ-NEXT:   }
# LLVM-OFFSET-EQ-NEXT: ]

# GNU-OFFSET-EQ:      Version needs section '.gnu.version_r' contains 1 entries:
# GNU-OFFSET-EQ-NEXT:  Addr: 0000000000000004  Offset: 0x000044  Link: 1 (.mystrtab)
# GNU-OFFSET-EQ-NEXT:   0x0000: Version: 1  File: <corrupt vn_file: 1>  Cnt: 1
# GNU-OFFSET-EQ-NEXT:   0x0010:   Name: <corrupt>  Flags: none  Version: 0

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name: .mystrtab
    Type: SHT_STRTAB
    Content: "00"
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .mystrtab
    AddressAlign: 4
    Dependencies:
      - Version: 1
        File:    foo
        Entries:
          - Name:  'foo'
            Hash:  0
            Flags: 0
            Other: 0
DynamicSymbols:
  - Name: foo

## Here we check that we can properly dump the case when a dependency file name
## and/or a dependency name string offset is greater than the string table size.
##
# RUN: yaml2obj --docnum=5 %s -o %t5
# RUN: llvm-readobj --sections -V %t5 | FileCheck %s --check-prefix=LLVM-OFFSET-GR
# RUN: llvm-readelf --sections -V %t5 | FileCheck %s --check-prefix=GNU-OFFSET-GR

# LLVM-OFFSET-GR:      VersionRequirements [
# LLVM-OFFSET-GR-NEXT:   Dependency {
# LLVM-OFFSET-GR-NEXT:     Version: 1
# LLVM-OFFSET-GR-NEXT:     Count: 1
# LLVM-OFFSET-GR-NEXT:     FileName: <corrupt vn_file: 1>
# LLVM-OFFSET-GR-NEXT:     Entries [
# LLVM-OFFSET-GR-NEXT:       Entry {
# LLVM-OFFSET-GR-NEXT:         Hash: 0
# LLVM-OFFSET-GR-NEXT:         Flags [ (0x0)
# LLVM-OFFSET-GR-NEXT:         ]
# LLVM-OFFSET-GR-NEXT:         Index: 0
# LLVM-OFFSET-GR-NEXT:         Name: <corrupt>
# LLVM-OFFSET-GR-NEXT:       }
# LLVM-OFFSET-GR-NEXT:     ]
# LLVM-OFFSET-GR-NEXT:   }
# LLVM-OFFSET-GR-NEXT: ]

# GNU-OFFSET-GR:      Version needs section '.gnu.version_r' contains 1 entries:
# GNU-OFFSET-GR-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 1 (.mystrtab)
# GNU-OFFSET-GR-NEXT:   0x0000: Version: 1  File: <corrupt vn_file: 1>  Cnt: 1
# GNU-OFFSET-GR-NEXT:   0x0010:   Name: <corrupt>  Flags: none  Version: 0

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name: .mystrtab
    Type: SHT_STRTAB
    Content: ""
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .mystrtab
    AddressAlign: 4
    Dependencies:
      - Version: 1
        File:    foo
        Entries:
          - Name:  'foo'
            Hash:  0
            Flags: 0
            Other: 0
DynamicSymbols:
  - Name: foo

## Check that we report a warning when sh_link references a non-existent section.

# RUN: yaml2obj --docnum=6 %s -o %t6
# RUN: llvm-readobj --sections -V %t6 2>&1 | FileCheck %s -DFILE=%t6 --implicit-check-not="warning:" --check-prefix=INVALID-LINK-LLVM
# RUN: llvm-readelf --sections -V %t6 2>&1 | FileCheck %s -DFILE=%t6 --implicit-check-not="warning:" --check-prefix=INVALID-LINK-GNU

# INVALID-LINK-LLVM:      VersionRequirements [
# INVALID-LINK-LLVM-NEXT:  warning: '[[FILE]]': invalid section linked to SHT_GNU_verneed section with index 1: invalid section index: 255
# INVALID-LINK-LLVM-NEXT:   Dependency {
# INVALID-LINK-LLVM-NEXT:     Version: 1
# INVALID-LINK-LLVM-NEXT:     Count: 1
# INVALID-LINK-LLVM-NEXT:     FileName: <corrupt vn_file: 1>
# INVALID-LINK-LLVM-NEXT:     Entries [
# INVALID-LINK-LLVM-NEXT:       Entry {
# INVALID-LINK-LLVM-NEXT:         Hash: 0
# INVALID-LINK-LLVM-NEXT:         Flags [ (0x0)
# INVALID-LINK-LLVM-NEXT:         ]
# INVALID-LINK-LLVM-NEXT:         Index: 0
# INVALID-LINK-LLVM-NEXT:         Name: <corrupt>
# INVALID-LINK-LLVM-NEXT:       }
# INVALID-LINK-LLVM-NEXT:     ]
# INVALID-LINK-LLVM-NEXT:   }
# INVALID-LINK-LLVM-NEXT: ]

# INVALID-LINK-GNU:      Version needs section '.gnu.version_r' contains 1 entries:
# INVALID-LINK-GNU-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_verneed section with index 1: invalid section index: 255
# INVALID-LINK-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 255 (<corrupt>)
# INVALID-LINK-GNU-NEXT:  0x0000: Version: 1 File: <corrupt vn_file: 1> Cnt: 1
# INVALID-LINK-GNU-NEXT:  0x0010: Name: <corrupt> Flags: none Version: 0

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  0xFF
    Dependencies:
      - Version: 1
        File:    foo
        Entries:
          - Name:  'foo'
            Hash:  0
            Flags: 0
            Other: 0
DynamicSymbols:
  - Name: foo

## Check that we report a warning when we can't read the content of the SHT_GNU_verneed section.

# RUN: yaml2obj --docnum=7 %s -o %t7
# RUN: llvm-readobj --sections -V %t7 2>&1 | FileCheck %s -DFILE=%t7 --check-prefix=INVALID-DATA
# RUN: llvm-readelf --sections -V %t7 2>&1 | FileCheck %s -DFILE=%t7 --check-prefix=INVALID-DATA

# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verneed section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x228)

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .dynstr
    ShOffset: 0xFFFFFFFF
## Triggers creation of the .dynstr.
DynamicSymbols:
  - Name: foo

## Check that we report a warning when a SHT_GNU_verneed section contains a version dependency
## that goes past the end of the section.

# RUN: yaml2obj --docnum=8 %s -o %t8
# RUN: llvm-readobj --sections -V %t8 2>&1 | FileCheck %s -DFILE=%t8 --check-prefix=DEP-PAST-END
# RUN: llvm-readelf --sections -V %t8 2>&1 | FileCheck %s -DFILE=%t8 --check-prefix=DEP-PAST-END

# DEP-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verneed section with index 1: version dependency 1 goes past the end of the section

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .dynstr
    ShSize: 0x1
    Dependencies:
      - Version: 1
        File:    foo
        Entries:
          - Name:  'foo'
            Hash:  0
            Flags: 0
            Other: 0
DynamicSymbols:
  - Name: foo

## Check we report a warning when a version dependency is not correctly aligned in memory.

# RUN: yaml2obj --docnum=9 %s -o %t9
# RUN: llvm-readobj --sections -V %t9 2>&1 | FileCheck %s -DFILE=%t9 --check-prefix=MISALIGNED-DEP
# RUN: llvm-readelf --sections -V %t9 2>&1 | FileCheck %s -DFILE=%t9 --check-prefix=MISALIGNED-DEP

# MISALIGNED-DEP: warning: '[[FILE]]': invalid SHT_GNU_verneed section with index 1: found a misaligned version dependency entry at offset 0x0

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Type: Fill
    Size: 0x1
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .dynstr
    Dependencies:
      - Version: 1
        File:    foo
        Entries:
          - Name:  'foo'
            Hash:  0
            Flags: 0
            Other: 0
DynamicSymbols:
  - Name: foo

## Check that we report a warning when a SHT_GNU_verneed section contains a dependency definition
## that refers to an auxiliary entry that goes past the end of the section.

# RUN: yaml2obj --docnum=10 %s -o %t10
# RUN: llvm-readobj --sections -V %t10 2>&1 | FileCheck %s -DFILE=%t10 --check-prefix=AUX-PAST-END
# RUN: llvm-readelf --sections -V %t10 2>&1 | FileCheck %s -DFILE=%t10 --check-prefix=AUX-PAST-END

# AUX-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verneed section with index 1: version dependency 1 refers to an auxiliary entry that goes past the end of the section

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .dynstr
    ShSize: 21
    Dependencies:
      - Version: 1
        File:    foo
        Entries:
          - Name:  'foo'
            Hash:  0
            Flags: 0
            Other: 0
DynamicSymbols:
  - Name: foo

## Check we report a warning when an auxiliary entry is not correctly aligned in memory.

# RUN: yaml2obj %s --docnum=11 -o %t11
# RUN: llvm-readobj -V %t11 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t11
# RUN: llvm-readelf -V %t11 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t11

# MISALIGNED-AUX: warning: '[[FILE]]': invalid SHT_GNU_verneed section with index 1: found a misaligned auxiliary entry at offset 0x11

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .dynstr
## The byte offset to the auxiliary entry is 0x11, i.e. it is not correctly aligned in memory.
    Content: "0100010001000000110000000000000000000000"
DynamicSymbols:
  - Name: foo

## Check how we handle the case when a dependency definition entry has an unsupported version.

# RUN: yaml2obj %s --docnum=12 -o %t12
# RUN: llvm-readobj -V %t12 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t12
# RUN: llvm-readelf -V %t12 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t12

# UNSUPPORTED-VERSION: warning: '[[FILE]]': unable to dump SHT_GNU_verneed section with index 1: version 65278 is not yet supported

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Info:  1
    Link:  .dynstr
    Dependencies:
      - Version: 0xfefe
        File:    foo
        Entries:
          - Name:  'foo'
            Hash:  0
            Flags: 0
            Other: 0
DynamicSymbols:
  - Name: foo

## In this case SHT_GNU_verneed is linked to a custom dynamic string table, which is not
## called ".dynstr". Check we handle this case properly.

# RUN: yaml2obj --docnum=13 %s -o %t13
# RUN: llvm-readelf -V %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=GNU-CUSTOM-DYNSTR
# RUN: llvm-readobj -V %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=LLVM-CUSTOM-DYNSTR

# GNU-CUSTOM-DYNSTR:      Version symbols section '.gnu.version' contains 2 entries:
# GNU-CUSTOM-DYNSTR-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 4 (.dynsym)
# GNU-CUSTOM-DYNSTR-NEXT:   000:   0 (*local*)       2 (bcdefghij)
# GNU-CUSTOM-DYNSTR:      Version needs section '.gnu.version_r' contains 1 entries:
# GNU-CUSTOM-DYNSTR-NEXT:  Addr: 0000000000000004  Offset: 0x000044  Link: 3 (.custom.dynstr)
# GNU-CUSTOM-DYNSTR-NEXT:   0x0000: Version: 1  File: j  Cnt: 1
# GNU-CUSTOM-DYNSTR-NEXT:   0x0010:   Name: bcdefghij  Flags: none  Version: 2

# LLVM-CUSTOM-DYNSTR:      VersionSymbols [
# LLVM-CUSTOM-DYNSTR:      Symbol {
# LLVM-CUSTOM-DYNSTR:        Version: 2
# LLVM-CUSTOM-DYNSTR-NEXT:   Name: foo@bcdefghij

# LLVM-CUSTOM-DYNSTR:      VersionRequirements [
# LLVM-CUSTOM-DYNSTR:        Dependency {
# LLVM-CUSTOM-DYNSTR:          Entries [
# LLVM-CUSTOM-DYNSTR:            Entry {
# LLVM-CUSTOM-DYNSTR:              Index: 2
# LLVM-CUSTOM-DYNSTR-NEXT:          Name: bcdefghij

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Flags:   [ SHF_ALLOC ]
    Link:    .dynsym
    Entries: [ 0, 2 ]
  - Name:         .gnu.version_r
    Type:         SHT_GNU_verneed
    Flags:        [ SHF_ALLOC ]
    Link:         .custom.dynstr
    Info:         1
    AddressAlign: 4
    Dependencies:
      - Version: 1
        File:    zed
        Entries:
          - Name:  'bar'
            Hash:  0
            Flags: 0
            Other: 2
  - Name: .custom.dynstr
    Type: SHT_STRTAB
    Content: "6162636465666768696a00" ## 'a','b','c','d','e','f','g','h','i','j',NIL
DynamicSymbols:
  - Name:    foo
    Binding: STB_GLOBAL