Compiler projects using llvm
## Check we print symbol versions, when they are available.

## Test undefined symbols.
# RUN: yaml2obj %s -o %t-undef.o
# RUN: llvm-objdump -T %t-undef.o 2>&1 | tr '\t' '|' | FileCheck %s \
# RUN:   -DFILE=%t-undef.o --check-prefix=UNDEF --match-full-lines --strict-whitespace

## version2sym and version3sym are invalid: undefined symbols cannot refer to .gnu.version_d.
## We still check their behaviors.
#      UNDEF:DYNAMIC SYMBOL TABLE:
# UNDEF-NEXT:0000000000000000      D  *UND*|0000000000000000              localversym
# UNDEF-NEXT:0000000000000000      D  *UND*|0000000000000000              globalversym
# UNDEF-NEXT:0000000000000000      D  *UND*|0000000000000000 (v2)         version2sym
# UNDEF-NEXT:0000000000000000      D  *UND*|0000000000000000 (v3hidden)   version3sym
# UNDEF-NEXT:0000000000000000      D  *UND*|0000000000000000 (v4)         version4sym
# UNDEF-NEXT:0000000000000000      D  *UND*|0000000000000000 (v5hidden)   .hidden version5sym

## Test defined symbols.
# RUN: yaml2obj -DINDEX=0x1 %s -o %t-def.o
# RUN: llvm-objdump -T %t-def.o 2>&1 | tr '\t' '|' | FileCheck %s \
# RUN:   -DFILE=%t-def.o --check-prefix=DEF --match-full-lines --strict-whitespace

#      DEF:DYNAMIC SYMBOL TABLE:
# DEF-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000              localversym
# DEF-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000              globalversym
# DEF-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000  v2          version2sym
# DEF-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000 (v3hidden)   version3sym
# DEF-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000 (v4)         version4sym
# DEF-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000 (v5hidden)   .hidden version5sym

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Flags:   [ SHF_ALLOC ]
## 0x8000 is a special VERSYM_HIDDEN bit.
    Entries: [ 0, 0, 1, 2, 0x8003, 4, 0x8005 ]
    ShSize:  [[VERSYMSIZE=<none>]]
  - Name:         .gnu.version_d
    Type:         SHT_GNU_verdef
    Flags:        [ SHF_ALLOC ]
    Link:         .dynstr
    AddressAlign: 0x4
    Info:         0x2
    ShOffset:     [[VERDEFOFFSET=<none>]]
    Entries:
      - VersionNdx: 2
        Names:
          - v2
      - VersionNdx: 3
        Names:
          - v3hidden
  - Name:  .gnu.version_r
    Type:  SHT_GNU_verneed
    Flags: [ SHF_ALLOC ]
    Link:  .dynstr
    Info:  0x2
    Dependencies:
      - Version: 1
        File:    file1.so
        Entries:
          - Name:  v4
            Hash:  0
            Flags: 0
            Other: 4
      - Version: 1
        File:    file2.0
        Entries:
          - Name:  v5hidden
            Hash:  0
            Flags: 0
            Other: 5
  - Name:    .dynsym
    Type:    SHT_DYNSYM
    EntSize: [[ENTSIZE=<none>]]
DynamicSymbols:
  - Name:  localversym
    Index: [[INDEX=<none>]]
    Binding: STB_GLOBAL
  - Name:  globalversym
    Index: [[INDEX=<none>]]
    Binding: STB_GLOBAL
  - Name:  version2sym
    Index: [[INDEX=<none>]]
    Binding: STB_GLOBAL
  - Name:  version3sym
    Index: [[INDEX=<none>]]
    Binding: STB_GLOBAL
  - Name:  version4sym
    Index: [[INDEX=<none>]]
    Binding: STB_GLOBAL
  - Name:  version5sym
    Index: [[INDEX=<none>]]
    Other: [ STV_HIDDEN ]
    Binding: STB_GLOBAL

## Test the output with a long version name.
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-objdump -T %t2 2>&1 | tr '\t' '|' | FileCheck %s \
# RUN:   --check-prefix=LONGNAME --match-full-lines --strict-whitespace

#      LONGNAME:DYNAMIC SYMBOL TABLE:
# LONGNAME-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000  v2          sym1
# LONGNAME-NEXT:0000000000000000 g    D  .gnu.version|0000000000000000  v3withverylongname sym2

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Flags:   [ SHF_ALLOC ]
    Entries: [ 1, 2, 3 ]
  - Name:         .gnu.version_d
    Type:         SHT_GNU_verdef
    Flags:        [ SHF_ALLOC ]
    Link:         .dynstr
    AddressAlign: 0x4
    Info:         0x2
    Entries:
      - VersionNdx: 2
        Names:
          - v2
      - VersionNdx: 3
        Names:
          - v3withverylongname
  - Name:    .dynsym
    Type:    SHT_DYNSYM
DynamicSymbols:
  - Name:  sym1
    Index: 1
    Binding: STB_GLOBAL
  - Name:  sym2
    Index: 1
    Binding: STB_GLOBAL

## Check we report a warning when we are unable to read a SHT_GNU_versym section entry.
## In this case, the section has a size that is not a multiple of its sh_entsize.

# RUN: yaml2obj -DVERSYMSIZE=0xff %s -o %t2-broken-versym.o
# RUN: llvm-objdump -T %t2-broken-versym.o 2>&1 | FileCheck %s --check-prefixes=VERSION-ERR1,NOVER

# VERSION-ERR1:warning: {{.*}}: unable to read an entry with index 1 from SHT_GNU_versym section
# NOVER-NEXT:0000000000000000      D  *UND*  0000000000000000 localversym
# NOVER-NEXT:0000000000000000      D  *UND*  0000000000000000 globalversym
# NOVER-NEXT:0000000000000000      D  *UND*  0000000000000000 version2sym
# NOVER-NEXT:0000000000000000      D  *UND*  0000000000000000 version3sym
# NOVER-NEXT:0000000000000000      D  *UND*  0000000000000000 version4sym
# NOVER-NEXT:0000000000000000      D  *UND*  0000000000000000 .hidden version5sym