在其他文章里,这三个指令用了好多次了,但是没有真正总结他们的用法,现在来讲解一下。
参看:readelf命令
参看:objdump命令
参看:nm命令
常用选项:
(1)使用 readelf 显示一个或者多个elf格式的目标文件的信息
readelf -h add.o (-h 显示elf文件开始的文件头信息)
# readelf -h add.o
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 252 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 11
Section header string table index: 8
(2)使用 objdump 查看目标文件或者可执行的目标文件
objdump -d add.o (-d 从objfile中反汇编那些特定指令机器码的section。 )
# objdump -d add.o
add.o: file format elf32-i386
Disassembly of section .text:
00000000 <add_int>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 45 0c mov 0xc(%ebp),%eax
6: 8b 55 08 mov 0x8(%ebp),%edx
9: 01 d0 add %edx,%eax
b: 5d pop %ebp
c: c3 ret
(3)使用 nm 显示二进制目标文件的符号表,包括符号地址、符号类型、符号名等
nm add.o
# nm add.o
00000000 T add_int