llvm/llvm/test/tools/yaml2obj/ELF/arm-exidx-section.yaml

## Test how we create SHT_ARM_EXIDX sections.

## Test that the content of SHT_ARM_EXIDX sections,
## generated for 32/64-bit little/big endian targets is correct.
## Also check that we can use a special EXIDX_CANTUNWIND (0x1) value for a Value field of an entry.
# RUN: yaml2obj --docnum=1 -DENCODE=LSB -DCLASS=64 %s -o %t.le64
# RUN: llvm-readobj --sections --section-data %t.le64 | FileCheck %s --check-prefixes=DEFAULT,LE
# RUN: yaml2obj --docnum=1 -DENCODE=LSB -DCLASS=32 %s -o %t.le32
# RUN: llvm-readobj --sections --section-data %t.le32 | FileCheck %s --check-prefixes=DEFAULT,LE
# RUN: yaml2obj --docnum=1 -DENCODE=MSB -DCLASS=64 %s -o %t.be64
# RUN: llvm-readobj --sections --section-data %t.be64 | FileCheck %s --check-prefixes=DEFAULT,BE
# RUN: yaml2obj --docnum=1 -DENCODE=MSB -DCLASS=32 %s -o %t.be32
# RUN: llvm-readobj --sections --section-data %t.be32 | FileCheck %s --check-prefixes=DEFAULT,BE

# DEFAULT:      Name: .ARM.exidx (1)
# DEFAULT-NEXT: Type: SHT_ARM_EXIDX (0x70000001)
# DEFAULT-NEXT: Flags [ (0x0)
# DEFAULT-NEXT: ]
# DEFAULT-NEXT: Address: 0x0
# DEFAULT-NEXT: Offset: 0x{{.*}}
# DEFAULT-NEXT: Size: 16
# DEFAULT-NEXT: Link: 0
# DEFAULT-NEXT: Info: 0
# DEFAULT-NEXT: AddressAlignment: 0
# DEFAULT-NEXT: EntrySize: 0
# DEFAULT-NEXT: SectionData (
# LE-NEXT:       0000: DDCCBBAA 44332211 9988FFEE 01000000  |
# BE-NEXT:       0000: AABBCCDD 11223344 EEFF8899 00000001  |
# DEFAULT-NEXT: )

--- !ELF
FileHeader:
  Class:   ELFCLASS[[CLASS=64]]
  Data:    ELFDATA2[[ENCODE=LSB]]
  Type:    ET_DYN
  Machine: [[MACHINE=EM_ARM]]
Sections:
  - Name: .ARM.exidx
    Type: SHT_ARM_EXIDX
    Entries:
      - Offset: 0xAABBCCDD
        Value:  0x11223344
      - Offset: 0xEEFF8899
        Value:  EXIDX_CANTUNWIND

## Check we only recognize the SHT_ARM_EXIDX section type when machine type is EM_ARM.
# RUN: not yaml2obj --docnum=1 -DMACHINE=EM_NONE %s 2>&1 | FileCheck %s --check-prefix=UNKNOWN

# UNKNOWN:      error: invalid hex32 number
# UNKNOWN-NEXT:  Type: SHT_ARM_EXIDX

## Check we can set arbitrary section properties for a SHT_ARM_EXIDX section.
## Also check that we are able to specify none of "Entries", "Content" nor "Size" keys.

# RUN: yaml2obj --docnum=2 %s -o %t.props.o
# RUN: llvm-readelf --sections %t.props.o | FileCheck %s --check-prefix=PROPERTIES

# PROPERTIES: [Nr] Name       Type      Address          Off    Size   ES Flg Lk    Inf Al
# PROPERTIES: [ 1] .ARM.exidx ARM_EXIDX 0000000000001122 000055 000000 66 AMS 13124 0   85

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_ARM
Sections:
  - Name:         .ARM.exidx
    Type:         SHT_ARM_EXIDX
    Flags:        [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
    Address:      0x1122
    Link:         0x3344
    AddressAlign: 0x55
    EntSize:      0x66

## Check we can't use the "Entries" key together with the "Content" or "Size" keys.

# RUN: not yaml2obj --docnum=3 -DSIZE=0 -DENT="[]" %s 2>&1 | \
# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
# RUN: not yaml2obj --docnum=3 -DCONTENT="'00'" -DENT="[]" %s 2>&1 | \
# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR

# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size"

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_ARM
Sections:
  - Name:    .ARM.exidx
    Type:    SHT_ARM_EXIDX
    Size:    [[SIZE=<none>]]
    Content: [[CONTENT=<none>]]
    Entries: [[ENT=<none>]]

## Check we can use the "Content" key with the "Size" key when the size is greater
## than or equal to the content size.

# RUN: not yaml2obj --docnum=3 -DCONTENT="'00'" -DSIZE=0 %s 2>&1 | \
# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR

# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size

# RUN: yaml2obj --docnum=3 -DCONTENT="'00'" -DSIZE=1 %s -o %t.cont.size.eq.o
# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="00"

# RUN: yaml2obj --docnum=3 -DCONTENT="'00'" -DSIZE=2 %s -o %t.cont.size.gr.o
# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0000"

# CHECK-CONTENT:      Name: .ARM.exidx
# CHECK-CONTENT:      SectionData (
# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
# CHECK-CONTENT-NEXT: )

## Check we can use "Content" key alone to emit arbitrary content.

# RUN: yaml2obj --docnum=3 -DCONTENT="'11223344'" %s -o %t.content.o
# RUN: llvm-readobj --sections --section-data %t.content.o | \
# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="11223344"

## Check we can use "Size" key alone to emit content of an arbitrary size.

# RUN: yaml2obj --docnum=3 -DSIZE=4 %s -o %t.size.o
# RUN: llvm-readobj --sections --section-data %t.size.o | \
# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="00000000"