您的位置:首页 > 娱乐 > 明星 > strip 、objdump、objcopy 差异与区别

strip 、objdump、objcopy 差异与区别

2025/2/25 15:02:43 来源:https://blog.csdn.net/weixin_43269452/article/details/141218054  浏览:    关键词:strip 、objdump、objcopy 差异与区别

strip 、objdump、objcopy 差异与区别

  • strip
    • 命令用于从已编译的可执行文件或目标文件中移除调试信息和其他非必要数据。这可以减小文件的大小,并且有助于保护源代码不被轻易反编译。通常,在发布软件时会使用 strip 命令来减少二进制文件的体积
  • objdump
    • 命令用于显示目标文件的信息,包括汇编语言表示、符号表、重定位条目等。这对于分析和调试程序非常有用
  • objcopy
    • 是一个用于复制和转换目标文件格式的命令行工具。它通常用于在不同的目标文件格式之间进行转换,或者对目标文件进行各种操作,比如提取或嵌入符号表、重定位信息等。

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去除文件中全部多余信息,防止被反编译
# 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 文件信息中改变,stripped
# file ice-x86.ko  
ice-x86.ko : ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, stripped

b、

  • strip 去除部分 debug 信息
# 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 文件信息中改变,with debug_info
# file ice-x86.ko.xz 
ice-x86.ko.xz: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, not stripped

方式二

  • 除了使用 strip 还能使用 objcopy 去除部分调试信息
objcopy -g ice-x86.ko
  • 看下文件的体积,缩小很多
# ll ice-x86.ko 
-rw-r--r--. 1 root root 1880144 Aug 15 10:07 ice-x86.ko
  • file 文件信息中改变,with debug_info,相当于执行了 strip -g
# file ice.ko : ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, not stripped
# ll ice-x86.ko  

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com