readelf 命令详解

来源:互联网 发布:女性 黄酒 知乎 编辑:程序博客网 时间:2024/05/21 21:36

[描述] 

readelf用来显示一个或者多个elf格式的目标文件的信息,可以通过它的选项来控制显示哪些信息。这里的elf-file(s)就表示那些被检查的文件。可以支持32位,64位的elf格式文件,也支持包含elf文件的文档(这里一般指的是使用ar命令将一些elf文件打包之后生成的例如lib*.a之类的“静态库”文件)。 

这个程序和objdump提供的功能类似,但是它显示的信息更为具体,并且它不依赖BFD库(BFD库是一个GNU项目,它的目标就是希望通过一种统一的接口来处理不同的目标文件),所以即使BFD库有什么bug存在的话也不会影响到readelf程序。 


ELF文件类型: 

种类型的ELF文件: 

a)可重定位文件:用户和其他目标文件一起创建可执行文件或者共享目标文件,例如lib*.a文件。 

b)可执行文件:用于生成进程映像,载入内存执行,例如编译好的可执行文件a.out。 

c)共享目标文件:用于和其他共享目标文件或者可重定位文件一起生成elf目标文件或者和执行文件一起创建进程映像,例如lib*.so文件。 


ELF文件作用: 

ELF文件参与程序的连接(建立一个程序)和程序的执行(运行一个程序),所以可以从不同的角度来看待elf格式的文件: 

a)如果用于编译和链接(可重定位文件),则编译器和链接器将把elf文件看作是节头表描述的节的集合,程序头表可选。 

b)如果用于加载执行(可执行文件),则加载器则将把elf文件看作是程序头表描述的段的集合,一个段可能包含多个节,节头表可选。 

c)如果是共享文件,则两者都含有。

 

readelf 命令

readelf <option(s)> elf-file(s) 

<option(s)>:

-a 
--all 显示全部信息,等价于 -h -l -S -s -r -d -V -A -I. 

-h 
--file-header 显示elf文件开始的文件头信息. 


-l 
--program-headers  
--segments 显示程序头(段头)信息(如果有的话)。 

-S 
--section-headers  
--sections 显示节头信息(如果有的话)。 

-g 
--section-groups 显示节组信息(如果有的话)。 

-t 
--section-details 显示节的详细信息(-S的)。 

-s 
--syms        
--symbols 显示符号表段中的项(如果有的话)。 

-e 
--headers 显示全部头信息,等价于: -h -l -S 

-n 
--notes 显示note段(内核注释)的信息。 

-r 
--relocs 显示可重定位段的信息。 

-u 
--unwind 显示unwind段信息。当前只支持IA64 ELF的unwind段信息。 

-d 
--dynamic 显示动态段的信息。 

-V 
--version-info 显示版本段的信息。 

-A 
--arch-specific 显示CPU构架信息。 

-D 
--use-dynamic 使用动态段中的符号表显示符号,而不是使用符号段。 

-x <number or name> 
--hex-dump=<number or name> 以16进制方式显示指定段内内容。number指定段表中段的索引,或字符串指定文件中的段名。 

-w[liaprmfFsoR] or 
--debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=loc,=Ranges] 
显示调试段中指定的内容。 

-I 
--histogram 显示符号的时候,显示bucket list长度的柱状图。 

-v 
--version 显示readelf的版本信息。 

-H 
--help 显示readelf所支持的命令行选项。 

-W 
--wide 宽行输出。 

-------------------------------------------------------------------------------------------

Usage: readelf <option(s)> elf-file(s)

 Options are:

  -a --all                     Equivalent to: -h -l -S -s -r -d -V -A -I

  -h --file-header       Display the ELF file header

  -l --program-headers   Display the program headers

     --segments               An alias for --program-headers

  -S --section-headers   Display the sections' header

     --sections                 An alias for --section-headers

  -g --section-groups    Display the section groups

  -t --section-details     Display the section details

  -e --headers               Equivalent to: -h -l -S

  -s --syms                   Display the symbol table

     --symbols              An alias for --syms

  --dyn-syms              Display the dynamic symbol table

  -n --notes                 Display the core notes (if present)

  -r --relocs                 Display the relocations (if present)

  -u --unwind              Display the unwind info (if present)

  -d --dynamic            Display the dynamic section (if present)

  -V --version-info      Display the version sections (if present)

  -A --arch-specific     Display architecture specific information (if any)

  -c --archive-index     Display the symbol/file index in an archive

  -D --use-dynamic       Use the dynamic section info when displaying symbols

  -x --hex-dump=<number|name>            Dump the contents of section <number|name> as bytes

  -p --string-dump=<number|name>         Dump the contents of section <number|name> as strings

  -R --relocated-dump=<number|name>   Dump the contents of section <number|name> as relocated bytes

  -w[lLiaprmfFsoRt] or

  --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,

                          =frames-interp,=str,=loc,=Ranges,=pubtypes,

                         =gdb_index,=trace_info,=trace_abbrev,=trace_aranges]

                         Display the contents of DWARF2 debug sections

  --dwarf-depth=N        Do not display DIEs at depth N or greater

  --dwarf-start=N          Display DIEs starting with N, at the same depth or deeper

  -I --histogram             Display histogram of bucket list lengths

  -W --wide                  Allow output width to exceed 80 characters

  @<file>                     Read options from <file>

  -H --help                   Display this information

  -v --version              Display the version number of readelf

0 0
原创粉丝点击