赞
踩
strip
命令来减少二进制文件的体积1、获取一个二进制文件,file 看一下基本信息
# file ice-x86.ko : ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, with debug_info, not stripped
-rw-r--r-- 1 root root 33418288 Aug 14 18:44 ice-x86.ko
2、看下文件中调试信息
# readelf -S ice-x86.ko |grep debug
[73] .debug_aranges PROGBITS 0000000000000000 000bf2b1
[74] .rela.debug_[...] RELA 0000000000000000 0115cf40
[75] .debug_info PROGBITS 0000000000000000 000bfc71
[76] .rela.debug_info RELA 0000000000000000 0115d9d8
[77] .debug_abbrev PROGBITS 0000000000000000 008e8607
[78] .debug_line PROGBITS 0000000000000000 0090f42f
[79] .rela.debug_line RELA 0000000000000000 01d35220
[80] .debug_frame PROGBITS 0000000000000000 009c4d48
[81] .rela.debug_frame RELA 0000000000000000 01d374e8
[82] .debug_str PROGBITS 0000000000000000 009d9730
[83] .debug_loc PROGBITS 0000000000000000 00e4d975
[84] .rela.debug_loc RELA 0000000000000000 01d47838
[85] .debug_ranges PROGBITS 0000000000000000 00ff1114
[86] .rela.debug_[...] RELA 0000000000000000 01f348d
3、去除调试信息
方式一
a、
# strip ice-x86.ko
# readelf -S ice-x86.ko |grep debug
ll ice-x86.ko
-rw-r--r--. 1 root root 786496 Aug 15 10:12 ice-x86.ko
# file ice-x86.ko
ice-x86.ko : ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, stripped
b、
# strip -g ice-x86.ko.xz
# readelf -S ice-x86.ko |grep debug
# ll ice-x86.ko
-rw-r--r--. 1 root root 1880144 Aug 15 10:07 ice-x86.ko
# file ice-x86.ko.xz
ice-x86.ko.xz: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, not stripped
方式二
objcopy -g ice-x86.ko
# ll ice-x86.ko
-rw-r--r--. 1 root root 1880144 Aug 15 10:07 ice-x86.ko
# file ice.ko : ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, not stripped
# ll ice-x86.ko
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。