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

anon picture anon · Mar 24, 2010 · Viewed 47.5k times · Source

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...

Answer

caf picture caf · Mar 24, 2010

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.