objdump

Show binary file information

Supplementary instructions

objdump command is a gcc tool used to view the composition of an object file or an executable object file.

Options

-a --archive-headers
# Display the member information of the archive, similar to ls -l which lists the information of lib*.a.

-b bfdname --target=bfdname
# Specify the object 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 and clearly indicate that the file is an object file generated by the Oasys compiler under the Vax system. objdump -i will give a list of object code formats that can be specified here.

-C --demangle
# Decode the underlying symbol name into a user-level name. In addition to removing the leading underscore, it also allows the C++ function name to be displayed in an understandable manner.
--debugging
-g
# Display debugging information. Attempts to parse the debugging information saved in the file and display it in C language syntax. Only certain types of debugging 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
# Disassemble the sections of machine code for specific instructions from objfile.

-D --disassemble-all
# Similar to -d, but disassembles all sections.

--prefix-addresses
# When disassembling, display the complete address of each line. This is an older disassembly format.

-EB
-EL
--endian={big|little}
#Specify the little endian of the target file. This option 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 the header summary information of each section of the target file.

-H
--help
A short help message.

-i
--info
Displays a list of architecture and target formats available for the -b or -m option.

-j name
--section=name
Only display information about the section with the specified name name

-l
--line-numbers
Mark the corresponding target code with the file name and line number. It is only used with -d, -D or -r. The difference between using -ld and using -d is not very big. It is useful when debugging at the source code level. It is required to use - during compilation. Debug compilation options like g.

-m machine
--architecture=machine
Specify the architecture used when disassembling the target file. This option is useful when the file to be disassembled itself does not describe the architecture information (such as S-records). The architectures that can be specified here can be listed with the -i option.

--reloc
-r
Display the relocation entry of the file. If used with -d or -D, the relocation portion is displayed in disassembled format.

--dynamic-reloc
-R
Displaying the dynamic relocation entry of the file is only meaningful for dynamic target files, such as some shared libraries.

-s
--full-contents
Display the complete contents of the specified section. By default, all non-empty sections will be displayed.

-S
--source
Disassemble 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.

--show-raw-insn
When disassembling, 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 at the specified address. This option affects the output of the -d, -r, and -s options.

--stop-address=address
Displays data up to the specified address. This affects the output of the -d, -r, and -s options.

-t
--syms
Displays the file's symbol table entry. Similar to the information provided by nm -s

-T
--dynamic-syms
Displaying the file's dynamic symbol table entry is only meaningful for dynamic target files, such as some shared libraries. It displays information similar to that displayed by nm -D|--dynamic.

-V
--version
Version Information 

--all-headers
-x
Displays available header information, including symbol tables and relocation entries. -x is equivalent to -a -f -h -r -t specified simultaneously.

-z 
--disassemble-zeroes
Normally the disassembly output will omit large chunks of zeros, this option causes these chunks of zeros to be disassembled as well.

@file You can collect options into a file and then load it using this @file option.

Example

First, the source code and compilation instructions on which most of the subsequent 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.cpp

Here, the generated file is mytest.o, which contains debugging information for the convenience of testing. When testing executable files, the displayed results are similar. ​

**Check the version number of objdump currently used: **

[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.

**View information in archive files: **

[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.o

**Here, libmy2.a is a static library generated by packaging multiple *.o target files using the ar command. The output of the command is similar to ar -tv. Compared with ar -tv, the output is 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 architectures 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 ---------

Here, the information displayed is relative to the list of architectures and target formats available with the -b or -m option. ​

**Display the contents of the text segment in the mytest.o file: **

[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 it cannot be used alone -j or --section, for example objdump --section=.text mytest.o will not run successfully. ​

**Disassemble the text segment content in mytest.o and express 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
   1e: c3 ret

Note 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 target files that contain debugging information. If the -g option of g++ is not specified when compiling, then the target file does not contain debugging information, and the display effect will be 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
   1e: c3 ret

Here, especially when the debugging parameter -g is specified during compilation, the disassembly effect is more obvious. The -d parameter is implied. ​

**Display the symbol table entry of the file: **

[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 l d .comment 00000000 .comment
00000000 g F .text 0000000c _Z9printTestv
00000000 *UND* 00000000 __gxx_personality_v0
0000000c g F .text 00000013 _Z10printTest2v

Here, 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_v0

**Display the symbol table entry of the file, decode and represent the underlying symbols to 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 l d .comment 00000000 .comment
00000000 g F .text 0000000c printTest()
00000000 *UND* 00000000 __gxx_personality_v0
0000000c g F .text 00000013 printTest2()

Here, the printTest2 function is more readable than without -C. ​

**Disassemble specific machine code segments of the target 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
   1e: c3 ret

Here, the contents of the text segment are disassembled. ​

**Disassemble a specific segment and match 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  
  1e:   c3                      ret    

Here, the option "-d" disassembles the machine code section of the specific instruction from the objfile, and "-l" specifies that the corresponding object code is marked with the file name and line number. Use only with -d, -D or -r. , the difference between using -ld and using -d is not very big. It is useful when debugging at the source code level. It requires debugging and compilation options such as -g to be used during compilation. ​

**Display the header summary information of each segment of the target 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 

Here, see this option in man objdump for more information.