The objdump command is a gcc tool used to view the composition of object files or executable object files.
Options
--archive-headers
-a
displays the member information of the archive, similar to ls -l will list the information of lib*.a.
-b bfdname
--target=bfdname
specifies the target code format. This is not necessary, objdump can automatically recognize many formats, such as:
objdump -b oasys -m vax -h fu.o
Display the header summary information of fu.o, clearly indicating that the file is generated by the Oasys compiler under the Vax system Target file. objdump -i will give a list of object code formats that can be specified here.
-C
--demangle Decodes
underlying symbolic names into user-level names, in addition to stripping leading underscores, also causes C++ function names to be displayed in an understandable way.
--debugging
-g
Display debugging information. Attempts to parse the debug information stored in the file and display it in C language syntax. Only certain types of debug information are supported. Some other formats are supported by readelf -w.
-e
--debugging-tags
Similar to the -g option, but the generated information is in a format compatible with the ctags tool.
--disassemble
-d
Disassembles sections of machine code for those specific instructions from objfile.
-D
--disassemble-all
Like -d, but disassembles all sections.
--prefix-addresses
When disassembling, display the full address of each line. This is an older disassembly format.
-EB
-EL
--endian={big|little}
specifies the little endian of the object file. This item will affect the disassembled instructions. Used when the disassembled file does not describe little endian information. For example, S-records.
-f
--file-headers
displays the overall header summary information for each file in objfile.
-h
--section-headers
--headers
Display header summary information for each section of the object file.
-H
--help
Short help message.
-i
--info
Display a list of architectures and target formats available for the -b or -m options.
-j name
--section=name
only display information about the section named name
-l
--line-numbers
Label the corresponding object code with file name and line number, only used with -d, -D or -r - The difference between ld and using -d is not very big. It is useful when debugging at the source level. It is required to use debugging and compilation options such as -g when compiling.
-m machine
--architecture=machine
Specifies the architecture to use when disassembling object files. This option is useful when the disassembled file itself does not describe architecture information (such as S-records). The architectures that can be specified here can be listed with the -i option.
--reloc
-r
Displays the file's relocation entry. If used with -d or -D, relocations are displayed in disassembled form.
--dynamic-reloc
-R
Displays the dynamic relocation entry of the file, which is only meaningful for dynamic object files, such as some shared libraries.
-s
--full-contents
Display the full content of the specified section. By default all non-empty sections will be displayed.
-S
--source
disassembles the source code as much as possible, especially when the debugging parameter -g is specified when compiling, the effect is more obvious. The -d parameter is implied. When disassembling
--show-raw-insn , display the machine code corresponding to each assembly instruction. If --prefix-addresses is not specified, this will be the default option. --no-show-raw-insn When disassembling, do not display the machine code of the assembly instructions. If --prefix-addresses is not specified, this will be the default option. --start-address=address Display data starting from the specified address, this option affects the output of the -d, -r and -s options. --stop-address=address Display data until the specified address, this affects the output of the -d, -r and -s options.
-t
--syms
Display the file's symbol table entries. Similar to the information provided by nm -s
-T
--dynamic-syms
shows the dynamic symbol table entry of the file, which is only meaningful for dynamic object files, such as some shared libraries. It displays information similar to that displayed by nm -D|--dynamic.
-V
--version
version information
--all-headers
-x
Display available header information, including symbol table, relocation entry. -x is equivalent to -a -f -h -r -t specified together.
-z
--disassemble-zeroes
General disassembly output will omit large blocks of zeros, this option causes these zero blocks to be disassembled as well.
@file options can be grouped into a file and then loaded using this @file option.
Example
First, the source code and compilation instructions on which most of the following tests are based are given. The source code is as follows:
[root@localhost test]# nl mytest.cpp void printTest () { char a; a = 'a'; } void printTest2 () { int a = 2; a += 2; }Compile the above source code as follows:
[root@localhost test]# g++ -c -g mytest.cppHere, the generated file is mytest.o, which contains debugging information for the convenience of testing. The test of the executable file shows similar results.
Check the version number of the currently used objdump:
[root@localhost test]# objdump -V GNU objdump 2.17.50.0.6-14.el5 20061020 Copyright 2005 free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty.To view the information in the archive file:
[root@localhost test]# objdump -a libmy2.a In archive libmy2.a: myfile.o: file format elf32-i386 rwxrwxrwx 0/0 2724 Nov 16 16:06 2009 myfile.o mytest.o: file format elf32-i386 rw-r--r-- 0/0 727 Jul 13 15:32 2011 mytest.oHere, libmy2.a is a static library generated by packaging multiple *.o object files using the ar command. The output of the command is similar to ar -tv, compared to the output of ar -tv as follows:
[root@localhost test]# ar -tv libmy2.a rwxrwxrwx 0/0 2724 Nov 16 16:06 2009 myfile.o rw-r--r-- 0/0 727 Jul 13 15:32 2011 mytest.o
Display a list of available schemas and target structures:
[root@localhost test]# objdump -i BFD header file version 2.17.50.0.6-14.el5 20061020 elf32-i386 (header little endian, data little endian) i386 a.out-i386-linux (header little endian, data little endian) i386 efi-app-ia32 (header little endian, data little endian) i386 elf64-x86-64 (header little endian, data little endian) i386 elf64-little (header little endian, data little endian) i386 elf64-big (header big endian, data big endian) i386 elf32-little (header little endian, data little endian) i386 elf32-big (header big endian, data big endian) i386 srec (header endianness unknown, data endianness unknown) i386 symbolsrec (header endianness unknown, data endianness unknown) i386 tekhex (header endianness unknown, data endianness unknown) i386 binary (header endianness unknown, data endianness unknown) i386 ihex (header endianness unknown, data endianness unknown) i386 trad-core (header endianness unknown, data endianness unknown) elf32-i386 a.out-i386-linux efi-app-ia32 elf64-x86-64 i386 elf32-i386 a.out-i386-linux efi-app-ia32 elf64-x86-64 elf64-little elf64-big elf32-little elf32-big srec symbolsrec i386 elf64-little elf64-big elf32-little elf32-big srec symbolsrec tekhex binary ihex trad-core i386 tekhex binary ihex ---------
这里,显示的信息是相对于 -b 或者 -m 选项可用的架构和目标格式列表。 显示mytest.o文件中的text段的内容:
[root@localhost test]# objdump --section=.text -s mytest.o mytest.o: file format elf32-i386 Contents of section .text: 0000 5589e583 ec10c645 ff61c9c3 5589e583 U......E.a..U... 0010 ec10c745 fc020000 008345fc 02c9c3 ...E......E....Note here that -j or --section cannot be used alone, for example objdump --section=.text mytest.o will not run successfully.
Disassemble the content of the text section in mytest.o and represent it in source code form as much as possible:
[root@localhost test]# objdump -j .text -S mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000 <_Z9printTestv>: void printTest () 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 10 sub $0x10,%esp { char a; a = 'a'; 6: c6 45 ff 61 movb $0x61,0xffffffff(%ebp) } a: c9 leave b: c3 ret 000000c <_Z10printTest2v>: void printTest2 () c: 55 push %ebp d: 89 e5 mov %esp,%ebp f: 83 ec 10 sub $0x10,%esp { int a = 2; 12: c7 45 fc 02 00 00 00 movl $0x2,0xfffffffc(%ebp) a+=2; 19: 83 45 fc 02 addl $0x2,0xfffffffc(%ebp) } 1d: c9 leave 1st: c3 retNote here that -j or --section cannot be used alone, for example objdump -j .text mytest.o will not run successfully. In addition, the -S command has a better display effect for the target file containing debugging information. If the -g option of g++ is not specified during compilation, then the target file does not contain debugging information, so the display effect is much worse.
Disassemble the source code of mytest.o:
[root@localhost test]# objdump -S mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000 <_Z9printTestv>: void printTest () 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 10 sub $0x10,%esp { char a; a = 'a'; 6: c6 45 ff 61 movb $0x61,0xffffffff(%ebp) } a: c9 leave b: c3 ret 0000000c <_Z10printTest2v>: void printTest2 () c: 55 push %ebp d: 89 e5 mov %esp,%ebp f: 83 ec 10 sub $0x10,%esp { int a = 2; 12: c7 45 fc 02 00 00 00 movl $0x2,0xfffffffc(%ebp) a+=2; 19: 83 45 fc 02 addl $0x2,0xfffffffc(%ebp) } 1d: c9 leave 1st: c3 retHere, especially when the debugging parameter -g is specified when compiling, the effect of disassembly is more obvious. The -d parameter is implied.
Display the file's symbol table entry:
[root@localhost test]# objdump -t mytest.o mytest.o: file format elf32-i386 SYMBOL TABLE: 00000000 l df *ABS* 00000000 mytest.cpp 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_frame 00000000 .debug_frame 00000000 l d .debug_loc 00000000 .debug_loc 00000000 l d .debug_pubnames 00000000 .debug_pubnames 00000000 l d .debug_aranges 00000000 .debug_aranges 00000000 l d .note.GNU-stack 00000000 .note.GNU-stack 00000000 ld .comment 00000000 .comment 00000000 g F .text 0000000c _Z9printTestv 00000000 *AND* 00000000 __gxx_personality_v0 0000000c g F .text 00000013 _Z10printTest2vHere, the output information is similar to the output of the nm -s command. In comparison, the output of the nm command is as follows:
[root@localhost test]# nm -s mytest.o 0000000c T _Z10printTest2v 00000000 T _Z9printTestv U __gxx_personality_v0Display the file's symbol table entry, decode and represent the underlying symbols as user-level:
[root@localhost test]# objdump -t -C mytest.o mytest.o: file format elf32-i386 SYMBOL TABLE: 00000000 l df *ABS* 00000000 mytest.cpp 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_frame 00000000 .debug_frame 00000000 l d .debug_loc 00000000 .debug_loc 00000000 l d .debug_pubnames 00000000 .debug_pubnames 00000000 l d .debug_aranges 00000000 .debug_aranges 00000000 l d .note.GNU-stack 00000000 .note.GNU-stack 00000000 ld .comment 00000000 .comment 00000000 g F .text 0000000c printTest() 00000000 *AND* 00000000 __gxx_personality_v0 0000000c g F .text 00000013 printTest2()Here, the readability of the printTest2 function is increased compared to no -C.
Disassemble a specific machine code segment of an object file:
[root@localhost test]# objdump -d mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000 <_Z9printTestv>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 10 sub $0x10,%esp 6: c6 45 ff 61 movb $0x61,0xffffffff(%ebp) a: c9 leave b: c3 ret 0000000c <_Z10printTest2v>: c: 55 push %ebp d: 89 e5 mov %esp,%ebp f: 83 ec 10 sub $0x10,%esp 12: c7 45 fc 02 00 00 00 movl $0x2,0xfffffffc(%ebp) 19: 83 45 fc 02 addl $0x2,0xfffffffc(%ebp) 1d: c9 leave 1st: c3 retHere, the contents of the text segment are disassembled.
Disassemble a specific section and map the file name and line number corresponding to the assembly code:
[root@localhost test]# objdump -d -l mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000 <_Z9printTestv>: _Z9printTestv(): /root/test/04_libraryTest/mytest.cpp:1 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 10 sub $0x10,%esp /root/test/04_libraryTest/mytest.cpp:4 6: c6 45 ff 61 movb $0x61,0xffffffff(%ebp) /root/test/04_libraryTest/mytest.cpp:5 a: c9 leave b: c3 ret 0000000c <_Z10printTest2v>: _Z10printTest2v(): /root/test/04_libraryTest/mytest.cpp:6 c: 55 push %ebp d: 89 e5 mov %esp,%ebp f: 83 ec 10 sub $0x10,%esp /root/test/04_libraryTest/mytest.cpp:8 12: c7 45 fc 02 00 00 00 movl $0x2,0xfffffffc(%ebp) /root/test/04_libraryTest/mytest.cpp:9 19: 83 45 fc 02 addl $0x2,0xfffffffc(%ebp) /root/test/04_libraryTest/mytest.cpp:10 1d: c9 leave 1st: c3 retHere, the item "-d" disassembles sections of machine code for those specific instructions from the objfile, while the use of "-l" specifies to label the corresponding object code with the file name and line number, used only with -d, -D or -r , the difference between using -ld and using -d is not very big. It is useful in source-level debugging. It is required to use debugging and compilation options such as -g when compiling.
Display header summary information for each segment of the object file:
[root@localhost test]# objdump -h mytest.o mytest.o: file format elf32-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000001f 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, readonly, CODE 1 .data 00000000 00000000 00000000 00000054 2**2 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000000 00000000 00000000 00000054 2**2 ALLOC 3 .debug_abbrev 00000046 00000000 00000000 00000054 2**0 CONTENTS, READONLY, DEBUGGING 4 .debug_info 000000ed 00000000 00000000 0000009a 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 5 .debug_line 0000003e 00000000 00000000 00000187 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 6 .debug_frame 00000044 00000000 00000000 000001c8 2**2 CONTENTS, RELOC, READONLY, DEBUGGING 7 .debug_loc 00000058 00000000 00000000 0000020c 2**0 CONTENTS, READONLY, DEBUGGING 8 .debug_pubnames 0000002f 00000000 00000000 00000264 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 9 .debug_aranges 00000020 00000000 00000000 00000293 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 10 .comment 0000002e 00000000 00000000 000002b3 2**0 CONTENTS, READONLY 11 .note.GNU-stack 00000000 00000000 00000000 000002e1 2**0 CONTENTS, READONLY
转载于:http://man.linuxde.net/objdump