## Check that yaml2obj is able to produce an object from YAML
## containing sections with duplicate names (but different name suffixes).

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj -s %t1 | FileCheck %s --check-prefix=CASE1

# CASE1: Name: .foo1 (
# CASE1: Name: .foo (
# CASE1: Name: .foo (
# CASE1: Name: .foo2 (

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name: .foo1
    Type: SHT_PROGBITS
  - Name: .foo
    Type: SHT_PROGBITS
  - Name: '.foo [1]'
    Type: SHT_PROGBITS
  - Name: .foo2
    Type: SHT_PROGBITS

## Check that yaml2obj reports an error in case we have
## sections with equal names and suffixes.

# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=CASE2
# CASE2: error: repeated section/fill name: '.foo [1]' at YAML section/fill number 2
# CASE2: error: repeated section/fill name: '.foo [1]' at YAML section/fill number 3

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name: '.foo [1]'
    Type: SHT_PROGBITS
  - Name: '.foo [1]'
    Type: SHT_PROGBITS
  - Name: '.foo [1]'
    Type: SHT_PROGBITS

## Check that yaml2obj reports an error in case we have
## symbols without suffixes in the names and their
## names are equal.

# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=CASE3
# CASE3: error: repeated section/fill name: '.foo' at YAML section/fill number 2

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name: .foo
    Type: SHT_PROGBITS
  - Name: .foo
    Type: SHT_PROGBITS

## Check that yaml2obj can produce an object when symbols are defined
## relative to sections with duplicate names (but different name suffixes).

# RUN: yaml2obj --docnum=4 %s -o %t4
# RUN: llvm-readobj -s -t %t4 | FileCheck %s --check-prefix=CASE4

# CASE4:      Section {
# CASE4:       Index: 1
# CASE4-NEXT:  Name: .foo
# CASE4:       Index: 2
# CASE4-NEXT:  Name: .foo

# CASE4:      Symbol {
# CASE4:       Name: foo
# CASE4-NEXT:  Value:
# CASE4-NEXT:  Size:
# CASE4-NEXT:  Binding:
# CASE4-NEXT:  Type:
# CASE4-NEXT:  Other:
# CASE4-NEXT:  Section: .foo (0x1)
# CASE4:       Name: bar
# CASE4-NEXT:  Value:
# CASE4-NEXT:  Size:
# CASE4-NEXT:  Binding:
# CASE4-NEXT:  Type:
# CASE4-NEXT:  Other:
# CASE4-NEXT:  Section: .foo (0x2)

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name: .foo
    Type: SHT_PROGBITS
  - Name: '.foo [1]'
    Type: SHT_PROGBITS
Symbols:
  - Name:    foo
    Section: .foo
  - Name:    bar
    Section: '.foo [1]'

## Check that yaml2obj can produce SHT_GROUP sections that
## reference sections and symbols with name suffixes.

# RUN: yaml2obj --docnum=5 %s -o %t5
# RUN: llvm-readobj --elf-section-groups %t5 | FileCheck %s --check-prefix=CASE5

# CASE5:      Groups {
# CASE5-NEXT:   Group {
# CASE5-NEXT:     Name: .group (1)
# CASE5-NEXT:     Index: 1
# CASE5-NEXT:     Link: 5
# CASE5-NEXT:     Info: 1
# CASE5-NEXT:     Type: COMDAT (0x1)
# CASE5-NEXT:     Signature: foo
# CASE5-NEXT:     Section(s) in group [
# CASE5-NEXT:       .text.foo (2)
# CASE5-NEXT:     ]
# CASE5-NEXT:   }
# CASE5-NEXT:   Group {
# CASE5-NEXT:     Name: .group (1)
# CASE5-NEXT:     Index: 3
# CASE5-NEXT:     Link: 5
# CASE5-NEXT:     Info: 2
# CASE5-NEXT:     Type: COMDAT (0x1)
# CASE5-NEXT:     Signature: foo
# CASE5-NEXT:     Section(s) in group [
# CASE5-NEXT:       .text.foo (4)
# CASE5-NEXT:     ]
# CASE5-NEXT:   }
# CASE5-NEXT: }

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name: .group
    Type: SHT_GROUP
    Info: foo
    Members:
      - SectionOrType: GRP_COMDAT
      - SectionOrType: .text.foo
  - Name: .text.foo
    Type: SHT_PROGBITS
  - Name: '.group [1]'
    Type: SHT_GROUP
    Info: 'foo [1]'
    Members:
      - SectionOrType: GRP_COMDAT
      - SectionOrType: '.text.foo [1]'
  - Name: '.text.foo [1]'
    Type: SHT_PROGBITS
Symbols:
  - Name:    foo
    Section: .text.foo
  - Name:    'foo [1]'
    Section: '.text.foo [1]'
