2012-01-23 3 views
24

Мне нужно узнать о макете файла ELF для проекта, над которым я работаю, и я заметил наличие этих инструментов. Почему все дистрибутивы Linux включают в себя как readelf, так и objdump? Связаны ли эти инструменты друг с другом? Когда я предпочту использовать один над другим?readelf vs. objdump: зачем нужны оба

ответ

35

из 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. */ 
+12

Комментарий о 'objdump' не в состоянии сбросить' DWARF' данные отладки, используемый, чтобы быть правдой, но не верно, так как около 2005 –

+1

I также хотел бы добавить примечание, что 'readelf' является независимой от архитектуры. Чтобы «objdump» ваше приложение правильно, вы должны иметь правильный «objdump» из соответствующей инструментальной цепочки, то есть ARM 'objdump' для двоичных файлов ARM, X86' objdump' для двоичных файлов X86 и т. Д. –

Смежные вопросы