[llvm-objdump][test] Reorganize ELF --syms tests

Merge symbol-table-elf.test and common-symbol-elf.test, and add some
more tests (invalid st_type, STT_COMMON, STT_GNU_IFUNC, STT_HIOS, STT_LOPROC, SHN_UNDEF, SHN_ABS, SHN_COMMON, STB_GNU_UNIQUE, invalid binding, etc) to test/llvm-objdump/ELF/symbol-table.test

The naming follows test/llvm-{readobj,objcopy}/ELF .

Some discrepancy from GNU objdump:

* STT_COMMON: can be produced with `ld.bfd -r -z common`, but it almost never exists in practice
* STT_GNU_IFUNC: will be fixed by D75793
* STB_GNU_UNIQUE: will be fixed by D75797
* STT_TLS: GNU objdump does not print 'O'
* unknown binding: GNU objdump does not print 'g'. This probably does not matter.
* A reserved symbol index is displayed as *ABS* in GNU objdump. It is not clear what we should print.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D75796
This commit is contained in:
Fangrui Song 2020-03-06 20:22:59 -08:00
parent d09873308c
commit a67a0f1131
4 changed files with 148 additions and 60 deletions

View File

@ -0,0 +1,148 @@
## Test how --syms/-t prints the static symbol table.
# RUN: yaml2obj --docnum=1 %s -o %t
# RUN: llvm-objdump --syms %t > %t.txt
# RUN: llvm-objdump -t %t | cmp - %t.txt
# RUN: FileCheck %s --input-file=%t.txt --match-full-lines --strict-whitespace
# CHECK:SYMBOL TABLE:
# CHECK-NEXT:0000000000000000 l df *ABS* 0000000000000000 a.c
# CHECK-NEXT:0000000000000000 l d .text 0000000000000000 .text
# CHECK-NEXT:0000000000002000 l O .data 0000000000000000 local_object
# CHECK-NEXT:0000000000001fff l F .text 0000000000000000 local_func
# CHECK-NEXT:0000000000000000 l *ABS* 0000000000000000 local_abs
# CHECK-NEXT:0000000000000000 g .data 0000000000000000 notype
# CHECK-NEXT:0000000000000000 g O .data 0000000000000010 object
# CHECK-NEXT:0000000000000000 g F .text 000000000000000f func
# CHECK-NEXT:0000000000000000 g O *COM* 0000000000000000 common
# CHECK-NEXT:0000000000000000 g O .data 0000000000000000 tls
# CHECK-NEXT:0000000000000000 g .text 0000000000000000 ifunc
# CHECK-NEXT:0000000000000000 g .text 0000000000000000 invalid_type
# CHECK-NEXT:0000000000000000 g .text 0000000000000000 STT_HIOS
# CHECK-NEXT:0000000000000000 g .text 0000000000000000 STT_LOPROC
# CHECK-NEXT:0000000000000000 *UND* 0000000000000000 undef
# CHECK-NEXT:0000000000000000 *UND* 0000000000000000 SHN_LOPROC
# CHECK-NEXT:0000000000000000 *UND* 0000000000000000 SHN_LOOS
# CHECK-NEXT:0000000000000000 *UND* 0000000000000000 reserve
# CHECK-NEXT:0000000000000000 g *ABS* 0000000000000000 abs
# CHECK-NEXT:0000000000000000 *COM* 0000000000000000 common2
# CHECK-NEXT:0000000000000000 g O .data 0000000000000000 gnu_unique
# CHECK-NEXT:0000000000000000 g .data 0000000000000000 invalid_binding
# CHECK-NEXT:0000000000000000 g .data 0000000000000000 STB_HIOS
# CHECK-NEXT:0000000000000000 g .data 0000000000000000 STB_LOPROC
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
- Name: .data
Type: SHT_PROGBITS
Symbols:
- Name: "a.c"
Type: STT_FILE
Index: SHN_ABS
- Type: STT_SECTION
Section: .text
- Name: local_object
Type: STT_OBJECT
Section: .data
Value: 0x2000
- Name: local_func
Type: STT_FUNC
Section: .text
Value: 0x1fff
- Name: local_abs
Index: SHN_ABS
- Name: notype
Binding: STB_GLOBAL
Section: .data
- Name: object
Type: STT_OBJECT
Size: 0x10
Binding: STB_GLOBAL
Section: .data
- Name: func
Type: STT_FUNC
Size: 0xf
Binding: STB_GLOBAL
Section: .text
- Name: common
Type: STT_COMMON
Binding: STB_GLOBAL
Section: .data
- Name: tls
Type: STT_TLS
Binding: STB_GLOBAL
Section: .data
- Name: ifunc
Type: STT_GNU_IFUNC
Binding: STB_GLOBAL
Section: .text
- Name: invalid_type
Type: 7
Binding: STB_GLOBAL
Section: .text
- Name: STT_HIOS
Type: 12
Binding: STB_GLOBAL
Section: .text
- Name: STT_LOPROC
Type: 13
Binding: STB_GLOBAL
Section: .text
- Name: undef
Binding: STB_GLOBAL
- Name: SHN_LOPROC
Binding: STB_GLOBAL
Index: 0xff00
- Name: SHN_LOOS
Binding: STB_GLOBAL
Index: 0xff20
- Name: reserve
Binding: STB_GLOBAL
Index: 0xff40
- Name: abs
Index: SHN_ABS
Binding: STB_GLOBAL
- Name: common2
Binding: STB_GLOBAL
Index: SHN_COMMON
- Name: gnu_unique
Type: STT_OBJECT
Binding: STB_GNU_UNIQUE
Section: .data
- Name: invalid_binding
Binding: 3
Section: .data
- Name: STB_HIOS
Binding: 12
Section: .data
- Name: STB_LOPROC
Binding: 13
Section: .data
## For an ELF32 object, print the address and size fields as 32-bit hexadecimals.
# RUN: yaml2obj --docnum=2 -D BITS=32 %s -o %t.32
# RUN: llvm-objdump --syms %t.32 | FileCheck --check-prefix=ELF32 %s --match-full-lines --strict-whitespace
## For an ELF64 object, print the address and size fields as 64-bit hexadecimals.
# RUN: yaml2obj --docnum=2 -D BITS=64 %s -o %t.64
# RUN: llvm-objdump --syms %t.64 | FileCheck --check-prefix=ELF64 %s --match-full-lines --strict-whitespace
# ELF32:SYMBOL TABLE:
# ELF32-NEXT:00000000 *UND* 00000000 sym
# ELF64:SYMBOL TABLE:
# ELF64-NEXT:0000000000000000 *UND* 0000000000000000 sym
--- !ELF
FileHeader:
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Symbols:
- Name: sym

