天天看点

About linux的strip命令

作者:有AI野心的电工和码农

strip命令

The strip command removes the symbol table SHT_SYMTAB and its associated string table, debugging information, and line number information from ELF object files.

That is, besides the symbol table and associated string table, the following sections are removed:

.line

.debug*

.stab*

该命令从可执行文件、动态链接库, 等等, 二进制文件的ELF对象文件中删除符号表SHT_SYMTAB, 行号信息, 调试信息, 字符串表;

命令一旦执行成功, 那么gdb就读不到这些文件的符号表了, 也就不能进行正常的调试了;

一、下面是对可执行文件ISMG_LogServer_SOL10_GCC34_V500_090320执行strip命令前后, gdb命令对它的调试信息的变化:

strip前,用gdb工具调试:

-bash-3.00$ gdb 
GNU gdb 6.2.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.10".
(gdb) file ISMG_LogServer_SOL10_GCC34_V500_090320
Reading symbols from /export/home1/ismg/ISMG5/bin/ISMG_LogServer_SOL10_GCC34_V500_090320...done.
(gdb)           

执行strip命令:

strip ISMG_LogServer_SOL10_GCC34_V500_090320

string后,用gdb工具调试:

-bash-3.00$ gdb 
GNU gdb 6.2.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.10".
(gdb) file ISMG_LogServer_SOL10_GCC34_V500_090320
Reading symbols from /export/home1/ismg/ISMG5/bin/ISMG_LogServer_SOL10_GCC34_V500_090320...(no debugging symbols found)...done.
(gdb)           

二、下面是对可执行文件ISMG_LogServer_SOL10_GCC34_V500_090320执行strip命令前后,文件大小的变化:

strip前,文件的大小:

-bash-3.00$ ls -lt | grep LogServer
-rwxr-xr-x  1 ismg  dba  436944  3月 20日 10:39 ISMG_LogServer_SOL10_GCC34_V500_090320           

执行strip命令:

strip ISMG_LogServer_SOL10_GCC34_V500_090320

strip后,文件的大小:

-bash-3.00$ ls -lt | grep LogServer
-rwxr-xr-x  1 ismg  dba  71116  3月 20日 10:40 ISMG_LogServer_SOL10_GCC34_V500_090320           

arm-linux-strip

就像 arm-linux-gcc 是 gcc 的arm嵌入式对应版一样,

arm-linux-strip也是strip命令的对应版本。

另外:

strip操作是单向的,文件一单strip过就不能恢复原样了;

如果文件大小没有减小, 那就是已经strip过了;

cc编译时加上"-s"参数,具有同样的作用。

继续阅读