如何判断一个.so是否是debug编译的?
如果用此方法:用file来查看一个.so, 根据是否包含”not stripped”来判断该.so是否是debug编译的。然而stripped/not stripped并不是debug/release编译的判断标准. 对debug和release的.so运行file后可得出几乎相同的输出, 都是not stripped。所以此方法是不准确的。
debug/release的区别更多的表现在.so和可执行程序所拥有的段上。debug编译出来的.so和可执行程序拥有很多附加的段来包含哪些debug的信息。所以查看段信息是一种判断的方式。
对同一个开源软件进行debug和release编译, 并且查看某个.so的段(readelf -S)
readelf -S 文件名
例子:
[postgres-13@yz219 ~]$ readelf -S /home/postgres-13/postgresql/bin/postgres
共有 38 个节头,从偏移量 0x241fbc8 开始:
节头:
[号] 名称 类型 地址 偏移量
大小 全体大小 旗标 链接 信息 对齐
……
[25] .data PROGBITS 0000000000d0e800 0070e800
000000000000e018 0000000000000000 WA 0 0 32
[26] .bss NOBITS 0000000000d1c820 0071c818
0000000000032468 0000000000000000 WA 0 0 32
[27] .comment PROGBITS 0000000000000000 0071c818
000000000000005a 0000000000000001 MS 0 0 1
[28] .debug_aranges PROGBITS 0000000000000000 0071c872
0000000000008eb0 0000000000000000 0 0 1
[29] .debug_info PROGBITS 0000000000000000 00725722
0000000000f150ed 0000000000000000 0 0 1
[30] .debug_abbrev PROGBITS 0000000000000000 0163a80f
00000000000b3d5d 0000000000000000 0 0 1
[31] .debug_line PROGBITS 0000000000000000 016ee56c
00000000001a7148 0000000000000000 0 0 1
[32] .debug_str PROGBITS 0000000000000000 018956b4
000000000009e650 0000000000000001 MS 0 0 1
[33] .debug_loc PROGBITS 0000000000000000 01933d04
0000000000905368 0000000000000000 0 0 1
[34] .debug_ranges PROGBITS 0000000000000000 0223906c
000000000011d0d0 0000000000000000 0 0 1
……