「DEBUG」是計算機「排除故障」的意思。馬克2號(Harvard Mark II)編製程序的格蕾絲·霍珀(Grace Hopper)是一位美國海軍準將及計算機科學家,同時也是世界最早的一批程序設計師之一。有一天,她在調試設備時出現故障,拆開繼電器後,發現有隻飛蛾被夾扁在觸點中間,從而「卡」住了機器的運行。於是,霍珀詼諧地把程序故障統稱為「臭蟲(BUG)」,把排除程序故障叫DEBUG,而這奇怪的「稱呼」,竟成為後來計算機領域的專業行話。
Release,英文翻譯就是'發布'的意思
Debug 通常稱為調試版本,它包含調試信息,並且不作任何優化,便於程式設計師調試程序。
「Release」 稱為發布版本,它往往是進行了各種優化,使得程序在代碼大小和運行速度上都是最優的,以便用戶很好地使用。
「對於初學者最疑惑的問題就是:我剛運行沒問題,發給我同學在怎麼就跑步起來呢,惱火、、」
這個問題就是你給別人 Debug 版本,而 Debug 版本帶了一些調試信息,這可能會調用一些 dll 文件動態加載,而直接發送到其他主機結果可想而知,運行報錯...
解決辦法就是生成 Release 版本。當然如果你想讓程序擁有一個安裝流程,你可以看下以前的推送。
程序打包教程
Windows 下 debug 和 release 怎麼區分,相信用過VS的你已經知道了,那 Linux 下有 debug 和 release 的區別嗎?
答案是有的,那我們來實驗證明一下:
測試代碼:
#include<stdio.h>
int fun(const char *src,const char *dest)
{
int ret = strcmp(src,dest);
return ret;
}
int main()
{
char password[20] = "123456";
int ret = fun("123456",password);
if(ret==0)
printf("logo in\n");
else
printf("logo fail\n");
return 0;
}代碼很簡單,一個登陸判斷函數 fun() 和主函數 main()
我們用 -g 選項編譯一下
gcc -g -o test-debug test.c去掉 -g 選項再編譯一下
gcc -o test-debug-temp test.c我們來比較一下他們的大小
deroy@ubuntu:~/deroy$ ls -l
total 28
-rw-r--r-- 1 deroy deroy 264 Jan 25 05:57 test.c
-rwxr-xr-x 1 deroy deroy 11120 Jan 25 06:00 test-debug
-rwxr-xr-x 1 deroy deroy 8424 Jan 25 06:01 test-debug-temp不加 -g 足足少了2696B,少掉的那部分是什麼呢,如果你了解過 gdb 那你就知道少掉的那部分是源碼調試信息。
你以為不就 -g 選項就是 release 版本了嗎?天真
我們用readelf -s命令來查看一下不加 -g 選項能看到什麼,這個命令是用來查看二進位信息的,也可以查看符號表。
deroy@ubuntu:~/deroy$ readelf -s test-debug-temp
.
50: 00000000000006fa 43 FUNC GLOBAL DEFAULT 14 fun
.
61: 0000000000000725 134 FUNC GLOBAL DEFAULT 14 main
.
65: 0000000000000580 0 FUNC GLOBAL DEFAULT 11 _init「我的fun函數怎麼暴露了、」
我們將程序裡面的「符號表」去掉,來看下「release」版本
objcopy --strip-debug test-debug-temp test-release啥也別說,先比「大小」
deroy@ubuntu:~/deroy$ ls -l
total 40
-rw-r--r-- 1 deroy deroy 264 Jan 25 05:57 test.c
-rwxr-xr-x 1 deroy deroy 11120 Jan 25 06:00 test-debug
-rwxr-xr-x 1 deroy deroy 8424 Jan 25 06:01 test-debug-temp
-rwxr-xr-x 1 deroy deroy 8312 Jan 25 06:10 test-release就只少了112 B,感覺readelf -s還是會暴露我們的函數名稱和地址
deroy@ubuntu:~/deroy$ readelf -s test-debug-temp
.
50: 00000000000006fa 43 FUNC GLOBAL DEFAULT 14 fun
.
61: 0000000000000725 134 FUNC GLOBAL DEFAULT 14 main
.
65: 0000000000000580 0 FUNC GLOBAL DEFAULT 11 _init果不其然,沒關係,我們還有終級絕招
再次strip深度清除符號表
strip test-release什麼都別說先看大小
deroy@ubuntu:~/deroy$ ls -l
total 36
-rw-r--r-- 1 deroy deroy 264 Jan 25 05:57 test.c
-rwxr-xr-x 1 deroy deroy 11120 Jan 25 06:00 test-debug
-rwxr-xr-x 1 deroy deroy 8424 Jan 25 06:01 test-debug-temp
-rwxr-xr-x 1 deroy deroy 6120 Jan 25 06:12 test-release比 debug 版本足足少了 5k,再次查看符號表
deroy@ubuntu:~/deroy$ readelf -s test-release
Symbol table '.dynsym' contains 9 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2)
3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail@GLIBC_2.4 (3)
4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2)
5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strcmp@GLIBC_2.2.5 (2)
6: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
7: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
8: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5 (2)你幾乎什麼都看不到,想破解這個程序難上加難。