Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Tiny C Compiler

From Wikipedia, the free encyclopedia
Compiler for the C programming language

Tiny C Compiler
Screenshot
DeveloperFabrice Bellard
Stable release
0.9.27 / 17 December 2017; 8 years ago (2017-12-17)
Written inC andAssembly[citation needed]
Operating systemLinux,Unix,Windows
PredecessorOTCC, Obfuscated Tiny C Compiler[1]
TypeCcompiler
LicenseLGPLv2.1
Websitebellard.org/tcc/ Edit this on Wikidata
Repository

TheTiny C Compiler, TCC, tCc, or TinyCC is ax86 (32-bits),X86-64 andARM processorCcompiler initially written byFabrice Bellard. It is designed to work for slower computers with little disk space (e.g. onrescue disks).Windows operating system support was added in version 0.9.23 (17 June 2005). TCC is distributed under theGNU Lesser General Public License.

TCC claims to implement all ofANSI C (C89/C90),[2] much of theC99 ISO standard,[3] and many GNU C extensions including inlineassembly.

Features

[edit]

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) andmemory footprint allow it to be used directly from a single 1.44 Mfloppy 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 thanGCC does.[4] As of 2023, the "mob" development branch also includes support forRISC-V andTMS320C67xx (aDSP 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 theshebanginterpreter directive syntax. The shebang for TCC (as given on the official TCC website)[2] is#!/usr/local/bin/tcc -run (assuming TCC is installed to/usr/local/bin/tcc, the location of installation may vary according to system).[5]

Compiled program performance

[edit]

In general, TCC's implementation emphasizes smallness instead of optimally-performing results. TCC generates code ina 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 statementregister values are written back to thestack 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).[6]

TCC performs a fewoptimizations, such asconstant propagation for all operations, multiplications and divisions are optimized toshifts when appropriate, and comparison operators are specially optimized (by maintaining a special cache for the processor flags). It also does some simpleregister allocation, which prevents many extraneous save/load pairs inside a singlestatement.

Here are two benchmark examples:

  1. A recursiveFibonacci algorithm on a 1.8 GHzIntel Centrino laptop with 512 MBRAM yields a noticeable difference in results betweenMicrosoft 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]
  2. A test compared different C compilers by using them to compile theGNU 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.[7]

    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

[edit]
  • TCCBOOT,[8] ahack where TCC loads and boots aLinux kernel from source in about 10 seconds. That is to say, it is a "boot loader" that reads Linux kernelsource 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 variouspatches were required to make this work.[9]
  • TCC was used to demonstrate a defense against thetrust attack.[10] It is also used inGNU Guix[11] in an attempt to make the distributionbootstrappable without using any binary.[12]
  • Cinpy[13] is aPythonlibrary 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 thectypes library.
  • TCC has been used as a reference for the compiled version of the Super Micro-Max Chess program source.[14]
  • Bun uses TCC to expose an API which allows users to compile and run C programs from JavaScript.[15]

History

[edit]

TCC has its origins in the Obfuscated Tiny C Compiler (OTCC),[1] a program Bellard wrote to win theInternational Obfuscated C Code Contest (IOCCC) in 2001. After that time, Bellard expanded and deobfuscated the program to produce tcc.[1]

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.[16]

Since Bellard's departure from the project, various people and groups have distributed patches or maintainedforks of TCC to build upon or fix issues with TCC. This includes Dave Dodge's collection of unofficial tcc patches,[17]Debian and kfreebsddownstream patches,[18] and grischka's gcc patches.[7] Grischka also set up a publicGitrepository for the project[19] that contains a mob branch[20] where numerous contributions, including a shared build,cross-compilers, andSELinux compatibility were added. Grischka's GIT repository later became the official TCC repository (linked to by Fabrice Bellard's Savannah project page[21]).

Current status

[edit]

As of December 2017 both the official TCC mailing list[22] and the official Git repository (as linked to by Fabrice Bellard's Savannah project page[23]) 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.[24]

See also

[edit]

References

[edit]
  1. ^abcBellard, Fabrice.Obfuscated Tiny C Compiler, winning entry ofIOCCC 2001.https://bellard.org/otcc/ and at the Internet Archive athttps://web.archive.org/web/20130721162702/http://www.ioccc.org/2001/
  2. ^ab"Tiny C Compiler Reference Documentation".bellard.org. Retrieved7 August 2008.
  3. ^According to the project'sTODO list complex types are the only missing C99 feature. Variable Length Arrays have been added in TCC 0.9.26
  4. ^"TCC : Tiny C Compiler".bellard.org. Retrieved27 March 2023.
  5. ^"tcc - Gentoo wiki".wiki.gentoo.org. Retrieved15 September 2025.
  6. ^Glöckner, Daniel.Re: Tinycc-devel (no subject), 8 September 2006.
  7. ^abgrischka,GCC by TCC (some fixes), 29 September 2005
  8. ^"TCCBOOT: TinyCC Boot Loader".bellard.org. Retrieved27 March 2023.
  9. ^"tinycc-devel (thread)".lists.gnu.org. Retrieved27 March 2023.
  10. ^Wheeler, David A.Countering Trusting Trust through Diverse Double-Compiling. ACSAC.
  11. ^"Guix Further Reduces Bootstrap Seed to 25% — 2020 — Blog — GNU Guix".
  12. ^"Bootstrappable builds".bootstrappable.org. Retrieved29 March 2023.
  13. ^"Cinpy". Archived fromthe original on 20 November 2008. Retrieved27 March 2023.
  14. ^"Super Micro Chess".SourceForge. 18 April 2016. Retrieved27 March 2023.
  15. ^"C compiler".Bun. Retrieved22 November 2024.
  16. ^"TCC : Tiny C Compiler". 4 February 2012. Archived fromthe original on 4 February 2012. Retrieved27 March 2023.
  17. ^"Unofficial tcc Patches".www.dododge.net. Archived fromthe original on 31 March 2007. Retrieved27 March 2023.
  18. ^"Debian -- Details of package tcc in sid".packages.debian.org. Retrieved27 March 2023.
  19. ^grischka,Public Git Hosting for tcc
  20. ^grischka,mob branch for tcc
  21. ^"Tiny C Compiler - Summary [Savannah]".savannah.nongnu.org. Retrieved27 March 2023.
  22. ^"tinycc-devel Archives".lists.gnu.org. Retrieved27 March 2023.
  23. ^"Public Git Hosting - tinycc.git/summary".repo.or.cz. Retrieved27 March 2023.
  24. ^"[Tinycc-devel] TCC version 0.9.27 is out".lists.nongnu.org. Retrieved27 March 2023.

External links

[edit]
Features
Standard library
Implementations
Compilers
IDEs
Comparison with
other languages
Descendant
languages
Designer
Retrieved from "https://en.wikipedia.org/w/index.php?title=Tiny_C_Compiler&oldid=1334539123"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp