日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

strip and linux lib compile

發布時間:2023/12/9 linux 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 strip and linux lib compile 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

From: http://www.360doc.com/content/11/0808/17/7472348_138951246.shtml

strip經常用來去除目標文件中的一些符號表、調試符號表信息,以減小程序的大小,在rpmbuild包的最后就用到。
其支持的選項如下:
>strip -h
用法:strip <選項> 輸入文件
從文件中刪除符號和節
?選項為:
? -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
? -R --remove-section=<name>?????? Remove section <name> from the output
? -s --strip-all?????????????????? Remove all symbol and relocation information
? -g -S -d --strip-debug?????????? Remove all debugging symbols & sections
???? --strip-unneeded????????????? Remove all symbols not needed by relocations
???? --only-keep-debug???????????? Strip everything but the debug information
? -N --strip-symbol=<name>???????? Do not copy symbol <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: 支持的目標: elf32-i386 a.out-i386-linux efi-app-ia32 elf32-little elf32-big elf64-alpha ecoff-littlealpha elf64-little elf64-big elf32-littlearm elf32-bigarm elf32-hppa-linux elf32-hppa elf64-ia64-little elf64-ia64-big efi-app-ia64 elf32-m68k a.out-m68k-linux elf32-powerpc aixcoff-rs6000 elf32-powerpcle ppcboot elf64-powerpc elf64-powerpcle aixcoff64-rs6000 elf32-s390 elf64-s390 elf32-sparc a.out-sparc-linux elf64-sparc a.out-sunos-big elf64-x86-64 pe-i386 pei-i386 srec symbolsrec tekhex binary ihex trad-core

目標文件分為:可重定位文件、可執行文件、共享文件
strip的默認選項會去除.symbol節的內容以及.debug節的內容,因此盡量只對可執行文件執行strip而不要對靜態庫或動態庫等目標文件strip。

測試代碼如下:

int max(int val1, int val2) {int iVal = (val1 > val2) ? val1 : val2;return iVal; }int min(int val1, int val2) {int iVal = (val1 < val2) ? val1 : val2;return iVal; }#include <stdio.h>extern int max(int val1, int val2); extern int min(int val1, int val2);int main() {int val1, val2;scanf("%d %d", &val1, &val2);printf("%d\n", max(val1, val2));printf("%d\n", min(val1, val2)); }

>gcc -c max.c min.c

>ar rcs libcmp.a max.o min.o
>gcc -o test main.c libcmp.a
>gcc -share -fPIC -o libcmp.so max.c min.c

>cp libcmp.a libcmp.a.bak
>cp libcmp.so libcmp.so.bak
>cp test test.orig
>strip libcmp.a libcmp.so
>strip test
>ll -h
總計 92K
-rwxr-xr-x 1 6.9K a.out
-rw-r--r-- 1 1.1K libcmp.a
-rw-r--r-- 1 1.6K libcmp.a.bak
-rwxr-xr-x 1 2.9K libcmp.so
-rwxr-xr-x 1 5.3K libcmp.so.bak
-rw-r--r-- 1? 237 main.c
-rw-r--r-- 1? ? 89 max.c
-rw-r--r-- 1? 695 max.o
-rw-r--r-- 1? ? 89 min.c
-rw-r--r-- 1? 695 min.o
-rwxr-xr-x 1 3.2K test
-rwxr-xr-x 1 6.8K test.orig

選項簡釋:
The -fPIC flag directs the compiler to generate position independent code section).
The -shared flag directs the linker to create a shared object file.

可見無論是靜態庫(libcmp.a)還是動態庫(libcmp.so)還是可執行文件(test),去掉一些符號信息后都減小了很多,但如果這時再鏈接這兩個庫的話是編不過的,因此,如果不是指定特殊的strip選項的話,還是盡量不要對庫文件strip,只對鏈接后的可執行文件strip就可以了(如果也不調試)。


總結

以上是生活随笔為你收集整理的strip and linux lib compile的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。