strip, 关于去除目标文件种的不必要信息

对于so动态库及可执行文件,可以直接调用不带参数的strip (-s, 即--strip-all)去除大多数不必要的信息。因为so库非常标准,所以strip之后仍然可以进行完美的动态连接;而可执行文件已经进行了链接,所以也可以用strip进行完美的strip。

 

对于静态库和目标文件(.o文件),不能直接调用不带参数的strip,因为o文件大多数是relocate文件,如果去除的参数不恰当,在编译成so或可执行文件时就无法找到对应的符号。

 

对于a库,可以先采用编译优化 -O3,将某些不必要的信息进行掩盖或去除:

Use of the GCC optimization flags will help make the code look much less readable to a human. When you compile with the highest level of optimization gcc -O3 the compiler will move things around such that the "flow" might not be at all what you expect.

对于a库,还可以考虑使用这2个strip选项进行瘦身:

       -g
       -S
       -d
       --strip-debug
           Remove debugging symbols only.

       --strip-unneeded
           Remove all symbols that are not needed for relocation processing.

 

posted @ 2015-10-07 14:51  微信公众号--共鸣圈  阅读(3554)  评论(0编辑  收藏  举报