Linux下的檢視檔案格式命令:file
###Date: 2017/9/3
Linux下的檢視檔案格式命令: file fileaname
e.g
第一個後面顯示not stripped,第二個後面顯示stripped,這兩者有什麼區別呢?
strip命令可以用來去除目標檔案中的符號表。
a.out和elf(Executable and Linking Format)。這兩種格式中都有符號表(symbol table),其中包括所有的符號(程式的入口點還有變數的地址等等)。在elf格式中符號表的內容會比a.out格式的豐富的多。但是這些符號表可以用 strip工具去除,這樣的話這個檔案就無法讓debug程式跟蹤了,但是會生成比較小的可執行檔案。
例如:
程式碼:
$:gcc -c hello.c
$:ls hello.c hello.o
用gcc把hello.c編譯成目標檔案hello.o
程式碼:
$:strip hello.o
用strip去掉hello.o中的符號資訊。
程式碼:
$:gcc hello.o /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o –o hello
/*
$:gcc hello.o /usr/lib/gcc/i686-pc-linux-gnu/3.4.5/../../../crt1.o7
: In function `_start'
: init.c: (.text+0x18)
: undefined reference to `main' collect2
: ld returned 1 exit status
*/
再用gcc連線時,聯結器ld報錯。說明在目標檔案中的符號起著很重要的作用,如果要釋出二進位制的程式的話,在debug後為了減小可執行檔案的大小,可以用strip來除去符號資訊但是在程式的除錯階段還是不要用strip為好。