View File

@ -1,3 +0,0 @@
// RUN: llvm-objdump -t %p/Inputs/common-symbol-elf | FileCheck %s
CHECK: 00000400 O *COM* 00000008 common_symbol

View File

@ -1,57 +0,0 @@
# RUN: yaml2obj -D BITS=32 %s -o %t.32
# RUN: llvm-objdump --syms %t.32 > %t.32.txt
# RUN: llvm-objdump -t %t.32 | cmp - %t.32.txt
# RUN: FileCheck --check-prefix=ELF32 %s --input-file=%t.32.txt
# RUN: yaml2obj -D BITS=64 %s -o %t.64
# RUN: llvm-objdump --syms %t.64 | FileCheck --check-prefix=ELF64 %s
# ELF32: SYMBOL TABLE:
# ELF32-NEXT: 00001004 l F .text 00000000 lfoo
# ELF32-NEXT: 00001008 l O .text 00000000 lbar
# ELF32-NEXT: 00001004 g F .text 00000000 foo
# ELF32-NEXT: 00001008 g O .text 00000000 bar
# ELF64: SYMBOL TABLE:
# ELF64-NEXT: 0000000000001004 l F .text 0000000000000000 lfoo
# ELF64-NEXT: 0000000000001008 l O .text 0000000000000000 lbar
# ELF64-NEXT: 0000000000001004 g F .text 0000000000000000 foo
# ELF64-NEXT: 0000000000001008 g O .text 0000000000000000 bar
!ELF
FileHeader:
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .bss
Type: SHT_NOBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000000010
Size: 64
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000010
Content: "00000000"
Symbols:
- Name: lfoo
Type: STT_FUNC
Section: .text
Value: 0x1004
- Name: lbar
Type: STT_OBJECT
Section: .text
Value: 0x1008
- Name: foo
Type: STT_FUNC
Section: .text
Value: 0x1004
Binding: STB_GLOBAL
- Name: bar
Type: STT_OBJECT
Section: .text
Value: 0x1008
Binding: STB_GLOBAL