Display information from binary files.
The objdump command is a GNU tool used to display various information about object files or executable files.
-a, --archive-headers
# Display archive header information, similar to ls -l for members of lib*.a.
-b bfdname, --target=bfdname
# Specify the object code format. This is usually not necessary as objdump can automatically recognize many formats, such as:
objdump -b oasys -m vax -h fu.o
# Display header summary information for fu.o, explicitly stating it is an object file generated by the Oasys compiler on a Vax system. objdump -i provides a list of target formats that can be specified.
-C, --demangle
# Decode low-level symbol names into user-level names. Besides removing leading underscores, it makes C++ function names readable.
-g, --debugging
# Display debugging information. Attempts to parse debugging information stored in the file and display it using C-like syntax. Only certain types of debugging information are supported. Other formats are supported by readelf -w.
-e, --debugging-tags
# Similar to -g, but the generated information is in a format compatible with the ctags tool.
-d, --disassemble
# Disassemble the executable sections from the object file.
-D, --disassemble-all
# Similar to -d, but disassembles all sections.
--prefix-addresses
# When disassembling, display the complete address on each line. This is an older disassembly format.
-EB, -EL, --endian={big|little}
# Specify the endianness of the object file. This affects the disassembled instructions. Useful when the file doesn't describe endianness (e.g., S-records).
-f, --file-headers
# Display the overall header summary for each file in the object file.
-h, --section-headers, --headers
# Display the header summary information for each section of the object file.
-H, --help
# Display brief help information.
-i, --info
# Display a list of architectures and object formats available for the -b or -m options.
-j name, --section=name
# Only display information for the section named 'name'.
-l, --line-numbers
# Label the object code with filename and line numbers. Only used with -d, -D, or -r. Requires the file to be compiled with debugging options like -g.
-m machine, --architecture=machine
# Specify the architecture to use when disassembling. Useful when the object file doesn't describe the architecture (e.g., S-records). Available architectures can be listed with -i.
-r, --reloc
# Display the relocation entries of the file. If used with -d or -D, relocations are shown in the disassembly.
-R, --dynamic-reloc
# Display the dynamic relocation entries of the file. Only meaningful for dynamic object files, such as shared libraries.
-s, --full-contents
# Display the full contents of any sections requested. By default, all non-empty sections are displayed.
-S, --source
# Disassemble source code if possible. This is most effective when the file was compiled with debugging parameters like -g. Implies -d.
--show-raw-insn
# When disassembling, display the machine code (hex) for each instruction. This is the default unless --prefix-addresses is specified.
--no-show-raw-insn
# When disassembling, do not display the machine code for instructions.
--start-address=address
# Start displaying data at the specified address. Affects -d, -r, and -s.
--stop-address=address
# Stop displaying data at the specified address. Affects -d, -r, and -s.
-t, --syms
# Display the symbol table entries of the file. Similar to the information provided by nm -s.
-T, --dynamic-syms
# Display the dynamic symbol table entries. Only meaningful for dynamic object files. Similar to nm -D.
-V, --version
# Display version information.
-x, --all-headers
# Display all available header information, including symbol tables and relocation entries. -x is equivalent to specifying -a -f -h -r -t.
-z, --disassemble-zeroes
# Normally, disassembly skips large blocks of zeros. This option forces them to be disassembled.
@file
# Read options from the specified file.
First, here is the source code and compilation command used for the following tests.
void printTest() {
char a;
a = 'a';
}
void printTest2() {
int a = 2;
a += 2;
}
Compile the source code:
g++ -c -g mytest.cpp
This generates mytest.o. It includes debugging information for testing purposes.
View the version of objdump:
objdump -V
View information in an archive file:
objdump -a libmy2.a
Note: libmy2.a is a static library created using the ar command. The output is similar to ar -tv.
List available architectures and targets:
objdump -i
Display the contents of the .text section in mytest.o:
objdump --section=.text -s mytest.o
Note: You cannot use -j or --section alone; you must specify an action like -s or -d.
Disassemble the .text section and show source code:
objdump -j .text -S mytest.o
Display the symbol table:
objdump -t mytest.o
Display the symbol table with demangled names:
objdump -t -C mytest.o
Disassemble the object file:
objdump -d mytest.o
Disassemble with line numbers:
objdump -d -l mytest.o
Display section headers:
objdump -h mytest.o