objdump

objdump命令

显示目标文件的信息

选项

1
Usage: objdump <option(s)> <file(s)>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-a 
--archive-headers
显示静态库文件的头信息,包含组成静态库的目标文件

> objdump -a test.a
----------------
In archive libtest.a:

a.o: file format elf32-i386
rw-rw-r-- 500/501 812 Jun 25 22:42 2019 a.o


b.o: file format elf32-i386
rw-rw-r-- 500/501 753 Jun 25 22:44 2019 b.o
-----------------
1
2
3
4
5
6
7
8
9
10
11
-f
--file-headers
文件头,描述整个文件的文件属性,包括是否可执行、是否重定向、是静态链接还是动态链接以及入口地址(如果是可执行文件)、目标硬件、目标操作系统等信息

> objdump -f test.o
------------------
test.o: file format elf32-i386
architecture: i386, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000
------------------
1
2
3
-p
--private-headers
显示目标文件格式详细的信息,与目标文件格式相关。对于某些目标文件格式,没有额外的信息被打印。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-h
--[section-]headers
显示各个段的头部摘要信息

> objdump -h test.o
------------------
test.o: file format elf32-i386

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000027 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 0000005c 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 0000005c 2**2
ALLOC
3 .comment 0000002e 00000000 00000000 0000005c 2**0
CONTENTS, READONLY
4 .note.GNU-stack 00000000 00000000 00000000 0000008a 2**0
CONTENTS, READONLY
-----------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-x
--all-headers
显示所有可用的头部信息,包括符号表和重定位入口

> objdump -x test.o
-----------------
test.o: file format elf32-i386
test.o
architecture: i386, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000027 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 0000005c 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 0000005c 2**2
ALLOC
3 .comment 0000002e 00000000 00000000 0000005c 2**0
CONTENTS, READONLY
4 .note.GNU-stack 00000000 00000000 00000000 0000008a 2**0
CONTENTS, READONLY
SYMBOL TABLE:
00000000 l df *ABS* 00000000 a.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .note.GNU-stack 00000000 .note.GNU-stack
00000000 l d .comment 00000000 .comment
00000000 g F .text 00000027 main
00000000 *UND* 00000000 shared
00000000 *UND* 00000000 swap


RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000015 R_386_32 shared
00000021 R_386_PC32 swap
--------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-d
--disassemble
反汇编可执行段

> objdump -d test.o
-------------------
test.o: file format elf32-i386


Disassembly of section .text:

00000000 <main>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 20 sub $0x20,%esp
9: c7 44 24 1c 64 00 00 movl $0x64,0x1c(%esp)
10: 00
11: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
18: 00
19: 8d 44 24 1c lea 0x1c(%esp),%eax
1d: 89 04 24 mov %eax,(%esp)
20: e8 fc ff ff ff call 21 <main+0x21>
25: c9 leave
26: c3 ret
------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-D
--disassemble-all
反汇编所有段

> objdump -D test.o
test.o: file format elf32-i386


Disassembly of section .text:

00000000 <main>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 20 sub $0x20,%esp
9: c7 44 24 1c 64 00 00 movl $0x64,0x1c(%esp)
10: 00
11: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
18: 00
19: 8d 44 24 1c lea 0x1c(%esp),%eax
1d: 89 04 24 mov %eax,(%esp)
20: e8 fc ff ff ff call 21 <main+0x21>
25: c9 leave
26: c3 ret

Disassembly of section .comment:

00000000 <.comment>:
0: 00 47 43 add %al,0x43(%edi)
3: 43 inc %ebx
4: 3a 20 cmp (%eax),%ah
6: 28 47 4e sub %al,0x4e(%edi)
9: 55 push %ebp
a: 29 20 sub %esp,(%eax)
c: 34 2e xor $0x2e,%al
e: 34 2e xor $0x2e,%al
10: 37 aaa
11: 20 32 and %dh,(%edx)
13: 30 31 xor %dh,(%ecx)
15: 32 30 xor (%eax),%dh
17: 33 31 xor (%ecx),%esi
19: 33 20 xor (%eax),%esp
1b: 28 52 65 sub %dl,0x65(%edx)
1e: 64 20 48 61 and %cl,%fs:0x61(%eax)
22: 74 20 je 44 <main+0x44>
24: 34 2e xor $0x2e,%al
26: 34 2e xor $0x2e,%al
28: 37 aaa
29: 2d 32 33 29 00 sub $0x293332,%eax
------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  -S
--source
同时显示汇编代码和源码,编译时指定-g选项时

> objdump -S test.o
------------------
test.o: file format elf32-i386


Disassembly of section .text:

00000000 <main>:
/* a.c */
extern int shared;

