Tiny C Compiler
The Tiny C Compiler (aka TCC, tcc, or TinyCC) is an x86 C language compiler created by Fabrice Bellard. It is designed to work for slow computers with little disk space (e.g. on rescue disks). The newest version (0.9.23, 17 Jun 2005) can be used on MS Windows operating systems too. TCC is distributed under the GNU Lesser General Public License.
Some of the speed is achieved by compromising in other areas; for example TCC is not close to being conforming to the C90 standard. Improving TCC to achieve compliance might significantly slow it down. Examples of unsupported areas are trigraph handling, proper type and expression checking, and incorrect nested macro expansion.
Features
- Small - can compile and execute C code everywhere, for example on rescue disks (about 100KB for x86 TCC executable, including C preprocessor, C compiler, assembler and linker).
- Fast - tcc generates optimized x86 code. No byte code overhead. Compile, assemble and link about 9 times faster than GCC.
- Any C dynamic library can be used directly. TCC is heading towards full ISOC99 compliance. TCC can of course compile itself.
- Includes an optional memory and bound checker. Bound checked code can be mixed freely with standard code.
- Compile and execute C source directly. No linking or assembly necessary. Full C preprocessor and GNU-like assembler included.
- C script is supported: just add '#!/usr/local/bin/tcc -run' at the first line of your C source, and execute it directly from the command line.
- With libtcc, you can use TCC as a backend for dynamic code generation.
Well-known uses of tcc include:
- TCCBOOT, an impressive hack where TCC loads and boots a Linux kernel from source in about 10 seconds. That is to say, it is a "boot loader" which reads Linux kernel source code from disk, writes executable instructions to memory, and begins running it. This did require changes to the Linux build process.
- TCC was used to demonstrate a defense against the trusting trust attack in the ACSAC paper Countering Trusting Trust through Diverse Double-Compiling
- TCC has been used to compile gcc, though various patches were required to make this work [1]
The original developer, Fabrice Bellard, has been busy on other projects, leaving official tcc development somewhat stalled. Various others have distributed patches or download sites of various improved versions of tcc, such as Landley's Mercurial branch and Dave Dodge's collection of unofficial tcc patches.
Compiled program performance
Although the TCC compiler itself is exceptionally fast and produces very small executables, there is an inherent trade off between this reduction in space and program performance. Rough benchmarks of a recursive Fibonacci algorithm on a 1.8Ghz Intel Centrino laptop with 512MB RAM yields a noticeable difference in results between Microsoft Visual C++ compiler 13.10.3052 and TCC. To calculate the 49th Fibonacci number, it took TCC approximately 110 seconds whereas it took VC++ approximately 93 seconds.