readelf 是 GNU binutils 中用于查看 ELF(Executable and Linkable Format)文件结构的命令行工具,常用于分析可执行文件、目标文件(.o)、共享库(.so)等。
下面从基本用法 → 常用选项 → 实战示例系统讲一遍。
readelf [选项] elf文件
常见文件类型:
a.outtest.olibxxx.soreadelf -h file
或
readelf --file-header file
能看到什么:
示例输出关键字段:
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Entry point address: 0x401000
readelf -S file
或
readelf --sections file
用途:
.text、.data、.bss、.rodatareadelf -l file
或
readelf --program-headers file
用途:
readelf -s file
或
readelf --symbols file
用途:
readelf --dyn-syms file
常用于:
undefined symbol 问题readelf -d file
或
readelf --dynamic file
常见信息:
(NEEDED) Shared library: [libc.so.6]
(SONAME) Library soname: [libtest.so]
readelf -r file
用途:
readelf -S file | grep debug
或
readelf --debug-dump=info file
readelf -h a.out | grep Type
EXEC:可执行文件DYN:共享库 / PIE 可执行文件REL:目标文件readelf -s test.o | grep UND
readelf -l a.out
关注:
LOAD 段INTERP(动态链接器路径)readelf -d a.out
NEEDED → 动态链接| 工具 | 特点 |
|---|---|
| readelf | 专注于 ELF 结构 |
| objdump | 更偏反汇编 |
常用组合:
readelf -h file
objdump -d file
✅ 分析 ELF 文件的标准流程:
readelf -h → 文件类型readelf -l → 内存布局readelf -S → 节区readelf -s → 符号readelf -d → 动态依赖如果你有具体文件或报错场景(比如符号找不到、PIE、ARM、stripped 文件),可以直接发出来,我可以一步步帮你分析。