作为长期的UNIX用户,我通常有一些排除系统故障的工具。最近,我正在开发软件并新增了对苹果公司的OSX系统的支持。但是和其他传统UNIX变种不同,OSX不支持许多与加载、链接和执行程序相关的工具。
例如,当共享库重定位出错时,我所做的首要事情就是对可执行文件运行ldd。ldd工具列出了可执行文件所依赖的共享库(包括所在路径)。但是在OSX上,试图运行ldd将报错。
evil:~ mohit$ ldd /bin/ls -bash: ldd: command not found
没找到?但在所有的类UNIX系统上基本上都有的啊!我想知道objdump是否可用。
evil:~ mohit$ objdump -x /bin/ls -bash: objdump: command not found
命令未找到!怎么回事?
问题在于与Linux、Solaris、HP-UX和其他许多UNIX变种不同,OSX不使用ELF文件格式。另外,OSX不属于GNU项目的一部分。该项目包含像ldd和objdump这样的工具。
为了在OSX获得可执行文件所依赖的共享库列表,需要使用otool工具。
evil:~ mohit$ otool /bin/ls otool: one of -fahlLtdoOrTMRIHScis must be specified Usage: 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 (symbolicly) when possible -V print disassembled operands symbolicly -c print argument strings of a core file -X print no leading addresses or headers -m don't use archive(member) syntax evil:~ mohit$ otool -L /bin/ls /bin/ls: /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, c