readelf vs. objdump:为什么两者都需要

zr.*_*zr. 37 linux elf objdump readelf

我需要了解我正在处理的项目的ELF文件布局,并且我注意到这些工具的存在.为什么所有Linux发行版都包含readelf和objdump?这些工具是否相互补充?我什么时候更愿意使用另一个?

syn*_*tel 49

来自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.  */
Run Code Online (Sandbox Code Playgroud)

  • 关于`objdump`无法转储`DWARF`调试信息的评论曾经是真实的,但自2005年以来一直没有. (16认同)
  • 我还要添加一个注释,即"readelf"与架构无关.要正确地'objdump`你的应用程序,你必须从相关的工具链中获得一个正确的`objdump`,即用于ARM二进制文件的ARM`objdump`,用于X86二进制文件的X86`objdump`等. (6认同)