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

objdump [options] filename

Example:

objdump -d a.out

🧠 What It Works On

  • .o files (object files produced by the compiler before linking)

  • Executables (like a.out or your compiled programs)

  • Static libraries (.a)

  • Dynamic libraries (.so)


1. Disassemble an Executable

objdump -d a.out

This shows the assembly code generated from your C source after compilation.

Example Output:

a.out: file format elf64-x86-64 Disassembly of section .text: 0000000000001139 <main>: 1139: 55 push %rbp 113a: 48 89 e5 mov %rsp,%rbp 113d: b8 00 00 00 00 mov $0x0,%eax 1142: 5d pop %rbp 1143: c3 ret

🧩 Explanation:

  • The section .text contains 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

objdump -x a.out

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

objdump -h a.out

Example Output:

Idx Name Size VMA LMA File off Algn 0 .text 0000013a 0000000000401139 0000000000401139 00001139 2**2 1 .data 00000010 0000000000601040 0000000000601040 00001040 2**3 2 .bss 00000008 0000000000601050 0000000000601050 00001050 2**3 3 .comment 0000002a 0000000000000000 0000000000000000 00001058 2**0

🧩 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

objdump -t a.out

Lists functions and global variables known to the program.

Example Output:

SYMBOL TABLE: 0000000000401139 l df *ABS* 0000000000000000 main.c 0000000000401139 g F .text 0000000000000013 main 0000000000601040 g O .data 0000000000000004 global_var

🧩 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

objdump -d --disassemble=main a.out

This restricts disassembly output to the main function — useful for classroom demos.


6. Show Source Code Along with Assembly (if compiled with -g)

objdump -S a.out

This displays C source code interleaved with assembly, which is excellent for teaching how high-level code maps to machine instructions.

Example:

int main() { => 1139: 55 push %rbp 113a: 48 89 e5 mov %rsp,%rbp printf("Hello"); => 113d: b8 00 00 00 00 mov $0x0,%eax }

7. Show File Format

objdump -f a.out

Displays:

  • File format (ELF, PE, etc.)

  • Architecture (x86-64, ARM, etc.)

  • Entry point address

Example Output:

a.out: file format elf64-x86-64 architecture: i386:x86-64, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x0000000000401139

Commonly Used Options Summary

OptionDescription
-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:

  1. Write and compile a simple program:

    #include <stdio.h> int main() { printf("Operating Systems Lab\n"); return 0; }
  2. Compile with debug symbols:

    gcc -g hello.c -o hello
  3. Use these commands and observe the outputs:

    objdump -f hello objdump -h hello objdump -t hello objdump -S hello
  4. 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

Popular posts from this blog

Operating Systems OS Lab PCCSL407 Semester 4 KTU BTech CS 2024 Scheme - Dr Binu V P

Exploring the /proc file system

ps command