Linux下查看.so和可执行文件是否debug编译
如何判断一个.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 文件名
- 1
发现release编译的只有29个段:
There are 29 section headers, starting at offset 0x1b7d78:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .note.gnu.build-i NOTE 00000000000001c8 000001c8
0000000000000024 0000000000000000 A 0 0 4
[ 2] .gnu.hash GNU_HASH 00000000000001f0 000001f0
0000000000003430 0000000000000000 A 3 0 8
[ 3] .dynsym DYNSYM 0000000000003620 00003620
000000000000b400 0000000000000018 A 4 2 8
[ 4] .dynstr STRTAB 000000000000ea20 0000ea20
00000000000083e2 0000000000000000 A 0 0 1
[ 5] .gnu.version VERSYM 0000000000016e02 00016e02
0000000000000f00 0000000000000002 A 3 0 2
[ 6] .gnu.version_r VERNEED 0000000000017d08 00017d08
0000000000000080 0000000000000000 A 4 2 8
[ 7] .rela.dyn RELA 0000000000017d88 00017d88
0000000000009570 0000000000000018 A 3 0 8
[ 8] .rela.plt RELA 00000000000212f8 000212f8
00000000000080d0 0000000000000018 A 3 10 8
[ 9] .init PROGBITS 00000000000293c8 000293c8
0000000000000018 0000000000000000 AX 0 0 4
[10] .plt PROGBITS 00000000000293e0 000293e0
00000000000055f0 0000000000000010 AX 0 0 4
[11] .text PROGBITS 000000000002e9d0 0002e9d0
0000000000144658 0000000000000000 AX 0 0 16
[12] .fini PROGBITS 0000000000173028 00173028
000000000000000e 0000000000000000 AX 0 0 4
[13] .rodata PROGBITS 0000000000173040 00173040
000000000001e9a0 0000000000000000 A 0 0 32
[14] .eh_frame_hdr PROGBITS 00000000001919e0 001919e0
000000000000427c 0000000000000000 A 0 0 4
[15] .eh_frame PROGBITS 0000000000195c60 00195c60
0000000000017d7c 0000000000000000 A 0 0 8
[16] .ctors PROGBITS 00000000003ae1e8 001ae1e8
0000000000000010 0000000000000000 WA 0 0 8
[17] .dtors PROGBITS 00000000003ae1f8 001ae1f8
0000000000000010 0000000000000000 WA 0 0 8
[18] .jcr PROGBITS 00000000003ae208 001ae208
0000000000000008 0000000000000000 WA 0 0 8
[19] .data.rel.ro PROGBITS 00000000003ae220 001ae220
0000000000005b38 0000000000000000 WA 0 0 32
[20] .dynamic DYNAMIC 00000000003b3d58 001b3d58
00000000000001a0 0000000000000010 WA 4 0 8
[21] .got PROGBITS 00000000003b3ef8 001b3ef8
00000000000010e8 0000000000000008 WA 0 0 8
[22] .got.plt PROGBITS 00000000003b4fe8 001b4fe8
0000000000002b08 0000000000000008 WA 0 0 8
[23] .data PROGBITS 00000000003b7b00 001b7b00
0000000000000158 0000000000000000 WA 0 0 32
[24] .bss NOBITS 00000000003b7c58 001b7c58
0000000000000010 0000000000000000 WA 0 0 8
[25] .comment PROGBITS 0000000000000000 001b7c58
000000000000002a 0000000000000001 MS 0 0