Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-objdump] Teach
llvm-objdump
dump dynamic symbols.
Summary: This patch is to teach `llvm-objdump` dump dynamic symbols (`-T` and `--dynamic-syms`). Currently, this patch is not fully compatible with `gnu-objdump`, but I would like to continue working on this in next few patches. It has two issues. 1. Some symbols shouldn't be marked as global(g). (`-t/--syms` has same issue as well) (Fixed by D75659) 2. `gnu-objdump` can dump version information and *dynamically* insert before symbol name field. `objdump -T a.out` gives: ``` DYNAMIC SYMBOL TABLE: 0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 printf 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __libc_start_main 0000000000000000 w D *UND* 0000000000000000 __gmon_start__ 0000000000000000 w D *UND* 0000000000000000 _ITM_registerTMCloneTable 0000000000000000 w DF *UND* 0000000000000000 GLIBC_2.2.5 __cxa_finalize ``` `llvm-objdump -T a.out` gives: ``` DYNAMIC SYMBOL TABLE: 0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable 0000000000000000 g DF *UND* 0000000000000000 printf 0000000000000000 g DF *UND* 0000000000000000 __libc_start_main 0000000000000000 w D *UND* 0000000000000000 __gmon_start__ 0000000000000000 w D *UND* 0000000000000000 _ITM_registerTMCloneTable 0000000000000000 w DF *UND* 0000000000000000 __cxa_finalize ``` Reviewers: jhenderson, grimar, MaskRay, espindola Reviewed By: jhenderson, grimar Subscribers: emaste, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75756
- Loading branch information
Showing
5 changed files
with
307 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
llvm/test/tools/llvm-objdump/X86/elf-dynamic-symbols.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
## Test that llvm-objdump can dump dynamic symbols. | ||
# RUN: yaml2obj --docnum=1 %s -o %t1 | ||
# RUN: llvm-objdump --dynamic-syms %t1 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=DYNSYM | ||
# RUN: llvm-objdump -T %t1 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=DYNSYM | ||
|
||
# DYNSYM:DYNAMIC SYMBOL TABLE: | ||
# DYNSYM-NEXT:0000000000000000 l DO .data 0000000000000000 localsym | ||
# DYNSYM-NEXT:0000000000000000 g DO .data 0000000000000000 globalsym | ||
# DYNSYM-NEXT:0000000000000000 u DO .data 0000000000000000 uniqueglobalsym | ||
# DYNSYM-NEXT:0000000000000000 w DO .data 0000000000000000 weaksym | ||
# DYNSYM-NEXT:0000000000000000 g Df .data 0000000000000000 filesym | ||
# DYNSYM-NEXT:0000000000000000 g DF .data 0000000000000000 funcsym | ||
# DYNSYM-EMPTY: | ||
|
||
--- !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: localsym | ||
Type: STT_OBJECT | ||
Section: .data | ||
Binding: STB_LOCAL | ||
- Name: globalsym | ||
Type: STT_OBJECT | ||
Section: .data | ||
Binding: STB_GLOBAL | ||
- Name: uniqueglobalsym | ||
Type: STT_OBJECT | ||
Section: .data | ||
Binding: STB_GNU_UNIQUE | ||
- Name: weaksym | ||
Type: STT_OBJECT | ||
Section: .data | ||
Binding: STB_WEAK | ||
- Name: filesym | ||
Type: STT_FILE | ||
Section: .data | ||
Binding: STB_GLOBAL | ||
- Name: funcsym | ||
Type: STT_FUNC | ||
Section: .data | ||
Binding: STB_GLOBAL | ||
|
||
## Test dumping ELF files with no .dynsym section. | ||
# RUN: yaml2obj --docnum=2 %s -o %t2 | ||
# RUN: llvm-objdump --dynamic-syms %t2 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=NODYNSYM | ||
# RUN: llvm-objdump -T %t2 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=NODYNSYM | ||
|
||
# NODYNSYM:DYNAMIC SYMBOL TABLE: | ||
# NODYNSYM-EMPTY: | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_DYN | ||
Machine: EM_X86_64 | ||
|
||
## Test dumping ELF files with logically empty .dynsym section (only has a 0-index NULL symbol). | ||
# RUN: yaml2obj --docnum=3 %s -o %t3 | ||
# RUN: llvm-objdump --dynamic-syms %t3 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=ONLY-NULL | ||
# RUN: llvm-objdump -T %t3 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=ONLY-NULL | ||
|
||
# ONLY-NULL:DYNAMIC SYMBOL TABLE: | ||
# ONLY-NULL-EMPTY: | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_DYN | ||
Machine: EM_X86_64 | ||
DynamicSymbols: [] | ||
|
||
## Test dumping ELF files with truly empty .dynsym section (size of .dynsym section is 0). | ||
# RUN: yaml2obj --docnum=4 %s -o %t4 | ||
# RUN: llvm-objdump --dynamic-syms %t4 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=EMPTY | ||
# RUN: llvm-objdump -T %t4 | \ | ||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=EMPTY | ||
|
||
# EMPTY:DYNAMIC SYMBOL TABLE: | ||
# EMPTY-EMPTY: | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_DYN | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .dynsym | ||
Type: SHT_DYNSYM | ||
Size: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Test dumping dynamic symbols reports a warning if the operation is unsupported for the file format. | ||
# RUN: yaml2obj %s --docnum=1 -o %t.macho.o | ||
# RUN: llvm-objdump --dynamic-syms %t.macho.o 2>&1 | \ | ||
# RUN: FileCheck %s -DFILE=%t.macho.o | ||
# RUN: yaml2obj %s --docnum=2 -o %t.coff.o | ||
# RUN: llvm-objdump --dynamic-syms %t.coff.o 2>&1 | \ | ||
# RUN: FileCheck %s -DFILE=%t.coff.o | ||
# RUN: llvm-objdump --dynamic-syms %p/XCOFF/Inputs/xcoff-section-headers.o 2>&1 | \ | ||
# RUN: FileCheck %s -DFILE=%p/XCOFF/Inputs/xcoff-section-headers.o | ||
|
||
# CHECK:DYNAMIC SYMBOL TABLE: | ||
# CHECK-NEXT:{{.*}}llvm-objdump: warning: '[[FILE]]': this operation is not currently supported for this file format | ||
# CHECK-EMPTY: | ||
|
||
--- !mach-o | ||
FileHeader: | ||
magic: 0xFEEDFACF | ||
cputype: 0x01000007 | ||
cpusubtype: 0x80000003 | ||
filetype: 0x00000002 | ||
ncmds: 0 | ||
sizeofcmds: 0 | ||
flags: 0x00218085 | ||
reserved: 0x00000000 | ||
|
||
--- !COFF | ||
header: | ||
Machine: IMAGE_FILE_MACHINE_AMD64 | ||
Characteristics: [] | ||
sections: [] | ||
symbols: [] |
Oops, something went wrong.