惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
N
News | PayPal Newsroom
SecWiki News
SecWiki News
P
Privacy International News Feed
T
Troy Hunt's Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
L
LINUX DO - 热门话题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Security Latest
Security Latest
AWS News Blog
AWS News Blog
S
Secure Thoughts
W
WeLiveSecurity
H
Heimdal Security Blog
T
Threat Research - Cisco Blogs
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
G
GRAHAM CLULEY
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
Cisco Talos Blog
Cisco Talos Blog
雷峰网
雷峰网
Cloudbric
Cloudbric
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
Latest news
Latest news
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
Docker
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
H
Help Net Security
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Check Point Blog
博客园 - 叶小钗

博客园 - PKICA

编译配置解答 git实用命令 rust底层设计理念值得注意的几个地方总结 rust可变引用作为函数参数的机理详解 Rust内存重解释transmute C与Rust类型映射 Rust FFI 安全抽象范式 rust延迟初始化原语 rust重借用机制与原理 rust参数传递模型 汇编语言语法详解 gdb汇编调试 gdb-pwndbg的安装与使用指南 gdb调试插件gef C语言thread_local gcore转储进程内存 gdb查看命令 RGB与YUV颜色编码的区别 Rust原子类型 C++ STL求两个集合交集差集 gdb调试集锦 ubuntu24.0.4使用root用户登录 ubuntu24.0.4输入密码后跳回登录界面 AI内存压缩技术TurboQuant及存疑 ubuntu切换到指定内核版本 在没有顶级科技大佬直接背书的情况下deepseek为啥能够异军突起? HuggingFace和deepseek的关系 当前主流AI大模型 Rust写时克隆Cow系列2
linux系统readelf命令使用指南
PKICA · 2026-04-13 · via 博客园 - PKICA

readelf 是 Linux 下一个强有力的工具,专门用于分析 ELF(Executable and Linkable Format)格式的文件,如可执行程序、目标文件(.o)和共享库(.so)。它独立于 BFD 库,因此能提供比 objdump 更具体的信息。

1. 核心常用命令 (必会)

假设目标文件为 myprogram

  • readelf -a myprogram:显示全部信息(包含文件头、段头、符号表、重定位信息、动态信息等)。
  • readelf -h myprogram:查看 ELF 文件头(ELF Header)。包括文件类型、机器架构、入口地址等。
  • readelf -S myprogram:查看节头表(Section Headers)。显示程序由哪些部分组成(如 .text 代码段、.data 数据段、.bss)。
  • readelf -l myprogram:查看段头表(Program Headers/Segments)。显示程序在运行时如何映射到内存中(主要针对可执行文件)。
  • readelf -s myprogram:查看符号表(Symbol Table)。列出变量、函数等符号
  • readelf -d myprogram:查看动态段(Dynamic Section)。主要用于动态链接库分析,查看所依赖的共享库(NEEDED)。
  • readelf -r myprogram:显示重定位信息(Relocations)。 

2. 常用功能进阶示例

2.1 查看依赖库

查看一个共享库或可执行文件需要哪些 .so 文件:

readelf -d /bin/ls | grep NEEDED

2.2 查找符号定义 (函数或变量)

查看符号表,查找特定函数 main 的位置:

readelf -s myprogram | grep main

2.3 查看文件架构 (x86-64, ARM)

readelf -h myprogram | grep Machine

2.4 查看指定节内容 (16进制)

查看数据段(如索引为 15 的 .rodata)的 16 进制内容:

readelf -x 15 myprogram
# 或使用节名称
readelf -x .rodata myprogram

2.5 友好显示长行 (-W)

readelf 默认在 80 列换行。对于 64 位 ELF 文件,添加 -W (wide) 参数能在一行中完整显示段信息,更具可读性。 [6, 8]

3. Readelf 选项速查表

选项对应长选项描述
-a --all 显示所有信息 (等价于 -h -l -S -s -r -d -V -A -I)
-h --file-header 显示 ELF 文件头信息
-l --segments 显示段头信息(执行视图)
-S --sections 显示节头信息(链接视图)
-s --symbols 显示符号表
-d --dynamic 显示动态段信息
-r --relocs 显示重定位信息
-x --hex-dump 以十六进制显示指定段内容
-W --wide 宽行输出,不折行

4. 常见场景

  • 分析段错误 (Segmentation Fault):检查核心转储(Core Dump)文件:readelf -h core
  • 调试动态库加载:使用 readelf -d 检查 NEEDED 字段。
  • 逆向工程:通过 readelf -s 查看导出的符号列表。
  • 定位代码布局:使用 readelf -S 分析 .text.rodata 的地址和大小。

注意:readelf 需要的 ELF 文件可以是可执行文件、.o 目标文件、.so 共享库,甚至 ar 命令打包的 .a 静态库。

参考资料: