Linux Objdump Command Examples (Disassemble A Binary File) : Home Free Ebook Start Here Contact About
Linux Objdump Command Examples (Disassemble A Binary File) : Home Free Ebook Start Here Contact About
≡ Menu
Home
Free eBook
Start Here
Contact
About
Objdump command in Linux is used to provide thorough information on object files. This
command is mainly used by the programmers who work on compilers, but still its a very
handy tool for normal programmers also when it comes to debugging. In this article, we
will understand how to use objdump command through some examples.
There is a wide range of options available for this command. We will try to cover a good
amount of them in this tutorial.
Examples
The ELF binary file of the following C program is used in all the examples mentioned in
this article.
#include<stdio.h>
int main(void)
{
int n = 6;
1 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
float f=1;
int i = 1;
for(;i<=n;i++)
f=f*i;
printf("\n Factorial is : [%f]\n",f);
return 0;
}
Note: The above is just a test code that was being used for some other purpose, but I
found it simple enough to use for this article.
$ objdump -f factorial
So we see that the information related to the overall file header was shown in the
output.
NOTE: The executable format used in the examples is ELF. To know more about it, refer
to our article on ELF file format.
The following example prints the object file format specific information.
$ objdump -p factorial
Program Header:
PHDR off 0x0000000000000040 vaddr 0x0000000000400040 paddr 0x0000000000400040 align 2**3
filesz 0x00000000000001f8 memsz 0x00000000000001f8 flags r-x
INTERP off 0x0000000000000238 vaddr 0x0000000000400238 paddr 0x0000000000400238 align 2**0
2 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
There can be various sections in an object file. Information related to them can be
printed using -h option.
The following examples shows various sections. As you see there are total of 26 (only
partial output is shown here).
$ objdump -h factorial
Sections:
Idx Name Size VMA LMA File off Algn
0 .interp 0000001c 0000000000400238 0000000000400238 00000238 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.ABI-tag 00000020 0000000000400254 0000000000400254 00000254 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.gnu.build-id 00000024 0000000000400274 0000000000400274 00000274 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .hash 00000024 0000000000400298 0000000000400298 00000298 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
....
14 .fini 0000000e 0000000000400668 0000000000400668 00000668 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
15 .rodata 0000001b 0000000000400678 0000000000400678 00000678 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .eh_frame_hdr 00000024 0000000000400694 0000000000400694 00000694 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
17 .eh_frame 0000007c 00000000004006b8 00000000004006b8 000006b8 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
18 .ctors 00000010 0000000000600e18 0000000000600e18 00000e18 2**3
CONTENTS, ALLOC, LOAD, DATA
3 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
So we see that the information related to all the section headers was printed in the
output. In the output above, Size is the size of the loaded section, VMA represents the
virtual memory address, LMA represents the logical memory address, File off is this
section’s offset from the beginning of the file, Algn represents alignment, CONTENTS,
ALLOC, LOAD, READONLY, DATA are flags that represent that a particular section is to
be LOADED or is READONLY etc.
Information related to all the headers in the object file can be retrieved using the -x
option.
The following example displays all the sections (only partial output is shown here):
$ objdump -x factorial
Program Header:
PHDR off 0x0000000000000040 vaddr 0x0000000000400040 paddr 0x0000000000400040 align 2**3
filesz 0x00000000000001f8 memsz 0x00000000000001f8 flags r-x
INTERP off 0x0000000000000238 vaddr 0x0000000000400238 paddr 0x0000000000400238 align 2**0
filesz 0x000000000000001c memsz 0x000000000000001c flags r--
.....
EH_FRAME off 0x0000000000000694 vaddr 0x0000000000400694 paddr 0x0000000000400694 align 2**2
filesz 0x0000000000000024 memsz 0x0000000000000024 flags r--
STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**3
filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
RELRO off 0x0000000000000e18 vaddr 0x0000000000600e18 paddr 0x0000000000600e18 align 2**0
filesz 0x00000000000001e8 memsz 0x00000000000001e8 flags r--
Dynamic Section:
NEEDED libc.so.6
INIT 0x00000000004003f0
FINI 0x0000000000400668
HASH 0x0000000000400298
GNU_HASH 0x00000000004002c0
STRTAB 0x0000000000400340
SYMTAB 0x00000000004002e0
STRSZ 0x000000000000003f
....
4 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
Version References:
required from libc.so.6:
0x09691a75 0x00 02 GLIBC_2.2.5
Sections:
Idx Name Size VMA LMA File off Algn
0 .interp 0000001c 0000000000400238 0000000000400238 00000238 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.ABI-tag 00000020 0000000000400254 0000000000400254 00000254 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.gnu.build-id 00000024 0000000000400274 0000000000400274 00000274 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .hash 00000024 0000000000400298 0000000000400298 00000298 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .gnu.hash 0000001c 00000000004002c0 00000000004002c0 000002c0 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
.....
18 .ctors 00000010 0000000000600e18 0000000000600e18 00000e18 2**3
CONTENTS, ALLOC, LOAD, DATA
19 .dtors 00000010 0000000000600e28 0000000000600e28 00000e28 2**3
CONTENTS, ALLOC, LOAD, DATA
20 .jcr 00000008 0000000000600e38 0000000000600e38 00000e38 2**3
CONTENTS, ALLOC, LOAD, DATA
21 .dynamic 000001a0 0000000000600e40 0000000000600e40 00000e40 2**3
CONTENTS, ALLOC, LOAD, DATA
22 .got 00000008 0000000000600fe0 0000000000600fe0 00000fe0 2**3
CONTENTS, ALLOC, LOAD, DATA
23 .got.plt 00000028 0000000000600fe8 0000000000600fe8 00000fe8 2**3
CONTENTS, ALLOC, LOAD, DATA
24 .data 00000010 0000000000601010 0000000000601010 00001010 2**3
CONTENTS, ALLOC, LOAD, DATA
25 .bss 00000010 0000000000601020 0000000000601020 00001020 2**3
ALLOC
26 .comment 00000023 0000000000000000 0000000000000000 00001020 2**0
CONTENTS, READONLY
SYMBOL TABLE:
0000000000400238 l d .interp 0000000000000000 .interp
0000000000400254 l d .note.ABI-tag 0000000000000000 .note.ABI-tag
0000000000400274 l d .note.gnu.build-id 0000000000000000 .note.gnu.build-id
0000000000400298 l d .hash 0000000000000000 .hash
00000000004002c0 l d .gnu.hash 0000000000000000 .gnu.hash
00000000004002e0 l d .dynsym 0000000000000000 .dynsym
0000000000400340 l d .dynstr 0000000000000000 .dynstr
0000000000400380 l d .gnu.version 0000000000000000 .gnu.version
0000000000400388 l d .gnu.version_r 0000000000000000 .gnu.version_r
....
0000000000600e30 g O .dtors 0000000000000000 .hidden __DTOR_END__
00000000004005a0 g F .text 0000000000000089 __libc_csu_init
0000000000601020 g *ABS* 0000000000000000 __bss_start
0000000000601030 g *ABS* 0000000000000000 _end
0000000000601020 g *ABS* 0000000000000000 _edata
0000000000400524 g F .text 0000000000000060 main
00000000004003f0 g F .init 0000000000000000 _init
Consider the following example. The assembler contents of executable sections (in the
object file) are displayed in this output (partial output shown below):
5 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
$ objdump -d factorial
00000000004003f0 :
4003f0: 48 83 ec 08 sub $0x8,%rsp
4003f4: e8 73 00 00 00 callq 40046c
..
Disassembly of section .plt:
0000000000400408 :
400408: ff 35 e2 0b 20 00 pushq 0x200be2(%rip) # 600ff0
40040e: ff 25 e4 0b 20 00 jmpq *0x200be4(%rip) # 600ff8
400414: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400418 :
400418: ff 25 e2 0b 20 00 jmpq *0x200be2(%rip) # 601000
40041e: 68 00 00 00 00 pushq $0x0
400423: e9 e0 ff ff ff jmpq 400408
0000000000400428 :
400428: ff 25 da 0b 20 00 jmpq *0x200bda(%rip) # 601008
40042e: 68 01 00 00 00 pushq $0x1
400433: e9 d0 ff ff ff jmpq 400408
0000000000400440 :
400440: 31 ed xor %ebp,%ebp
400442: 49 89 d1 mov %rdx,%r9
400445: 5e pop %rsi
...
000000000040046c :
40046c: 48 83 ec 08 sub $0x8,%rsp
400470: 48 8b 05 69 0b 20 00 mov 0x200b69(%rip),%rax # 600fe0
400477: 48 85 c0 test %rax,%rax
40047a: 74 02 je 40047e
40047c: ff d0 callq *%rax
...
0000000000400490 :
400490: 55 push %rbp
400491: 48 89 e5 mov %rsp,%rbp
400494: 53 push %rbx
400495: 48 83 ec 08 sub $0x8,%rsp
400499: 80 3d 80 0b 20 00 00 cmpb $0x0,0x200b80(%rip) # 601020
4004a0: 75 4b jne 4004ed
4004a2: bb 30 0e 60 00 mov $0x600e30,%ebx
4004fb: 00 00 00 00 00
...
0000000000400500 :
400500: 55 push %rbp
400501: 48 83 3d 2f 09 20 00 cmpq $0x0,0x20092f(%rip) # 600e38
400508: 00
400509: 48 89 e5 mov %rsp,%rbp
40050c: 74 12 je 400520
40050e: b8 00 00 00 00 mov $0x0,%eax
400513: 48 85 c0 test %rax,%rax
400516: 74 08 je 400520
6 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
0000000000400524 :
400524: 55 push %rbp
400525: 48 89 e5 mov %rsp,%rbp
400528: 48 83 ec 10 sub $0x10,%rsp
40052c: c7 45 fc 06 00 00 00 movl $0x6,-0x4(%rbp)
400533: b8 00 00 80 3f mov $0x3f800000,%eax
400538: 89 45 f8 mov %eax,-0x8(%rbp)
...
0000000000400668 :
400668: 48 83 ec 08 sub $0x8,%rsp
40066c: e8 1f fe ff ff callq 400490
400671: 48 83 c4 08 add $0x8,%rsp
400675: c3 retq
In case the assembler contents of all the sections is required in output, the option -D can
be used.
0000000000400238 :
400238: 2f (bad)
400239: 6c insb (%dx),%es:(%rdi)
40023a: 69 62 36 34 2f 6c 64 imul $0x646c2f34,0x36(%rdx),%esp
400241: 2d 6c 69 6e 75 sub $0x756e696c,%eax
400246: 78 2d js 400275
400248: 78 38 js 400282
40024a: 36 ss
40024b: 2d 36 34 2e 73 sub $0x732e3436,%eax
400250: 6f outsl %ds:(%rsi),(%dx)
400251: 2e 32 00 xor %cs:(%rax),%al
0000000000400254 :
400254: 04 00 add $0x0,%al
400256: 00 00 add %al,(%rax)
400258: 10 00 adc %al,(%rax)
40025a: 00 00 add %al,(%rax)
40025c: 01 00 add %eax,(%rax)
40025e: 00 00 add %al,(%rax)
7 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
400260: 47 rex.RXB
400261: 4e 55 rex.WRX push %rbp
400263: 00 00 add %al,(%rax)
400265: 00 00 add %al,(%rax)
400267: 00 02 add %al,(%rdx)
400269: 00 00 add %al,(%rax)
40026b: 00 06 add %al,(%rsi)
40026d: 00 00 add %al,(%rax)
40026f: 00 0f add %cl,(%rdi)
400271: 00 00 add %al,(%rax)
...
...
...
So we see that the relevant output was displayed. Since the output was very long, so I
clipped it. Note that I used the pager command for controlling the output.
8 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
So we see that the complete contents for all the sections were displayed in the output.
$ objdump -g factorial
So we see that all the available debug information was printed in output.
9 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
$ objdump -t factorial
SYMBOL TABLE:
0000000000400238 l d .interp 0000000000000000 .interp
0000000000400254 l d .note.ABI-tag 0000000000000000 .note.ABI-tag
0000000000400274 l d .note.gnu.build-id 0000000000000000 .note.gnu.build-id
0000000000400298 l d .hash 0000000000000000 .hash
00000000004002c0 l d .gnu.hash 0000000000000000 .gnu.hash
00000000004002e0 l d .dynsym 0000000000000000 .dynsym
0000000000400340 l d .dynstr 0000000000000000 .dynstr
0000000000400380 l d .gnu.version 0000000000000000 .gnu.version
.....
0000000000601010 g .data 0000000000000000 __data_start
0000000000601018 g O .data 0000000000000000 .hidden __dso_handle
0000000000600e30 g O .dtors 0000000000000000 .hidden __DTOR_END__
00000000004005a0 g F .text 0000000000000089 __libc_csu_init
0000000000601020 g *ABS* 0000000000000000 __bss_start
0000000000601030 g *ABS* 0000000000000000 _end
0000000000601020 g *ABS* 0000000000000000 _edata
0000000000400524 g F .text 0000000000000060 main
00000000004003f0 g F .init 0000000000000000 _init
So we see that the contents of symbol table were displayed in the output.
Dynamic symbols are those which are resolved during run time. The information related
to these symbols can be retrieved using the -D option.
11. Display the dynamic relocation entries in the file using -R option
10 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
So we see that all the dynamic relocation entries were displayed in the output.
This is extremely useful when you know the section related to which the information is
required. The option -j is used in this case.
11 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
...
If you want, the options to objdump can be read from a file. This can be done using ‘@’
option.
In this example above, I have used the -v and -i options. While -v is used to print the
version information, -i is used to provide supported object formats and architectures.
$ cat options.txt
-v -i
Execute the objdump by calling the options.txt file as shown below. This displays the
same output as above, as it is reading the options from the options.txt file.
$ objdump @options.txt
GNU objdump (GNU Binutils for Ubuntu) 2.20.1-system.20100303
Copyright 2009 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
12 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
Since now ELF is the format standard , isnt “readelf” a flexible command for
program and section headers ? objdump is anyway best suited for disassemble
object code .
Link
m4tch3t September 22, 2012, 8:52 pm
you must clarify what connection between those adressess (logical or virtual) with
the label,
like:
0 .interp 0000001c 0000000000400238 0000000000400238
how to read and associate between .interp and 0000000000400238..
i’m a newbie and i want to learn…^_^
Link
shadi April 23, 2015, 8:46 pm
Is there a way to find out which part of the instructions, i.e. which addresses, from
assembler contents of executable sections are from each C code and which part of
it is from linking dynamic libraries?
Link
shadi April 23, 2015, 9:46 pm
13 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
Link
Leave a Comment
Name
Website
Comment
Submit
EBOOKS
14 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
Linux 101 Hacks 2nd Edition eBook - Practical Examples to Build a Strong
Foundation in Linux
Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell
Scripting
Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and Awk
Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive in
Vim Editor
Nagios Core 3 eBook - Monitor Everything, Be Proactive, and Sleep Well
POPULAR POSTS
15 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
CATEGORIES
Linux Tutorials
Vim Editor
Sed Scripting
Awk Scripting
Bash Shell Scripting
Nagios Monitoring
OpenSSH
IPTables Firewall
Apache Web Server
MySQL Database
Perl Programming
Google Tutorials
Ubuntu Tutorials
PostgreSQL DB
Hello World Examples
C Programming
C++ Programming
DELL Server Tutorials
Oracle Database
VMware Tutorials
Contact Us
16 of 17 4/14/20, 1:51 PM
Linux Objdump Command Examples (Disassemble... https://www.thegeekstuff.com/2012/09/objdump-...
Email Me : Use this Contact Form to get in touch me with your comments, questions or
suggestions about this site. You can also simply drop me a line to say hello!.
Follow us on Google+
Follow us on Twitter
Support Us
17 of 17 4/14/20, 1:51 PM