objdump command
objdump (Object Dump)
Purpose
The objdump command in Linux displays detailed information about object files and executables.
It allows you to inspect:
-
Machine code (assembly) generated by the compiler
-
Headers and sections of binary files
-
Symbol tables and debugging information
It’s extremely useful for learning:
-
What happens after compilation
-
How the assembler and linker organize executables
-
How to read assembly code and understand binary structure
Basic Syntax
Example:
🧠 What It Works On
-
.ofiles (object files produced by the compiler before linking) -
Executables (like
a.outor your compiled programs) -
Static libraries (
.a) -
Dynamic libraries (
.so)
1. Disassemble an Executable
This shows the assembly code generated from your C source after compilation.
Example Output:
🧩 Explanation:
-
The section
.textcontains the program’s machine instructions. -
Each line shows:
-
Address in memory
-
Hex code (machine code)
-
Assembly instruction
-
This helps students visualize how C code is translated into assembly.
2. Display All Headers
Shows all header information, including:
-
ELF file type
-
Entry point address
-
Program headers
-
Section headers
-
Linked libraries
This output helps understand how executables are structured.
3. Display Section Headers
Example Output:
🧩 Explanation:
-
.text→ executable code -
.data→ initialized global/static data -
.bss→ uninitialized data -
.comment→ compiler information
This gives students insight into how memory is divided in a program’s binary.
4. Display Symbol Table
Lists functions and global variables known to the program.
Example Output:
🧩 Explanation:
-
F = function
-
O = object (variable)
-
.text, .data → section names where they are located
-
Address shows where each symbol is stored in memory
5. Show Only the Assembly of a Specific Function
This restricts disassembly output to the main function — useful for classroom demos.
6. Show Source Code Along with Assembly (if compiled with -g)
This displays C source code interleaved with assembly, which is excellent for teaching how high-level code maps to machine instructions.
Example:
7. Show File Format
Displays:
-
File format (ELF, PE, etc.)
-
Architecture (x86-64, ARM, etc.)
-
Entry point address
Example Output:
Commonly Used Options Summary
| Option | Description |
|---|---|
-d | Disassemble executable code |
-S | Show source code along with assembly |
-t | Show symbol table |
-h | Show section headers |
-x | Show all headers |
-f | Show file format info |
--disassemble=function | Disassemble only a given function |
Simple Lab Exercise
Aim:
To study the use of objdump command for analyzing executable files.
Procedure:
-
Write and compile a simple program:
-
Compile with debug symbols:
-
Use these commands and observe the outputs:
-
Note the section names, symbol addresses, and assembly instructions.
Learning Outcomes
Students will:
-
Understand how a C program is translated into machine code.
-
Learn how executables are organized internally (sections, headers, symbols).
-
Connect the compilation and execution process with OS concepts like memory layout and process loading.
Comments
Post a Comment