readelf vs. objdump: why are both needed
Asked Answered
R

1

59

I need to learn about the ELF file layout for a project I am working on and I noticed the existence of these tools. Why do all Linux distributions include both readelf and objdump? Do these tools complement one another? When would i prefer to use one over another?

Roadhouse answered 23/1, 2012 at 22:39 Comment(0)
P
85

from binutils/readelf.c:

 /* The difference between readelf and objdump:

   Both programs are capabale of displaying the contents of ELF format files,
   so why does the binutils project have two file dumpers ?

   The reason is that objdump sees an ELF file through a BFD filter of the
   world; if BFD has a bug where, say, it disagrees about a machine constant
   in e_flags, then the odds are good that it will remain internally
   consistent.  The linker sees it the BFD way, objdump sees it the BFD way,
   GAS sees it the BFD way.  There was need for a tool to go find out what
   the file actually says.

   This is why the readelf program does not link against the BFD library - it
   exists as an independent program to help verify the correct working of BFD.

   There is also the case that readelf can provide more information about an
   ELF file than is provided by objdump.  In particular it can display DWARF
   debugging information which (at the moment) objdump cannot.  */
Prosenchyma answered 23/1, 2012 at 22:42 Comment(4)
The comment about objdump not being able to dump DWARF debug info used to be true, but hasn't been true since about 2005.Johnathan
I would also like to add a note, that readelf is architecture independent. To objdump your app properly you have to have a proper objdump from a relevant toolchain, that is ARM objdump for ARM binaries, X86 objdump for X86 binaries, etc.Sassenach
The elfutils toolchain provides a good elf/dwarf consistency check now, so maintaining binutils elfutils forever is probably not necessary just on that account.Beera
Is it that readelf is better than objdump? Because it provides more information?Citronellal

© 2022 - 2024 — McMap. All rights reserved.