duplicate-symbol-and-section-names.yaml 3.42 KB
## Check that obj2yaml is able to produce YAML from
## an object containing symbols and sections with duplicate
## names and produces same-named sections and symbols
## with distinguishing suffixes.

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

# CHECK: Name: .foo (
# CHECK: Name: .foo (
# CHECK: Name: .foo (
# CHECK: Name: .bar (
# CHECK: Name: .bar (
# CHECK: Name: .bar (

# CHECK: Name: localfoo (
# CHECK: Name: localfoo (
# CHECK: Name: localfoo (
# CHECK: Name: localbar (
# CHECK: Name: localbar (
# CHECK: Name: localbar (

# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=CASE1

# CASE1:      --- !ELF
# CASE1-NEXT: FileHeader:
# CASE1-NEXT:   Class: ELFCLASS64
# CASE1-NEXT:   Data:  ELFDATA2LSB
# CASE1-NEXT:   Type:  ET_REL
# CASE1-NEXT: Sections:
# CASE1-NEXT:   - Name: .foo
# CASE1-NEXT:     Type: SHT_PROGBITS
# CASE1-NEXT:   - Name: '.foo (1)'
# CASE1-NEXT:     Type: SHT_PROGBITS
# CASE1-NEXT:   - Name: '.foo (2)'
# CASE1-NEXT:     Type: SHT_PROGBITS
# CASE1-NEXT:   - Name: .bar
# CASE1-NEXT:     Type: SHT_PROGBITS
# CASE1-NEXT:   - Name: '.bar (1)'
# CASE1-NEXT:     Type: SHT_PROGBITS
# CASE1-NEXT:   - Name: '.bar (2)'
# CASE1-NEXT:     Type: SHT_PROGBITS
# CASE1-NEXT: Symbols:
# CASE1-NEXT:   - Name: localfoo
# CASE1-NEXT:   - Name: 'localfoo (1)'
# CASE1-NEXT:   - Name: 'localfoo (2)'
# CASE1-NEXT:   - Name: localbar
# CASE1-NEXT:   - Name: 'localbar (1)'
# CASE1-NEXT:   - Name: 'localbar (2)'
# CASE1-NEXT: ...

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_REL
Sections:
  - Name: .foo
    Type: SHT_PROGBITS
  - Name: '.foo (555)'
    Type: SHT_PROGBITS
  - Name: '.foo (random_tag)'
    Type: SHT_PROGBITS
  - Name: .bar
    Type: SHT_PROGBITS
  - Name: '.bar (666)'
    Type: SHT_PROGBITS
  - Name: '.bar (random_tag)'
    Type: SHT_PROGBITS
Symbols:
  - Name: 'localfoo (111)'
  - Name: 'localfoo (222)'
  - Name: 'localfoo (random_tag)'
  - Name: 'localbar (333)'
  - Name: 'localbar (444)'
  - Name: 'localbar (random_tag)'

## Check we can refer to symbols with the same
## name from relocations.

# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=CASE2

# CASE2:      Relocations:
# CASE2-NEXT:  - Symbol: 'foo (1)'
# CASE2-NEXT:    Type:   R_X86_64_PC32
# CASE2-NEXT:  - Offset: 0x0000000000000004
# CASE2-NEXT:    Symbol: foo
# CASE2-NEXT:    Type:   R_X86_64_PC32
# CASE2-NEXT: Symbols:
# CASE2-NEXT:  - Name: foo
# CASE2-NEXT:  - Name: 'foo (1)'
  
--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name: .text
    Type: SHT_PROGBITS
    Size: 8
  - Name: .rela.text
    Type: SHT_RELA
    Info: .text
    Link: .symtab
    Relocations:
      - Type: R_X86_64_PC32
        Symbol: 'foo (1)'
      - Type: R_X86_64_PC32
        Offset: 4
        Symbol: foo
Symbols:
  - Name: foo
  - Name: 'foo (1)'

## Check obj2yaml does not add a suffix to a name if the
## symbol is in .symtab and .dynsym at the same time.

# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=CASE3

# CASE3:      Symbols:
# CASE3-NEXT:   - Name:    foo
# CASE3-NEXT:     Binding: STB_GLOBAL
# CASE3-NEXT: DynamicSymbols:
# CASE3-NEXT:   - Name:    foo
# CASE3-NEXT:     Binding: STB_GLOBAL

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
Symbols:
  - Name:    foo
    Binding: STB_GLOBAL
DynamicSymbols:
  - Name:    foo
    Binding: STB_GLOBAL