symbols.test 4.63 KB
## This is a general test for --symbols option and its aliases.
## There are also other symbols* tests that check specific things.

## Case 1: Test how llvm-readobj and llvm-readelf dumps symbols.
# RUN: yaml2obj %s --docnum=1 -o %t64
# RUN: llvm-readobj --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM
# RUN: llvm-readelf --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU64
# RUN: yaml2obj %s --docnum=2 -o %t32
# RUN: llvm-readobj --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM
# RUN: llvm-readelf --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU32

#      SYMBOLS-LLVM:Symbols [
# SYMBOLS-LLVM-NEXT:  Symbol {
# SYMBOLS-LLVM-NEXT:    Name:  (0)
# SYMBOLS-LLVM-NEXT:    Value: 0x0
# SYMBOLS-LLVM-NEXT:    Size: 0
# SYMBOLS-LLVM-NEXT:    Binding: Local (0x0)
# SYMBOLS-LLVM-NEXT:    Type: None (0x0)
# SYMBOLS-LLVM-NEXT:    Other: 0
# SYMBOLS-LLVM-NEXT:    Section: Undefined (0x0)
# SYMBOLS-LLVM-NEXT:  }
# SYMBOLS-LLVM-NEXT:  Symbol {
# SYMBOLS-LLVM-NEXT:    Name: foo (5)
# SYMBOLS-LLVM-NEXT:    Value: 0x1
# SYMBOLS-LLVM-NEXT:    Size: 0
# SYMBOLS-LLVM-NEXT:    Binding: Local (0x0)
# SYMBOLS-LLVM-NEXT:    Type: None (0x0)
# SYMBOLS-LLVM-NEXT:    Other: 0
# SYMBOLS-LLVM-NEXT:    Section: Undefined (0x0)
# SYMBOLS-LLVM-NEXT:  }
# SYMBOLS-LLVM-NEXT:  Symbol {
# SYMBOLS-LLVM-NEXT:    Name: bar (1)
# SYMBOLS-LLVM-NEXT:    Value: 0x2
# SYMBOLS-LLVM-NEXT:    Size: 0
# SYMBOLS-LLVM-NEXT:    Binding: Local (0x0)
# SYMBOLS-LLVM-NEXT:    Type: None (0x0)
# SYMBOLS-LLVM-NEXT:    Other: 0
# SYMBOLS-LLVM-NEXT:    Section: Undefined (0x0)
# SYMBOLS-LLVM-NEXT:  }
# SYMBOLS-LLVM-NEXT:]

#      SYMBOLS-GNU64:Symbol table '.symtab' contains 3 entries:
# SYMBOLS-GNU64-NEXT:   Num:    Value          Size Type    Bind   Vis       Ndx Name
# SYMBOLS-GNU64-NEXT:     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND 
# SYMBOLS-GNU64-NEXT:     1: 0000000000000001     0 NOTYPE  LOCAL  DEFAULT   UND foo
# SYMBOLS-GNU64-NEXT:     2: 0000000000000002     0 NOTYPE  LOCAL  DEFAULT   UND bar

#      SYMBOLS-GNU32:Symbol table '.symtab' contains 3 entries:
# SYMBOLS-GNU32-NEXT:   Num:    Value  Size Type    Bind   Vis       Ndx Name
# SYMBOLS-GNU32-NEXT:     0: 00000000     0 NOTYPE  LOCAL  DEFAULT   UND 
# SYMBOLS-GNU32-NEXT:     1: 00000001     0 NOTYPE  LOCAL  DEFAULT   UND foo
# SYMBOLS-GNU32-NEXT:     2: 00000002     0 NOTYPE  LOCAL  DEFAULT   UND bar

## Case 2: Check flag aliases produce identical output
# RUN: llvm-readobj --symbols %t64 > %t.symbols
# RUN: llvm-readobj --syms %t64 > %t.syms
# RUN: cmp %t.symbols %t.syms
# RUN: llvm-readobj -t %t64 > %t.t
# RUN: cmp %t.symbols %t.t
# RUN: llvm-readelf -s --elf-output-style=LLVM %t64 > %t.lowers
# RUN: cmp %t.symbols %t.lowers

# RUN: llvm-readelf --symbols %t64 > %t.symbols.gnu
# RUN: llvm-readelf --syms %t64 > %t.syms.gnu
# RUN: cmp %t.symbols.gnu %t.syms.gnu
## There is no -t option in llvm-readelf.
# RUN: not llvm-readelf -t %t64 2>&1 | FileCheck %s --check-prefix=NO-T-ERR
# NO-T-ERR: Unknown command line argument '-t'
## -s is an llvm-readobj option to dump sections.
# RUN: llvm-readobj -s --elf-output-style=GNU %t64 | FileCheck %s --implicit-check-not="Symbol table"

## Case 3: Test that both regular and dynamic symbols are dumped when `--symbols` and `--dyn-symbols`
##         are specified together. Note that the order is different for different styles.
# RUN: llvm-readobj --symbols --dyn-symbols %t64 | FileCheck %s --check-prefix=BOTH-LLVM
# RUN: llvm-readelf --symbols --dyn-symbols %t64 | FileCheck %s --check-prefix=BOTH-GNU

# BOTH-LLVM: Symbols [
# BOTH-LLVM: DynamicSymbols [

# BOTH-GNU: Symbol table '.dynsym'
# BOTH-GNU: Symbol table '.symtab'

## Case 4: --symbols implies --dyn-symbols for llvm-readelf.
# RUN: llvm-readobj --symbols %t64 | FileCheck %s --implicit-check-not="DynamicSymbols ["
# RUN: llvm-readelf --symbols %t64 | FileCheck %s --check-prefix=BOTH-GNU

## Case 5: Test that `--dyn-symbols` does not trigger `--symbols` implicitly.
# RUN: llvm-readobj --dyn-symbols %t64 | FileCheck %s --implicit-check-not="{{^}}Symbols ["
# RUN: llvm-readelf --dyn-symbols %t64 | FileCheck %s --implicit-check-not="Symbol table '.symtab'"

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Symbols:
  - Name:  foo
    Value: 0x1
  - Name:  bar
    Value: 0x2
DynamicSymbols:
  - Name:  zed

--- !ELF
FileHeader:
  Class:   ELFCLASS32
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_386
Symbols:
  - Name:  foo
    Value: 0x1
  - Name:  bar
    Value: 0x2
DynamicSymbols:
  - Name:  zed