llvm/llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml

## Test how we dump SHT_LLVM_CALL_GRAPH_PROFILE sections for 32 and 64-bit targets.

## Test we use the "Entries" property when it is possible to dump values correctly.

# RUN: yaml2obj -D BITS=64 -D ENCODE=LSB %s -o %t.le64
# RUN: obj2yaml %t.le64 | FileCheck %s --check-prefix=BASIC
# RUN: yaml2obj -D BITS=64 -D ENCODE=MSB %s -o %t.be64
# RUN: obj2yaml %t.be64 | FileCheck %s --check-prefix=BASIC
# RUN: yaml2obj -D BITS=32 -D ENCODE=LSB %s -o %t.le32
# RUN: obj2yaml %t.le32 | FileCheck %s --check-prefix=BASIC
# RUN: yaml2obj -D BITS=32 -D ENCODE=MSB %s -o %t.be32
# RUN: obj2yaml %t.be32 | FileCheck %s --check-prefix=BASIC

# BASIC:      Sections:
# BASIC-NEXT:   - Name: .llvm.call-graph-profile
# BASIC-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# BASIC-NEXT:     Link: .symtab
# BASIC-NEXT:     Entries:
# BASIC-NEXT:       - Weight: 89
# BASIC-NEXT:       - Weight: 98
# BASIC-NEXT: Symbols:

--- !ELF
FileHeader:
  Class: ELFCLASS[[BITS]]
  Data:  ELFDATA2[[ENCODE]]
  Type:  ET_DYN
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 89
      - Weight: 98
Symbols:
  - Name: foo
  - Name: bar

## Check how we handle broken cases.

# RUN: yaml2obj --docnum=2 %s -o %t.invalid
# RUN: obj2yaml %t.invalid | FileCheck %s --check-prefix=INVALID

# INVALID:      --- !ELF
# INVALID-NEXT: FileHeader:
# INVALID-NEXT:   Class: ELFCLASS32
# INVALID-NEXT:   Data:  ELFDATA2MSB
# INVALID-NEXT:   Type:  ET_DYN
# INVALID-NEXT: Sections:
# INVALID-NEXT:   - Name: .empty
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link: .symtab
# INVALID-NEXT:   - Name: .multiple.8.valid
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link: .symtab
# INVALID-NEXT:     Entries:
# INVALID-NEXT:         Weight: 3
# INVALID-NEXT:   - Name: .non.multiple.8
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link: .symtab
# INVALID-NEXT:     Content: '000000000000000300'
# INVALID-NEXT:   - Name: .multiple.8.invalid
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link: .symtab
# INVALID-NEXT:     Content: 008899AABBCCDDEEFF
# INVALID-NEXT:   - Name: .link.to.symtable
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link: .symtab
# INVALID-NEXT:     Entries:
# INVALID-NEXT:       - Weight: 0
# INVALID-NEXT:   - Name: .link.to.non.symtable.1
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Entries:
# INVALID-NEXT:           - Weight: 0
# INVALID-NEXT:   - Name: .link.to.non.symtable.2
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link: .empty
# INVALID-NEXT:     Entries:
# INVALID-NEXT:      - Weight: 0
# INVALID-NEXT:   - Name:    .zero.entry.size
# INVALID-NEXT:     Type:    SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link:    .symtab
# INVALID-NEXT:     EntSize: 0x0
# INVALID-NEXT:     Entries:
# INVALID-NEXT:       - Weight: 0
# INVALID-NEXT:   - Name: .invalid.entry.size
# INVALID-NEXT:     Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT:     Link: .symtab
# INVALID-NEXT:     EntSize: 0x1
# INVALID-NEXT:     Entries:
# INVALID-NEXT:       - Weight: 0
# INVALID-NEXT: Symbols:
# INVALID-NEXT:   - Name: foo
# INVALID-NEXT:   - Name: bar

--- !ELF
FileHeader:
  Class: ELFCLASS32
  Data:  ELFDATA2MSB
  Type:  ET_DYN
Sections:
## Case 1: Content is empty.
  - Name: .empty
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
## Case 2: Check that we use the "Entries" property to dump the data when it
##         has a size that is a multiple of 16 and is valid (it is possible to match
##         symbol indexes to symbols), but fallback to dumping the whole section
##         using the "Content" property otherwise.
## TODO: Teach yaml2obj to accept 'Size' key for SHT_LLVM_CALL_GRAPH_PROFILE
##       sections and use Entries for cases below.
  - Name: .multiple.8.valid
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Content: "0000000000000003"
  - Name: .non.multiple.8
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Content: "000000000000000300"
  - Name: .multiple.8.invalid
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Content: "008899AABBCCDDEEFF"
## Case 4: Check we use the "Content" property when a linked section
##         is not a symbol table.
  - Name: .link.to.symtable
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 0
  - Name: .link.to.non.symtable.1
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Link: 0
    Entries:
      - Weight: 0
  - Name: .link.to.non.symtable.2
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Link: 1
    Entries:
      - Weight: 0
## Case 5: Check we can dump a section that has a sh_entsize that is not a multiple of 16.
##         Check that in these cases we print the "EntSize" key.
  - Name: .zero.entry.size
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    EntSize: 0
    Entries:
      - Weight: 0
  - Name: .invalid.entry.size
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    EntSize: 1
    Entries:
      - Weight: 0
Symbols:
  - Name: foo
  - Name: bar