llvm/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml

## Check how yaml2obj produces .llvm_bb_addr_map sections.

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s

## Case 1: Specify content.
# CHECK:      Section {
# CHECK:        Index: 1
# CHECK-NEXT:   Name: .llvm_bb_addr_map (1)
# CHECK-NEXT:   Type: SHT_LLVM_BB_ADDR_MAP (0x6FFF4C0A)
# CHECK-NEXT:   Flags [ (0x0)
# CHECK-NEXT:   ]
# CHECK-NEXT:   Address: 0x0
# CHECK-NEXT:   Offset: 0x40
# CHECK-NEXT:   Size: 13
# CHECK-NEXT:   Link: 0
# CHECK-NEXT:   Info: 0
# CHECK-NEXT:   AddressAlignment: 0
# CHECK-NEXT:   EntrySize: 0
# CHECK-NEXT:   SectionData (
# CHECK-NEXT:     0000: 00000000 00000000 01010203 04
# CHECK-NEXT:   )
# CHECK-NEXT: }

## Case 2: Empty.
# CHECK:        Name: .llvm_bb_addr_map (1)
# CHECK:        Size:
# CHECK-SAME:   {{^ 0$}}

## Case 3: Specify Size only.
# CHECK:        Name: .llvm_bb_addr_map (1)
# CHECK:        SectionData (
# CHECK-NEXT:     0000: 00000000 00000000
# CHECK-NEXT:   )

# Case 4: Specify Entries.
# CHECK:        Name: .llvm_bb_addr_map (1)
# CHECK:        SectionData (
# CHECK-NEXT:     0000: 02002000 00000000 0000010B 010203
# CHECK-NEXT:   )

# Case 5: Specify Entries and omit the Address field.
# CHECK:        Name: .llvm_bb_addr_map (1)
# CHECK:        Address:
# CHECK-SAME:   {{^ 0x0$}}
# CHECK:        SectionData (
# CHECK-NEXT:     0000: 02000000 00000000 0000010C 010203
# CHECK-NEXT:   )

# Case 6: Override the NumBlocks field.
# CHECK:        Name: .llvm_bb_addr_map (1)
# CHECK:        SectionData (
# CHECK-NEXT:     0000: 02002000 00000000 0000020D 010203
# CHECK-NEXT:   )

# Case 7: Specify empty BBRanges.
# CHECK:        Name: .llvm_bb_addr_map (1)
# CHECK:        SectionData (
# CHECK-NEXT:     0000: 020000
# CHECK-NEXT:   )

# Case 8: Specify empty BBRanges with multi-bb-range.
# CHECK:        Name: .llvm_bb_addr_map (1)
# CHECK:        SectionData (
# CHECK-NEXT:     0000: 020800
# CHECK-NEXT:   )




--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:

## Test the following cases:

## 1) We can produce an .llvm_bb_addr_map section from a description with section
##    content.
##  Specify Content.
  - Name:    '.llvm_bb_addr_map (1)'
    Type:    SHT_LLVM_BB_ADDR_MAP
    Content: "00000000000000000101020304"

## 2) We can produce an empty .llvm_bb_addr_map section from a description
##    with empty section content.
  - Name: '.llvm_bb_addr_map (2)'
    Type: SHT_LLVM_BB_ADDR_MAP

## 3) We can produce a zero .llvm_bb_addr_map section of a specific size when
##    we specify the size only.
  - Name: '.llvm_bb_addr_map (3)'
    Type: SHT_LLVM_BB_ADDR_MAP
    Size: 8

## 4) We can produce an .llvm_bb_addr_map section from a description with
##    Entries.
  - Name: '.llvm_bb_addr_map (4)'
    Type: SHT_LLVM_BB_ADDR_MAP
    Entries:
      - Version: 2
        BBRanges:
          - BaseAddress: 0x0000000000000020
            BBEntries:
              - ID:            11
                AddressOffset: 0x00000001
                Size:          0x00000002
                Metadata:      0x00000003

## 5) When specifying the description with Entries, the 'Address' field will be
##    zero when omitted.
  - Name: '.llvm_bb_addr_map (5)'
    Type: SHT_LLVM_BB_ADDR_MAP
    Entries:
      - Version: 2
        BBRanges:
          - BBEntries:
            - ID:            12
              AddressOffset: 0x00000001
              Size:          0x00000002
              Metadata:      0x00000003

## 6) We can override the NumBlocks field with a value different from the
##    actual number of BB Entries.
  - Name: '.llvm_bb_addr_map (6)'
    Type: SHT_LLVM_BB_ADDR_MAP
    Entries:
      - Version:   2
        BBRanges:
          - BaseAddress:   0x0000000000000020
            NumBlocks: 2
            BBEntries:
             - ID:            13
               AddressOffset: 0x00000001
               Size:          0x00000002
               Metadata:      0x00000003

## 7) We can produce a SHT_LLVM_BB_ADDR_MAP section from a description
##    with one entry with empty BBRanges.
  - Name: '.llvm_bb_addr_map (7)'
    Type: SHT_LLVM_BB_ADDR_MAP
    Entries:
      - Version: 2
        BBRanges: []

## 8) We can produce a SHT_LLVM_BB_ADDR_MAP section from a multi-bb-range
##    description with one entry with empty BBRanges.
  - Name: '.llvm_bb_addr_map (8)'
    Type: SHT_LLVM_BB_ADDR_MAP
    Entries:
      - Version: 2
        Feature: 0x8
        BBRanges: []

## Check we can't use Entries at the same time as either Content or Size.
# RUN: not yaml2obj --docnum=2 -DCONTENT="00" %s 2>&1 | FileCheck %s --check-prefix=INVALID
# RUN: not yaml2obj --docnum=2 -DSIZE="0" %s 2>&1 | FileCheck %s --check-prefix=INVALID

# INVALID: error: "Entries" cannot be used with "Content" or "Size"

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
##  Specify Content and Size
  - Name:    '.llvm_bb_addr_map'
    Type:    SHT_LLVM_BB_ADDR_MAP
    Entries: []
    Content: [[CONTENT=<none>]]
    Size:    [[SIZE=<none>]]

## Check that yaml2obj generates a warning when we use unsupported versions.
# RUN: yaml2obj --docnum=3  %s 2>&1 | FileCheck %s --check-prefix=INVALID-VERSION
# INVALID-VERSION: warning: unsupported SHT_LLVM_BB_ADDR_MAP version: 3; encoding using the most recent version

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name: '.llvm_bb_addr_map'
    Type: SHT_LLVM_BB_ADDR_MAP
    Entries:
##  Specify unsupported version
      - Version: 3