objdump – Display Binary File Information

The objdump command is used to display information about one or more object files, executable files, shared libraries, and core files. This command is a part of the GNU Binutils package and is available on most Linux distributions.

Overview

The basic syntax for the objdump command is as follows:

objdump [options] file

Where file is the name of the object file, executable file, shared library, or core file that you want to analyze.

The objdump command provides a wide range of options that allow you to control the output format and the level of detail that is displayed. The most commonly used options are:

  • -d – Disassemble the contents of the file and display it in assembly language format.
  • -t – Display the symbol table of the file.
  • -x – Display all header information in hexadecimal and ASCII format.
  • -S – Display the source code intermixed with the disassembly.
  • -r – Display the relocation entries of the file.
  • -G – Display the debugging information in the file.
  • -g – Display the debugging information in the file, including line numbers and filenames.
  • -l – Display the line number information in the file.
  • -R – Display the dynamic relocation entries of the file.
  • -p – Display the sections of the file in their raw form.
  • -s – Display the contents of the sections of the file.

Here are some examples of how to use the objdump command:

objdump -d /bin/ls

This command will disassemble the contents of the /bin/ls executable file and display it in assembly language format.

objdump -t /usr/lib/libc.so.6

This command will display the symbol table of the /usr/lib/libc.so.6 shared library.

objdump -x -S /usr/bin/gcc

This command will display all header information in hexadecimal and ASCII format, as well as the source code intermixed with the disassembly, for the /usr/bin/gcc executable file.

Options

Here is a list of the available options for the objdump command:

Option Description
-a Display the archive header of the file.
-b <bfdname> Specify the binary file format.
-C Demangle C++ symbol names.
-d Disassemble the contents of the file.
-D Use the debug information in the file.
-EB Force big-endian byte order.
-EL Force little-endian byte order.
-f Display the file header of the file.
-g Display the debugging information in the file.
-G Display the debugging information in the file.
-h Display the section headers of the file.
-i Display the contents of the file’s notes section.
-I Use the specified directory as the include directory.
-j <section> Display the specified section.
-l Display the line number information in the file.
-m <machine> Specify the target architecture.
-M <option> Pass an option to the disassembler.
-n Display the contents of the file’s note section.
-p Display the sections of the file in their raw form.
-r Display the relocation entries of the file.
-R Display the dynamic relocation entries of the file.
-s Display the contents of the sections of the file.
-S Display the source code intermixed with the disassembly.
-t Display the symbol table of the file.
-T Display the dynamic symbol table of the file.
-V Display the version information of the objdump command.
-x Display all header information in hexadecimal and ASCII format.
-z Display the compressed section headers of the file.

Troubleshooting Tips

One common issue when using the objdump command is figuring out which options to use in order to get the desired output. The best way to approach this is to read the documentation carefully and experiment with different options until you get the output that you need.

Another issue that can arise is related to the format of the file that you are trying to analyze. If the file is not in a format that objdump can handle, you may get an error message. In this case, you may need to convert the file to a different format or use a different tool to analyze it.

Notes

The objdump command is a powerful tool for analyzing binary files and can be used for a wide range of tasks, including debugging, reverse engineering, and performance optimization. However, it is important to use it with caution, as incorrect use of this tool can lead to unintended consequences. Always make sure that you have a backup of your files before using objdump or any other command that modifies or analyzes them.