nxdong July 29, 2022 [linux ] #linux
LD_DEBUG 调试动态库加载
Linux 指定环境变量
可以用来查看程序搜索库的路径,使用方法如下:
LD_DEBUG=libs ./your_program
LD_DEBUG=help
查看命令使用方法
export LD_DEBUG = files
export LD_DEBUG = bindings
export LD_DEBUG = libs
export LD_DEBUG = versions
export LD_DEBUG = help
Mac
使用otool
工具
otool -- help
依赖的库查询
otool - L meyers_singleton
meyers_singleton:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.23.0 )
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3 )
查看汇编
otool - tV add
add:
( __TEXT,__text ) section
_add:
0000000100003f60 pushq % rbp
0000000100003f61 movq % rsp , % rbp
0000000100003f64 movl % edi , - 0x4 (% rbp )
0000000100003f67 movl % esi , - 0x8 (% rbp )
0000000100003f6a movl - 0x4 (% rbp ), % eax
0000000100003f6d addl - 0x8 (% rbp ), % eax
0000000100003f70 popq % rbp
0000000100003f71 retq
0000000100003f72 nopw % cs :(% rax ,% rax )
0000000100003f7c nopl (% rax )
_main:
0000000100003f80 pushq % rbp
0000000100003f81 movq % rsp , % rbp
0000000100003f84 subq $ 0 x10, % rsp
0000000100003f88 movl $ 0 x0, - 0x4 (% rbp )
0000000100003f8f movl % edi , - 0x8 (% rbp )
0000000100003f92 movq % rsi , - 0x10 (% rbp )
0000000100003f96 movl $ 0 x1, % edi
0000000100003f9b movl $ 0 x2, % esi
0000000100003fa0 callq _add
0000000100003fa5 xorl % eax , % eax
0000000100003fa7 addq $ 0 x10, % rsp
0000000100003fab popq % rbp
0000000100003fac retq
参考资料
ld man page
otool manpage