Linux strip命令用来从目标文件或可执行文件中剥掉一些符号信息和调试信息,文件功能不变,并变小
介绍
file 命令用来查看文件信息
not stripped 的库用于调试 
stripped 的库用做发布版本 release 
示例
$ file /usr/lib/x86_64-linux-gnu/crt1.o
/usr/lib/x86_64-linux-gnu/crt1.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), for GNU/Linux 3.2.0, not stripped
Linux 交叉编译后,不同平台需要使用不同的命令进行 strip
- 32平台:
arm-linux-strip 
- 64平台:
aarch64-linux-gnu-strip 
安装
apt install binutils -y
# 上面是默认 x86 的,其他架构
apt install binutils-aarch64-linux-gnu -y
help
  
  
    
      $ strip --help
Usage: strip <option(s)> in-file(s)
 Removes symbols and sections from files
 The options are:
  -I --input-target=<bfdname>      Assume input file is in format <bfdname>
  -O --output-target=<bfdname>     Create an output file in format <bfdname>
  -F --target=<bfdname>            Set both input and output format to <bfdname>
  -p --preserve-dates              Copy modified/access timestamps to the output
  -D --enable-deterministic-archives
                                   Produce deterministic output when stripping archives (default)
  -U --disable-deterministic-archives
                                   Disable -D behavior
  -R --remove-section=<name>       Also remove section <name> from the output
     --remove-relocations <name>   Remove relocations from section <name>
  -s --strip-all                   Remove all symbol and relocation information
  -g -S -d --strip-debug           Remove all debugging symbols & sections
     --strip-dwo                   Remove all DWO sections
     --strip-unneeded              Remove all symbols not needed by relocations
     --only-keep-debug             Strip everything but the debug information
  -M  --merge-notes                Remove redundant entries in note sections (default)
      --no-merge-notes             Do not attempt to remove redundant notes
  -N --strip-symbol=<name>         Do not copy symbol <name>
     --keep-section=<name>         Do not strip section <name>
  -K --keep-symbol=<name>          Do not strip symbol <name>
     --keep-file-symbols           Do not strip file symbol(s)
  -w --wildcard                    Permit wildcard in symbol comparison
  -x --discard-all                 Remove all non-global symbols
  -X --discard-locals              Remove any compiler-generated symbols
  -v --verbose                     List all object files modified
  -V --version                     Display this program's version number
  -h --help                        Display this output
     --info                        List object formats & architectures supported
  -o <file>                        Place stripped output into <file>
strip: supported targets: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big pe-x86-64 pe-bigobj-x86-64 pe-i386 srec symbolsrec verilog tekhex binary ihex plugin
Report bugs to <http://www.sourceware.org/bugzilla/>
     
   
 
示例
strip 后可以看到 crt1.o 文件编写
$ ls -lhart /usr/lib/x86_64-linux-gnu/crt1.o
-rw-r--r-- 1 root root 2.0K Apr  7  2022 /usr/lib/x86_64-linux-gnu/crt1.o
$ cp /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crt1-2.o
$ strip /usr/lib/x86_64-linux-gnu/crt1-2.o
$ ls -lhart /usr/lib/x86_64-linux-gnu/crt1-2.o
-rw-r--r-- 1 root root 1.1K Jan 21 15:35 /usr/lib/x86_64-linux-gnu/crt1-2.o