linux binutils,关于mac binutils

最近,在看《程序员的自我修养》一书,书中提到反汇编,使用到了binutils工具包。手头只有一台mac和一台装有win7的机器,并没有安装有linux的机器可用,想到mac 也属于unix系统,与linux大同小异,何况mac下也是用gcc编译,于是准备在mac下安装binutils试一试。

于是去gun官网下载了最新的binutils-2.22.tar.gz,接着解压,按照其README :1、./configure 2、make 3、make install 安装成功后。

运行objdump -h xxx.o以及readelf -h xxx.o 发现乱码问题,很是郁闷。随后各处查找,终于发现问题之所在,以下为摘抄高手的解释:

“Mach-O为Mach Object文件格式的缩写,它是一种用于可执行文件,目标代码,动态库,内核转储的文件格式。作为a.out格式的替代,Mach-O提供了更强的扩展性,并提升了符号表中信息的访问速度。Mach-O曾经为大部分基于Mach核心的操作系统所使用。NeXTSTEP,Darwin和Mac OS X等系统使用这种格式作为其原生可执行文件,库和目标代码的格式。而同样使用GNU Mach作为其微内核的GNU Hurd系统则使用ELF而非Mach-O作为其标准的二进制文件格式。”

在linux环境下,/usr/include目录下有elf.h文件,会有针对elf文件格式的结构体定义,在mac下,则有一个对应的mac-o目录,里面也有类似的文件。

mac下要查看可执行文件或者动态库的一些信息,就只能通过otool这样的工具来进行,不如readelf这样的熟悉和方便,另外mac也不用so这样的名称,而使用dylib,mac系统终究是来源于bsd。 主要意思是说linux和mac中的elf文件格式不太一样导致部分出现乱码,mac下只能采用otool

Uage: otool [-fahlLDtdorSTMRIHvVcXm] ... -f print the fat headers -a print the archive header -h print the mach header -l print the load commands -L print shared libraries used -D print shared library id name -t print the text section (disassemble with -v) -p  start dissassemble from routine name -s print contents of section -d print the data section -o print the Objective-C segment -r print the relocation entries -S print the table of contents of a library -T print the table of contents of a dynamic shared library -M print the module table of a dynamic shared library -R print the reference table of a dynamic shared library -I print the indirect symbol table -H print the two-level hints table -v print verbosely (symbolically) when possible -V print disassembled operands symbolically -c print argument strings of a core file -X print no leading addresses or headers -m don't use archive(member) syntax -B force Thumb disassembly (ARM objects only)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值