一、介绍
readelf命令,一般用于查看ELF格式的文件信息,常见的文件如在Linux上的可执行文件,动态库(.so)或者静态库(.a) 等包含ELF格式的文件。以下命令的使用是基于android编译出来的so文件上面去运行。
以下查看帮助文档
man readelf
readelf -h #显示帮助
参数选项:也可参考 readelf用法小记
Usage: readelf <option(s)> elf-file(s)
Display information about the contents of ELF format files
Options are:
-a --all Equivalent to: -h -l -S -s -r -d -V -A -I
//all 显示全部信息,等价于 -h -l -S -s -r -d -V -A -I。
-h --file-header Display the ELF file header
//显示elf文件开始的文件头信息
-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
//显示节的详细信息(-S的)。
-e --headers Equivalent to: -h -l -S
//显示全部头信息,等价于: -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)
//显示note段(内核注释)的信息 。
-r --relocs Display the relocations (if present)
//显示可重定位段的信息。
-u --unwind Display the unwind info (if present)
//显示unwind段信息。当前只支持IA64 ELF的unwind段信息。
-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).
//显示CPU构架信息。
-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
//显示readelf所支持的命令行选项。
-v --version Display the version number of readelf
//显示readelf的版本信息。
二、使用示例
具体命令:
- readelf -c xxx.a 查看静态库定义的函数
- readelf -A xxx.so 查看动态库定义的函数
- readelf -a test 查看test全部信息
- readelf -h test 查看test的ELF Header头信息
- readelf -l test 查看test的Program Header Table信息
- readelf -S test 查看test的Section Header Table信息
- ……