Tiny C Compiler
| 開發者 | Fabrice Bellard |
|---|---|
| 穩定版本 | 0.9.26/ 2013年2月15日 |
| 程式語言 | C and Assembly |
| 作業系統 | Linux, Unix, Windows |
| 類型 | C compiler |
| 許可協議 | GNU Lesser General Public License |
| 網站 | http://bellard.org/tcc/ |
Tiny C Compiler (縮寫為 TCC, tCc 或 TinyCC) 用於 x86 (16/32 位元)或是 x86-64 (64 位元) 系統的 C compiler,而開發者為 Fabrice Bellard。軟體是設計用於低階電腦環境,或是於磁碟容量有限的空間中(1.44磁片或是硬碟)。軟體可以適用於Windows、Linux、Unix 作業系統,而最新版本為 0.9.26 (Feb 15, 2013)。TCC 是在 GNU Lesser General Public License (LGPL)協定規範下發布。
TCC 符合 ANSI C (C89/C90) 規範,Tiny C Compiler Reference Documentation accessed on 2008-08-07] 亦符合新版的 ISO C99 標準規範,與 GNU C 擴展的內嵌組合語言(即 inline assembler,內聯彙編大陸用語)功能 assembly。
而 Google Andriod 系統內亦曾經內建於其中,於Andriod 2.0版本中,可詳見於 Jserv 網站上的文章:
目录 |
更新項目 [编辑]
- 支援C99 VLA規範
- 可產生make的dependencies (-MD/-MF)
- 支援多種平台的程式編寫,例:x86-64, ARM, OSX, WinCE, kFreeBSD, Hurd
- 修正一些已知的bug
特色功能 [编辑]
TCC 與其他 C 語言編譯器的不同處在於:
- 容量小,軟體大小約為1MB左右,可儲存於1.44MB的磁碟片中使用。
- 速度快,以 TCC 開發的程式可執行於 x86(16/32位元) 與 x86-64(64位元) 環境中,據開發者說,執行比GCC較來得相當快速。程式亦可以包含組合語言(inline Assembler)於其中執行與編譯。
- 無限制,其他C 語言的動態 Library祗要符合ISO C99規範,皆可以給予TCC來使用與編譯。
- 安全性,TCC包含一個可選的memory(記憶體)和boundschecker(程式檢測器),經過檢測的程式碼可以隨意地混合於標準程式碼內。
- 其他,TCC為命令列式的使用,目前並無整合性開發環境,但可以配合其他的編輯軟體使用(如: UltraEdit ...等)。
編譯效率 [编辑]
建議參考開發者文件說明 Compilation Speed。
使用資訊 [编辑]
程式安裝 [编辑]
- Windows 環境安裝,設定與測試
將win32壓縮檔案 tcc-0.9.25-win32-bin.zip 解壓縮於任意目錄下皆可以, 這裏示範於C磁碟下
C:\TCC 或 C:\>MD TCC<enter>
設定系統環境參數, 新增
變數名稱:TCC 參數為:C:\TCC
增加路徑
變數名稱:path
參數:{原有的路徑參數};%TCC%;
測試: 開啟命令提示字元(Command Prompt) 於任一目錄下輸入 TCC -version, 即顯示如下
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Administrator>TCC -version <enter> tcc version 0.9.25
往後即可於任一目錄下編譯C語言程式碼
使用方式 [编辑]
- 可以相同於一般的命令列C語言軟體的使用方式
- 編譯方式
於 Windows 下編譯
C:\>tcc <filename.c>
或是
C:\>tcc -run <filename.c>
提示: 以 "-run" 方式來編譯程式,編譯結果祗會存放於記憶中而己,執行完畢後即釋放,而不會產生對應的執行檔 (即EXE)。
於 Linux/Unix Like 下編譯
/use/local/bin/tcc <filename.c>
或是
/use/local/bin/tcc -run <filename.c>
同前述 "-run" 的提示。
指令查詢 [编辑]
可於 DOS/Windows 命令提示字元下,或是於 Linux/Unix Like 下鍵入
C:\>TCC <enter> 或是 [folder name]$ TCC <center>
即會得到如下說明語法:
tcc version 0.9.25 - Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard
usage: tcc [-v] [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]
[-Wwarn] [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-soname name]
[-static] [infile1 infile2...] [-run infile args...]
General options:
-v display current version, increase verbosity
-c compile only - generate an object file
-o outfile set output filename
-Bdir set tcc internal library path
-bench output compilation statistics
-run run compiled source
-fflag set or reset (with 'no-' prefix) 'flag' (see man page)
-Wwarning set or reset (with 'no-' prefix) 'warning' (see man page)
-w disable all warnings
Preprocessor options:
-E preprocess only
-Idir add include path 'dir'
-Dsym[=val] define 'sym' with value 'val'
-Usym undefine 'sym'
Linker options:
-Ldir add library path 'dir'
-llib link with dynamic or static library 'lib'
-shared generate a shared library
-soname set name for shared library to be used at runtime
-static static linking
-rdynamic export all global symbols to dynamic linker
-r generate (relocatable) object file Debugger options:
-g generate runtime debug info
檔案大小 [编辑]
網路上 Demon's Blog 亦有測試資訊,以 Borland C Compilder 5.5 (BCC, Commandline, Freeware), Visual C++ 6.0 與Tiny C Compiler來比較編譯後的檔案大小。
測試編譯程式碼為:
#include <stdio.h> int main() { printf("Hello, world\n"); return 0; }
編譯結果為:
- 用 Borland C Compiler 5.5 編譯結果為 51.0 KB (52,224 bytes)
- 用 Visual C++ 6.0 編譯結果為 40.0 KB (40,960 bytes)
- 用TCC 0.9.25編譯結果為 1.50 KB (1,536 bytes)
使用組合語言 [编辑]
TinyCC即整合了 Assembly 於其中,使用 TinyCC assembler 的語法相容於 GNU assembler 即可,但是使用時仍是有限制條件如下:
- 必須是 C 或 C++ 的指令有支援
- 由於指標符號相同於 C,所以無法使用符號有 "." 或 "$"
- 支援 32 位元為主
- 必須為inline Assembler內嵌組合語言(或內聯彙編大陸用語)使用
相關支援的組合語言語法如下列所示:
.align n[,value] .skip n[,value] .space n[,value] .byte value1[,...] .word value1[,...] .short value1[,...] .int value1[,...] .long value1[,...] .quad immediate_value1[,...] .globl symbol .global symbol .section section .text .data .bss .fill repeat[,size[,value]] .org n .previous .string string[,...] .asciz string[,...] .ascii string[,...]
注意事項 [编辑]
為方便編譯,要將 TCC 原始碼內的 libtcc.h 於置於 include 內。
開發歷史 [编辑]
TCC 是由 Obfuscated Tiny C Compiler (OTCC) 即小型混淆器用途發展而來,程式由 Bellard 於2001年編寫來為參加 International Obfuscated C Code Contest (IOCCC)比賽。其後,Bellard 即延伸發展其小型混淆器的程式,而成為最終的TCC。
相關資訊 [编辑]
- Portable C Compiler (PCC)
- Small-C
- inline Assembler內嵌組合語言(內聯彙編大陸用語)
參考資訊 [编辑]
- Tiny C Compiler Reference Documentation accessed on 2008-08-07
- Glöckner, Daniel. Re: Tinycc-devel (no subject), September 8, 2006.
- a b grischka, GCC by TCC (some fixes), 29 Sep 2005
- Wheeler, David A. Countering Trusting Trust through Diverse Double-Compiling. ACSAC.
- Bellard, Fabrice. Obfuscated Tiny C Compiler
- Bellard Fabrice Project Homepage