现在的位置: 首页 > 综合 > 正文

关于mac binutils

2018年03月18日 ⁄ 综合 ⁄ 共 1621字 ⁄ 字号 评论关闭

最近,在看《程序员的自我修养》一书,书中提到反汇编,使用到了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] <object file> ...
-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 <routine name>  start dissassemble from routine name
-s <segname> <sectname> 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)

【上篇】
【下篇】

抱歉!评论已关闭.