dynamic-symbols.yaml 2.23 KB
## Ensures that implicitly added sections can be ordered within Sections.

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj --sections %t1 | FileCheck %s --check-prefix=SECTION
# RUN: llvm-nm --dynamic %t1 | FileCheck %s --check-prefix=SYMBOL

--- !ELF
FileHeader:
  Class:           ELFCLASS64
  Data:            ELFDATA2LSB
  Type:            ET_DYN
  Machine:         EM_X86_64
Sections:
  - Name: .data
    Type: SHT_PROGBITS
    Flags: [ SHF_ALLOC, SHF_WRITE ]
DynamicSymbols:
  - Name: dynlocal
    Type: STT_OBJECT
    Section: .data
    Binding: STB_LOCAL
  - Name: dynglobal
    Type: STT_OBJECT
    Section: .data
    Binding: STB_GLOBAL
  - Name: dynweak
    Type: STT_OBJECT
    Section: .data
    Binding: STB_WEAK

# SECTION: Name: .dynsym
# SECTION-NEXT: Type: SHT_DYNSYM
# SECTION-NEXT: Flags
# SECTION-NEXT: SHF_ALLOC
# SECTION: Name: .dynstr
# SECTION-NEXT: Type: SHT_STRTAB
# SECTION-NEXT: Flags
# SECTION-NEXT: SHF_ALLOC

# SYMBOL-DAG: d dynlocal
# SYMBOL-DAG: D dynglobal
# SYMBOL-DAG: V dynweak

## Check we can use numeric values to refer to sections.

# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --dyn-symbols %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=NUM

# NUM:      Name: foo
# NUM:      Section:
# NUM-SAME: .data (0x1)

# NUM:      Name: bar
# NUM:      Section:
# NUM-SAME: .strtab (0x2)

# NUM:      Name: zed
# NUM: warning: '[[FILE]]': invalid section index: 255
# NUM:      Section:
# NUM-SAME: <?> (0xFF)

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .data
    Type: SHT_PROGBITS
DynamicSymbols:
  - Name: foo
    Section: 1
  - Name: bar
    Section: 2
  - Name: zed
    Section: 0xff

## Check we report errors when unknown sections are referenced by dynamic symbols.

# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=ERR

# ERR: error: unknown section referenced: '.sec1' by YAML symbol 'foo'
# ERR: error: unknown section referenced: '.sec2' by YAML symbol 'bar'

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .data
    Type: SHT_PROGBITS
DynamicSymbols:
  - Name: foo
    Section: .sec1
  - Name: bar
    Section: .sec2