当前位置:   article > 正文

strip 、objdump、objcopy 差异与区别

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 
  • 1
  • 2

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

3、去除调试信息

方式一

a、

  • 使用strip去除文件中全部多余信息,防止被反编译
# strip ice-x86.ko 
# readelf -S ice-x86.ko  |grep debug
  • 1
  • 2
  • 看下文件的体积,缩小很多
ll ice-x86.ko  
-rw-r--r--. 1 root root 786496 Aug 15 10:12 ice-x86.ko 
  • 1
  • 2
  • file 文件信息中改变,stripped
# file ice-x86.ko  
ice-x86.ko : ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=ca1f40033e8b3ce779deb4604897f67aea62f459, stripped
  • 1
  • 2

b、

  • strip 去除部分 debug 信息
# strip -g ice-x86.ko.xz
# readelf -S ice-x86.ko  |grep debug
  • 1
  • 2
  • 看下文件的体积,缩小很多
# ll ice-x86.ko 
-rw-r--r--. 1 root root 1880144 Aug 15 10:07 ice-x86.ko
  • 1
  • 2
  • 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
  • 1
  • 2

方式二

  • 除了使用 strip 还能使用 objcopy 去除部分调试信息
objcopy -g ice-x86.ko
  • 1
  • 看下文件的体积,缩小很多
# ll ice-x86.ko 
-rw-r--r--. 1 root root 1880144 Aug 15 10:07 ice-x86.ko
  • 1
  • 2
  • 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  
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/988111
推荐阅读
相关标签
  

闽ICP备14008679号