Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does objdump manage to display source code with the -S option?

Is there a reference to the source file in the binary? I tried running strings on the binary and couldn't find any reference to the source file listed...

like image 372
anon Avatar asked Mar 24 '10 20:03

anon


People also ask

What does objdump do in Linux?

objdump is a command-line program for displaying various information about object files on Unix-like operating systems. For instance, it can be used as a disassembler to view an executable in assembly form. It is part of the GNU Binutils for fine-grained control over executables and other binary data.

What is objdump in GCC?

objdump displays information about one or more object files. The options control what particular information to display. This information is mostly useful to programmers who are working on the compilation tools, as opposed to programmers who just want their program to compile and work.


1 Answers

objdump uses the DWARF debugging information compiled into the binary, which references the source file name. If the binary isn't compiled with debugging information, or objdump can't find the source file, then you don't get source code in your output - only assembly.

You don't see the source file name when you use strings on the binary, because DWARF uses compression.

like image 128
caf Avatar answered Sep 26 '22 00:09

caf