Tiny C Compiler
{{Short description|Compiler for the C programming language}}
{{Use dmy dates|date=June 2023}}
{{Infobox software
| name = Tiny C Compiler
| logo =
| screenshot = Tiny C Compiler 0.9.23 Windows help en.png
| caption = Screenshot
| developer = Fabrice Bellard
| latest release version = 0.9.27
| latest release date = {{start date and age|2017|12|17|df=y}}
| programming language = C and Assembly{{Citation needed|date=September 2020|reason=According to the source, it seems to be written in C (except one or two very small functions, like alloca).}}
| operating system = Linux, Unix, Windows
| license = LGPLv2.1
| website = {{URL|http://www.tinycc.org/}}
| repo = {{URL|https://repo.or.cz/w/tinycc.git }}
| replaces = OTCC, Obfuscated Tiny C CompilerBellard, Fabrice. [https://bellard.org/otcc/ Obfuscated Tiny C Compiler], winning entry of IOCCC 2001. https://bellard.org/otcc/ and at the Internet Archive at https://web.archive.org/web/20130721162702/http://www.ioccc.org/2001/
}}
The Tiny C Compiler, TCC, tCc, or TinyCC is a x86 (32-bits), X86-64 and ARM processor C compiler initially written by Fabrice Bellard. It is designed to work for slower computers with little disk space (e.g. on rescue disks). Windows operating system support was added in version 0.9.23 (17 June 2005). TCC is distributed under the GNU Lesser General Public License.
TCC claims to implement all of ANSI C (C89/C90),[https://bellard.org/tcc/tcc-doc.html#SEC6 Tiny C Compiler Reference Documentation] accessed on 2008-08-07 much of the C99 ISO standard,According to the project's [https://repo.or.cz/w/tinycc.git/blob/HEAD:/TODO TODO list] complex types are the only missing C99 feature. Variable Length Arrays have been added in TCC 0.9.26 and many GNU C extensions including inline assembly.
Features
TCC has a number of features that differentiate it from other current C compilers:
- Its small file size (about 100 KB for the x86 TCC executable) and memory footprint allow it to be used directly from a single 1.44 M floppy disk, such as a rescue disk.
- TCC is intended to produce native x86, x86-64 and ARM code very quickly; according to Bellard, it compiles, assembles and links about nine times faster than GCC does.{{Cite web|url=https://bellard.org/tcc/|title=TCC : Tiny C Compiler|website=bellard.org|accessdate=27 March 2023}} As of 2023, the "mob" development branch also includes support for RISC-V and TMS320C67xx (a DSP chip).
- TCC has a number of compiler-specific language features intended to improve its practicality, such as an optional memory and bound checker, for improved code stability.
- TCC allows programs to be run automatically at compile time using a command-line switch. This allows programs to be run as a shell script under Unix-like systems that support the shebang interpreter directive syntax.
Compiled program performance
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. 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, or edi because they need to be preserved across function calls).Glöckner, Daniel. [https://lists.gnu.org/archive/html/tinycc-devel/2006-09/msg00028.html Re: Tinycc-devel (no subject)], 8 September 2006.
TCC performs 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.
Here are two benchmark examples:
- A recursive Fibonacci algorithm on a 1.8 GHz Intel Centrino laptop with 512 MB 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 MS Visual C++ program approximately 18% longer than the TCC compiled program.{{Citation needed|date=February 2008}}
- A test compared different C compilers by using them to compile the GNU C Compiler (GCC) itself, and then using the resulting compilers to compile GCC again. Compared to GCC 3.4.2, a TCC modified to compile GCC was able to compile the compiler ten times faster, but the resulting .exe it produced was 57% larger, and much slower, taking 2.2 times as long to compile GCC again.
The results were: Running cc1 (the GCC C compiler) on itself required 518 seconds when compiled using GCC 3.4.2, 545 seconds using Microsoft C compiler, and 1145 seconds using TCC. To create these compilers in the first place, GCC (3.4.2) took 744 seconds to compile the GCC compiler, whereas TCC took only 73 seconds. The level of optimization in each compiler was -O1 or similar.
Uses
- TCCBOOT,{{Cite web|url=https://bellard.org/tcc/tccboot.html|title=TCCBOOT: TinyCC Boot Loader|website=bellard.org|accessdate=27 March 2023}} 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" that 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 has been used to compile GCC, though various patches were required to make this work.{{Cite web|url=https://lists.gnu.org/archive/html/tinycc-devel/2005-09/threads.html|title=tinycc-devel (thread)|website=lists.gnu.org|accessdate=27 March 2023}}
- TCC was used to demonstrate a defense against the trust attack.Wheeler, David A. [https://www.dwheeler.com/trusting-trust Countering Trusting Trust through Diverse Double-Compiling]. ACSAC. It is also used in GNU Guix{{cite web | url=https://guix.gnu.org/en/blog/2020/guix-further-reduces-bootstrap-seed-to-25/ | title=Guix Further Reduces Bootstrap Seed to 25% — 2020 — Blog — GNU Guix }} in an attempt to make the distribution bootstrapable without using any binary.{{Cite web|url=https://bootstrappable.org/|title=Bootstrappable builds|website=bootstrappable.org|accessdate=29 March 2023}}
- Cinpy{{Cite web|url=http://www.cs.tut.fi/~ask/cinpy/|archiveurl=https://web.archive.org/web/20081120164629/http://www.cs.tut.fi/~ask/cinpy/|url-status=dead|title=Cinpy|archivedate=20 November 2008|accessdate=27 March 2023}} is a Python library that allows you to implement functions with C in Python modules. The functions are compiled with TCC at runtime. The results are made callable in Python through the ctypes library.
- Comes installed on JavaScript Linux{{Cite web|url=https://bellard.org/jslinux/|title=JSLinux|website=bellard.org|accessdate=27 March 2023}} (also by Bellard).
- Has been used as a reference for the compiled version of the Super Micro-Max Chess program source.{{Cite web|url=https://sourceforge.net/projects/smmax/|title=Super Micro Chess|website=SourceForge|date=18 April 2016 |accessdate=27 March 2023}}
- Bun, the JavaScript runtime, uses TCC to expose an API which allows users to compile and run C programs from JavaScript.{{Cite web|url=https://bun.sh/docs/api/cc|title=C compiler|website=Bun|accessdate=22 November 2024}}
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 2001. After that time, Bellard expanded and deobfuscated the program to produce tcc.
At some time prior to 4 February 2012 Fabrice Bellard updated the project's official web page to report that he was no longer working on TCC.{{Cite web|url=http://bellard.org/tcc/|title=TCC : Tiny C Compiler|date=4 February 2012|archive-url=https://web.archive.org/web/20120204081201/http://bellard.org/tcc/ |accessdate=27 March 2023|archive-date=2012-02-04 }}
Since Bellard's departure from the project, various people and groups have distributed patches or maintained forks of TCC to build upon or fix issues with TCC. This includes Dave Dodge's collection of unofficial tcc patches,{{Cite web|url=http://www.dododge.net/tcc/patches.html|archiveurl=https://web.archive.org/web/20070331221112/http://www.dododge.net/tcc/patches.html|url-status=dead|title=Unofficial tcc Patches|archivedate=31 March 2007|website=www.dododge.net|accessdate=27 March 2023}} Debian and kfreebsd downstream patches,{{Cite web|url=https://packages.debian.org/unstable/devel/tcc|title=Debian -- Details of package tcc in sid|website=packages.debian.org|accessdate=27 March 2023}} and grischka's gcc patches.grischka, [https://lists.gnu.org/archive/html/tinycc-devel/2005-09/msg00054.html GCC by TCC (some fixes)], 29 September 2005 Grischka also set up a public Git repository for the projectgrischka, [https://repo.or.cz/w/tinycc.git Public Git Hosting for tcc] that contains a mob branchgrischka, [https://repo.or.cz/w/tinycc.git/shortlog/refs/heads/mob mob branch for tcc] where numerous contributions, including a shared build, cross-compilers, and SELinux compatibility were added. Grischka's GIT repository later became the official TCC repository (linked to by Fabrice Bellard's Savannah project page {{Cite web|url=https://savannah.nongnu.org/projects/tinycc|title=Tiny C Compiler - Summary [Savannah]|website=savannah.nongnu.org|accessdate=27 March 2023}}).
Current status
As of December 2017 both the official TCC mailing list{{Cite web|url=https://lists.gnu.org/archive/html/tinycc-devel/|title=tinycc-devel Archives|website=lists.gnu.org|accessdate=27 March 2023}} and the official Git repository (as linked to by Fabrice Bellard's Savannah project page{{Cite web|url=https://repo.or.cz/w/tinycc.git/|title=Public Git Hosting - tinycc.git/summary|website=repo.or.cz|accessdate=27 March 2023}}) show active discussion and development by many developers and interested users. In December 2017, grischka announced on the mailing list that TCC version 0.9.27 was released.{{Cite web|url=https://lists.nongnu.org/archive/html/tinycc-devel/2017-12/msg00015.html|title=[Tinycc-devel] TCC version 0.9.27 is out|website=lists.nongnu.org|accessdate=27 March 2023}}
See also
{{Portal|Free and open-source software}}
References
{{Reflist}}
External links
- {{Official website|https://bellard.org/tcc/}}
- [https://lists.nongnu.org/mailman/listinfo/tinycc-devel TCC's active mailing list]
- [https://repo.or.cz/w/tinycc.git Source code repository]
- [https://ptsource.github.io/Developer-Platform/ PTSource IDE]-Integrated Development Environment includes TCC.
{{CProLang}}
Category:C (programming language) compilers
Category:Free and open source compilers
Category:Free software programmed in C
Category:Software using the GNU Lesser General Public License