主要针对ELF(可执行文件和可链接文件),有点反汇编的味道
VC6里有depend和dumpbin,Linux下是ldd和objdump,可查询依赖库
objdump可查到所使用cross-compile的版本,用法为objdump -s --section=.comment $prog
嵌入式版本有arm-linux-readelf:
(1)在host (x86) 机器上, 使用 arm-linux-readelf -d $target_prog 或 arm-linux-readelf -a | grep "Shared" $target_prog
(2)在target(arm)机器上,使用 /lib/ld.so.2 --list $prog
此外,file命令可以查看文件基本信息
ar 让你能查看函数库里的详细情况和用多个对象文件生成一个库文件。
经常用法:
1. ar -t libname.a //显示所有对象文件(.o文件)的列表.例: # ar t libtest.a
libtest1.o
libtest2.o
2. ar -rv libname.a objfile1.o objfile2.o ... objfilen.o //把objfile1.o--objfilen.o打包成一个库文件
nm --列出目标文件(.o)的符号清单
常用法:
nm -s filename.a/filename.o/a.out 里边所有的符号列表一清二楚。例:
# nm -s a.out
080495b8 A __bss_start
08048334 t call_gmon_start
其实ar和nm的功能基本都可以用objdump配合适当的参数实现
研究这个问题是因为之前交叉编译了QT4.7的库,但忘了使用的是不是EABI的交叉编译工具,通过arm-linux-readelf -h读取头文件,显示OS/ABI-ARM,Flags-GNU EABI,再由file显示gcc3.4.1,确定不是eabi版的
(以下转)我开始的时候并不知道怎么指定gcc的EABI,还以为4.1以上的gcc自动都是EABI,结果就是生成的内核能跑,而init进程(根文件系统的第一个进程)却运行不了。而最让我啼笑皆非的是 readelf,这绝对对我是误导的,例如:
一个ABI的文件
#readelf -h aa
ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x80f0
Start of program headers: 52 (bytes into file)
Start of section headers: 2361284 (bytes into file)
Flags: 0x2, has entry point, GNU EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 4
Size of section headers: 40 (bytes)
Number of section headers: 35
Section header string table index: 32
看见Flags那行了吗?清清楚楚写的是GNU EABI,其实它是ABI(想起来台词:它看起来是一个电吹风,其实还是刮胡刀)
真正的EABI是这样的
#readelf -h a.out
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x8130
Start of program headers: 52 (bytes into file)
Start of section headers: 2460164 (bytes into file)
Flags: 0x4000002, has entry point, Version4 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 6
Size of section headers: 40 (bytes)
Number of section headers: 36
Section header string table index: 33
本文介绍了用于分析ELF(可执行文件和可链接文件)的各种工具,包括VC6中的depend和dumpbin,Linux下的ldd和objdump,以及嵌入式版本的arm-linux-readelf。此外还介绍了如何使用这些工具来检查依赖库、版本信息和ABI类型。
2480

被折叠的 条评论
为什么被折叠?