int main()
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 20 sub $0x20,%esp
int a = 100;
9: c7 44 24 1c 64 00 00 movl $0x64,0x1c(%esp)
10: 00
swap( &a, &shared );
11: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
18: 00
19: 8d 44 24 1c lea 0x1c(%esp),%eax
1d: 89 04 24 mov %eax,(%esp)
20: e8 fc ff ff ff call 21 <main+0x21>
}
25: c9 leave
26: c3 ret
------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  -s
--full-contents
显示所有段的详细内容

> objdump -s test.o
------------------
test.o: file format elf32-i386

Contents of section .text:
0000 5589e583 e4f083ec 20c74424 1c640000 U....... .D$.d..
0010 00c74424 04000000 008d4424 1c890424 ..D$......D$...$
0020 e8fcffff ffc9c3 .......
Contents of section .debug_abbrev:
0000 01110125 0e130b03 081b0e11 01120110 ...%............
0010 06000002 2e013f0c 030e3a0b 3b0b4913 ......?...:.;.I.
0020 11011201 400a0113 00000334 0003083a ....@......4...:
0030 0b3b0b49 13020a00 00042e01 3f0c030e .;.I........?...
0040 3a0b3b0b 49133c0c 00000518 00000006 :.;.I.<.........
0050 24000b0b 3e0b0308 00000734 00030e3a $...>......4...:
0060 0b3b0b49 133f0c3c 0c000000 .;.I.?.<....
Contents of section .debug_info:
0000 79000000 03000000 00000401 00000000 y...............
0010 01612e63 00390000 00000000 00270000 .a.c.9.......'..
0020 00000000 00020134 00000001 045b0000 .......4.....[..
0030 00000000 00270000 00019c5b 00000003 .....'.....[....
0040 61000106 5b000000 02741c04 012f0000 a...[....t.../..
0050 0001075b 00000001 05000006 0405696e ...[..........in
0060 74000728 00000001 025b0000 00010107 t..(.....[......
0070 28000000 01025b00 00000101 00 (.....[......
Contents of section .debug_line:
0000 31000000 02001a00 00000101 fb0e0d00 1...............
0010 01010101 00000001 00000100 612e6300 ............a.c.
0020 00000000 00050200 00000016 9183083d ...............=
0030 02020001 01 .....
Contents of section .debug_pubnames:
0000 17000000 02000000 00007d00 00002500 ..........}...%.
0010 00006d61 696e0000 000000 ..main.....
Contents of section .debug_aranges:
0000 1c000000 02000000 00000400 00000000 ................
0010 00000000 27000000 00000000 00000000 ....'...........
Contents of section .debug_str:
0000 474e5520 4320342e 342e3720 32303132 GNU C 4.4.7 2012
0010 30333133 20285265 64204861 7420342e 0313 (Red Hat 4.
0020 342e372d 32332900 73686172 65640073 4.7-23).shared.s
0030 77617000 6d61696e 002f686f 6d652f63 wap.main./home/c
0040 72756973 652f636c 616e6700 ruise/clang.
Contents of section .comment:
0000 00474343 3a202847 4e552920 342e342e .GCC: (GNU) 4.4.
0010 37203230 31323033 31332028 52656420 7 20120313 (Red
0020 48617420 342e342e 372d3233 2900 Hat 4.4.7-23).
Contents of section .debug_frame:
0000 10000000 ffffffff 0100017c 080c0404 ...........|....
0010 88010000 1c000000 00000000 00000000 ................
0020 27000000 410e0885 02420d05 63c50c04 '...A....B..c...
0030 04000000 ....
----------------
1
2
3
-g
--debugging
显示调试信息
1
2
3
-e
--debugging-tags
类似与-g选项,生成的是和ctags工具相兼容的信息
1
2
3
-G
--stabs
显示文件中任何STABS信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-t
--syms
显示符号表的内容

> objdump -t test.o
---------------------
test.o: file format elf32-i386

SYMBOL TABLE:
00000000 l df *ABS* 00000000 a.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .debug_abbrev 00000000 .debug_abbrev
00000000 l d .debug_info 00000000 .debug_info
00000000 l d .debug_line 00000000 .debug_line
00000000 l d .debug_pubnames 00000000 .debug_pubnames
00000000 l d .debug_aranges 00000000 .debug_aranges
00000000 l d .debug_str 00000000 .debug_str
00000000 l d .note.GNU-stack 00000000 .note.GNU-stack
00000000 l d .debug_frame 00000000 .debug_frame
00000000 l d .comment 00000000 .comment
00000000 g F .text 00000027 main
00000000 *UND* 00000000 shared
00000000 *UND* 00000000 swap
---------------------
1
2
3
4
5
6
7
8
9
10
11
12
-T
--dynamic-syms
显示动态符号表的内容

> objdump -T test.o
----------------------
test.o: file format elf32-i386

objdump: test.o: not a dynamic object
DYNAMIC SYMBOL TABLE:
no symbols
----------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-r
--reloc
显示重定位的入口,可以和-d, -D 配合使用

> objdump -r test.o
----------------------
test.o: file format elf32-i386

RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000015 R_386_32 shared
00000021 R_386_PC32 swap


RELOCATION RECORDS FOR [.debug_info]:
OFFSET TYPE VALUE
00000006 R_386_32 .debug_abbrev
0000000c R_386_32 .debug_str
00000015 R_386_32 .debug_str
00000019 R_386_32 .text
0000001d R_386_32 .text
00000021 R_386_32 .debug_line
00000027 R_386_32 .debug_str
00000031 R_386_32 .text
00000035 R_386_32 .text
0000004d R_386_32 .debug_str
00000063 R_386_32 .debug_str
00000070 R_386_32 .debug_str


RELOCATION RECORDS FOR [.debug_line]:
OFFSET TYPE VALUE
00000027 R_386_32 .text


RELOCATION RECORDS FOR [.debug_pubnames]:
OFFSET TYPE VALUE
00000006 R_386_32 .debug_info


RELOCATION RECORDS FOR [.debug_aranges]:
OFFSET TYPE VALUE
00000006 R_386_32 .debug_info
00000010 R_386_32 .text


RELOCATION RECORDS FOR [.debug_frame]:
OFFSET TYPE VALUE
00000018 R_386_32 .debug_frame
0000001c R_386_32 .text
----------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-R
--dynamic-reloc
显示动态重定位的入口

> objdump -R /lib/ld-2.12.so
---------------------
/lib/ld-2.12.so: file format elf32-i386

DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
0001fe08 R_386_RELATIVE *ABS*
0001fe14 R_386_RELATIVE *ABS*
0001fe18 R_386_RELATIVE *ABS*
0001fe1c R_386_RELATIVE *ABS*
0001fe20 R_386_RELATIVE *ABS*
0001fe24 R_386_RELATIVE *ABS*
0001fe28 R_386_RELATIVE *ABS*
0001fe2c R_386_RELATIVE *ABS*
0001fe30 R_386_RELATIVE *ABS*
0001fe34 R_386_RELATIVE *ABS*
0001fe38 R_386_RELATIVE *ABS*
0001ffe8 R_386_RELATIVE *ABS*
0001fff4 R_386_RELATIVE *ABS*
00020834 R_386_RELATIVE *ABS*
0001ffec R_386_GLOB_DAT __libc_enable_secure
0001fff0 R_386_GLOB_DAT _r_debug
0001fff8 R_386_GLOB_DAT free
0001ffd0 R_386_JUMP_SLOT __libc_memalign
0001ffd4 R_386_JUMP_SLOT malloc
0001ffd8 R_386_JUMP_SLOT calloc
0001ffdc R_386_JUMP_SLOT realloc
0001ffe0 R_386_JUMP_SLOT ___tls_get_addr
0001ffe4 R_386_JUMP_SLOT free
---------------------
1
2
@file
从文件中读取选项
1
2
3
4
5
6
7
8
9
10
11
12
-v
--version
显示程序的版本号

> objdump -v
--------------------
GNU objdump version 2.20.51.0.2-5.48.el6 20100205
Copyright 2009 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
---------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-i
--info
列出支持的目标格式和架构

> objdump -i
---------------------
BFD header file version version 2.20.51.0.2-5.48.el6 20100205
elf32-i386
(header little endian, data little endian)
i386
a.out-i386-linux
(header little endian, data little endian)
i386
pei-i386
(header little endian, data little endian)
i386
elf64-x86-64
(header little endian, data little endian)
i386
elf64-l1om
(header little endian, data little endian)
l1om
elf64-little
(header little endian, data little endian)
i386
l1om
elf64-big
(header big endian, data big endian)
i386
l1om
elf32-little
(header little endian, data little endian)
i386
l1om
elf32-big
(header big endian, data big endian)
i386
l1om
srec
(header endianness unknown, data endianness unknown)
i386
l1om
symbolsrec
(header endianness unknown, data endianness unknown)
i386
l1om
verilog
(header endianness unknown, data endianness unknown)
i386
l1om
tekhex
(header endianness unknown, data endianness unknown)
i386
l1om
binary
(header endianness unknown, data endianness unknown)
i386
l1om
ihex
(header endianness unknown, data endianness unknown)
i386
l1om
trad-core
(header endianness unknown, data endianness unknown)

elf32-i386 a.out-i386-linux pei-i386 elf64-x86-64 elf64-l1om
i386 elf32-i386 a.out-i386-linux pei-i386 elf64-x86-64 ----------
l1om ---------- ---------------- -------- ------------ elf64-l1om

elf64-little elf64-big elf32-little elf32-big srec symbolsrec
i386 elf64-little elf64-big elf32-little elf32-big srec symbolsrec
l1om elf64-little elf64-big elf32-little elf32-big srec symbolsrec

verilog tekhex binary ihex trad-core
i386 verilog tekhex binary ihex ---------
l1om verilog tekhex binary ihex ---------
---------------------