Tiny C Compiler

Tiny C Compiler

Infobox Software
name = Tiny C Compiler
logo =
developer = Fabrice Bellard
latest release version = 0.9.24
latest release date = release date|2008|04|01
programming language = C and Assembly
operating system = Linux, Unix, Microsoft Windows
genre = C Compiler
license = GNU Lesser General Public License
website = http://bellard.org/tcc/

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). MS Windows operating system support has been added in version 0.9.23 (17 Jun 2005). TCC is distributed under the GNU Lesser General Public License (LGPL).

TCC claims to implement all of ANSI C (C89/C90), [ [http://bellard.org/tcc/tcc-doc.html#SEC6 Tiny C Compiler Reference Documentation] accessed on 2008-08-07] much of the new ISO C99 standard, and many GNUC extensions including inline assembly. However, it does make some compromises, and 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

TCC has the following 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. It compiles, assembles and links 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.
* Few dependencies. It includes its own hand-written lexer, and it is implemented using a recursive descent parser. Thus, building TCC requires few other libraries.

Its LGPL license permits anyone to use, modify, and/or redistribute the software, and it can be used to develop either open source or proprietary software.

Compiled program performance

Although the TCC compiler itself is exceptionally fast and produces very small executables, there is an inherent trade off between this size of the compiler and the performance of the code that TCC produces.

TCC does perform a few optimizations, such as constant propagation for all operations, multiplications and divisions are optimized to shifts when appropriate, and comparison operators are specially optimized (by maintaining a special cache for the processor flags). It also does some simple register allocation, which prevents many extraneous save/load pairs inside a "single" statement.

But in general, TCC's implementation emphasizes smallness instead of optimally-performing results. TCC generates code in a single pass, and does not perform most of the optimizations performed by other compilers such as gcc. TCC compiles every statement on its own, and at the end of each statement register values are written back to the stack and must be re-read even if the next line uses the values in registers (creating extraneous save/load pairs "between" statements). TCC uses only some of the available registers (e.g., on x86 it never uses ebx, esi, oredi because they need to be preserved across function calls). [Glöckner, Daniel. [http://lists.gnu.org/archive/html/tinycc-devel/2006-09/msg00028.html Re: Tinycc-devel (no subject)] , September 8, 2006.]

Here are two benchmark examples:
* Rough benchmarks of a recursive Fibonacci algorithm on a 1.8 GHz 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 a TCC-compiled program approximately 110 seconds whereas the same program compiled by VC++ took approximately 93 seconds. Here, TCC takes 18% longer.Fact|date=February 2008
* With a tcc modified to compile gcc, running cc1 (the gcc C compiler) on itself required 518 seconds when compiled using GCC 3.4.2, 558 seconds using GCC 2.95.3, 545 using Microsoft C compiler, and 1145 seconds using tcc. The level of optimization in each compiler was -O1 or similar.

Uses

Well-known uses of tcc include:
* [http://bellard.org/tcc/tccboot.html TCCBOOT] , a 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 [Wheeler, David A. " [http://www.dwheeler.com/trusting-trust Countering Trusting Trust through Diverse Double-Compiling] ". ACSAC.]
* TCC has been used to compile gcc, though various patches were required to make this work [http://lists.gnu.org/archive/html/tinycc-devel/2005-09/threads.html]
* [http://www.cs.tut.fi/~ask/cinpy/ Cinpy] is a Python library that allows you to implement functions with C in Python modules. The functions are compiled with tcc (Tiny C Compiler) in runtime. The results are made callable in Python through the ctypes library.

History

TCC has its origins in the Obfuscated Tiny C Compiler (OTCC), a program Bellard wrote to win the International Obfuscated C Code Contest (IOCCC) in 2002. Since that time, Bellard expanded and un-obfuscated the program to produce tcc. [Bellard, Fabrice. [http://fabrice.bellard.free.fr/otcc/ Obfuscated Tiny C Compiler] ]

Current Status

TCC has an [http://lists.nongnu.org/mailman/listinfo/tinycc-devel active mailing list] , and Fabrice Bellard's current version is available through CVS. However, official tcc development slowed due to Bellard's work on other projects.

[http://landley.net/code/tinycc/ Rob Landley created a fork of tcc] that incorporated various patches from others, using the Mercurial SCM; [http://www.landley.net/hg/tinycc Landley's Mercurial branch] showed its current status while the project was active. The project was discontinued on October 4, 2007 and recontinued as a fork on October 27, 2007 [http://landley.net/code/tinycc/] .

Various others have distributed patches or download sites of various improved versions of tcc, such as [http://www.dododge.net/tcc/patches.html Dave Dodge's collection of unofficial tcc patches] , [http://packages.debian.org/unstable/devel/tcc.html Debian and kfreebsd downstream patches] , and grischka's gcc patchesgrischka, [http://lists.gnu.org/archive/html/tinycc-devel/2005-09/msg00054.html GCC by TCC (some fixes)] , 29 Sep 2005] .

TCC 0.9.23 is the subject of vulnerability number [http://cve.mitre.org/cgi-bin/cvename.cgi?name=2006-0635 CVE-2006-0635] , which is also [http://osvdb.org/displayvuln.php?osvdb_id=22956 Open Source Vulnerability Database vulnerability 22956] . The report is that TCC "contains a flaw that may have security implications on programs compiled with it. The compiler fails to return unsigned values for the sizeof operator, resulting in potential integer overflows in the objects it compiles." In version 0.9.24 of TCC this vulnerability was closed.

See also

* Portable C Compiler

References

External links

* [http://bellard.org/tcc/ TCC's homepage]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Tiny C Compiler — Tiny C Compiler …   Википедия

  • Tiny C Compiler — Entwickler Fabrice Bellard Aktuelle Version 0.9.25 (20. Mai 2009) …   Deutsch Wikipedia

  • Tiny C Compiler — Pour les articles homonymes, voir Tcc. Tiny C Compiler (tcc, tout petit compilateur C) est un compilateur C x86 complet développé par Fabrice Bellard. Sa dernière version (0.9.25, du 20 mai 2009) peut être utilisée sur Unix, Linux et Microsoft… …   Wikipédia en Français

  • Tiny CC — Tiny C Compiler Краткая справка по командам Tiny C Compiler 0.9.23. Тип компилятор Разработчик Фабрис Беллар Написана на C и язык ассемблера …   Википедия

  • Tiny — may refer to:* Tiny (car), a British cyclecar manufactured by Nanson, Barker Co at Esholt, Yorkshire between 1912 and 1915 * Tiny, Ontario, a township in south central Ontario, CanadaPeople: * Tiny Tim (musician) (1932 1996), American musician *… …   Wikipedia

  • Tiny programming language — Tiny is an extremely simple programming language used in computer science courses to teach compiler construction techniques to students. The language itself is so basic that it only includes reading of integer numbers, addition and subtraction… …   Wikipedia

  • TCC — Tiny C Compiler Краткая справка по командам Tiny C Compiler 0.9.23. Тип компилятор Разработчик Фабрис Беллар Написана на C и язык ассемблера …   Википедия

  • TCc — Tiny C Compiler Краткая справка по командам Tiny C Compiler 0.9.23. Тип компилятор Разработчик Фабрис Беллар Написана на C и язык ассемблера …   Википедия

  • TinyC — Tiny C Compiler Краткая справка по командам Tiny C Compiler 0.9.23. Тип компилятор Разработчик Фабрис Беллар Написана на C и язык ассемблера …   Википедия

  • TinyCC — Tiny C Compiler Краткая справка по командам Tiny C Compiler 0.9.23. Тип компилятор Разработчик Фабрис Беллар Написана на C и язык ассемблера …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”