readelf vs. objdump:为啥都需要
Posted
技术标签:
【中文标题】readelf vs. objdump:为啥都需要【英文标题】:readelf vs. objdump: why are both neededreadelf vs. objdump:为什么都需要 【发布时间】:2012-02-17 06:38:14 【问题描述】:我需要了解我正在从事的项目的 ELF 文件布局,并且我注意到这些工具的存在。 为什么所有 Linux 发行版都包含 readelf 和 objdump?这些工具是否相互补充?我什么时候更喜欢使用其中一个而不是另一个?
【问题讨论】:
【参考方案1】:来自 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. */
【讨论】:
关于objdump
无法转储DWARF
调试信息的评论曾经是真实的,但自2005 年左右以来就不再真实了。
我还想补充一点,readelf
是独立于架构的。要正确objdump
您的应用程序,您必须从相关工具链中获得正确的objdump
,即 ARM objdump
用于 ARM 二进制文件,X86 objdump
用于 X86 二进制文件等。
elfutils 工具链现在提供了良好的 elf/dwarf 一致性检查,因此可能没有必要永远维护 binutils elfutils。
是不是readelf比objdump好?因为它提供了更多信息?以上是关于readelf vs. objdump:为啥都需要的主要内容,如果未能解决你的问题,请参考以下文章