Tiny C Compiler
   HOME

TheInfoList



OR:

The Tiny C Compiler, TCC, tCc, or TinyCC is a
x86 x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. Th ...
(32-bits),
X86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
and ARM processor C
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
initially written by Fabrice Bellard. It is designed to work for slower computers with little disk space (e.g. on rescue disks).
Windows Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
operating system support was added in version 0.9.23 (17 June 2005). TCC is distributed under the
GNU Lesser General Public License The GNU Lesser General Public License (LGPL) is a free-software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate a software component released under the LGPL into their own ...
. TCC claims to implement all of
ANSI C ANSI C, ISO C, and Standard C are successive standards for the C programming language published by the American National Standards Institute (ANSI) and ISO/IEC JTC 1/SC 22/WG 14 of the International Organization for Standardization (ISO) and the ...
(C89/C90), much of the C99 ISO standard, 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 Memory footprint refers to the amount of main memory that a program uses or references while running. The word footprint generally refers to the extent of physical dimensions that an object occupies, giving a sense of its size. In computing, t ...
allow it to be used directly from a single 1.44 M
floppy disk A floppy disk or floppy diskette (casually referred to as a floppy, a diskette, or a disk) is a type of disk storage composed of a thin and flexible disk of a magnetic storage medium in a square or nearly square plastic enclosure lined with a ...
, 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. As of 2023, the "mob" development branch also includes support for
RISC-V RISC-V (pronounced "risk-five") is an open standard instruction set architecture (ISA) based on established reduced instruction set computer (RISC) principles. The project commenced in 2010 at the University of California, Berkeley. It transfer ...
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 Register or registration may refer to: Arts, entertainment, and media Music * Register (music), the relative "height" or range of a note, melody, part, instrument, etc. * ''Register'', a 2017 album by Travis Miller * Registration (organ), ...
values are written back to the
stack Stack may refer to: Places * Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group * Blue Stack Mountains, in Co. Donegal, Ireland People * Stack (surname) (including a list of people ...
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). 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 In compiler optimization, register allocation is the process of assigning local automatic variables and Expression (computer science), expression results to a limited number of processor registers. Register allocation can happen over a basic bloc ...
, which prevents many extraneous save/load pairs inside a single statement. Here are two benchmark examples: #A recursive
Fibonacci Leonardo Bonacci ( – ), commonly known as Fibonacci, was an Italians, Italian mathematician from the Republic of Pisa, considered to be "the most talented Western mathematician of the Middle Ages". The name he is commonly called, ''Fibonacci ...
algorithm on a 1.8 GHz Intel Centrino laptop with 512 MB
RAM Ram, ram, or RAM most commonly refers to: * A male sheep * Random-access memory, computer memory * Ram Trucks, US, since 2009 ** List of vehicles named Dodge Ram, trucks and vans ** Ram Pickup, produced by Ram Trucks Ram, ram, or RAM may also ref ...
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. #A test compared different C compilers by using them to compile the
GNU C Compiler The GNU Compiler Collection (GCC) is a collection of compilers from the GNU Project that support various programming languages, hardware architectures, and operating systems. The Free Software Foundation (FSF) distributes GCC as free software ...
(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, a
hack Hack may refer to: Arts, entertainment, and media Games * Hack (Unix video game), ''Hack'' (Unix video game), a 1984 roguelike video game * .hack (video game series), ''.hack'' (video game series), a series of video games by the multimedia fran ...
where TCC loads and boots a
Linux kernel The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
from source in about 10 seconds. That is to say, it is a "
boot loader A bootloader, also spelled as boot loader or called bootstrap loader, is a computer program that is responsible for booting a computer and booting an operating system. If it also provides an interactive menu with multiple boot choices then it's o ...
" that reads Linux kernel
source code In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer. Since a computer, at base, only ...
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. * TCC was used to demonstrate a defense against the trust attack. It is also used in GNU Guix in an attempt to make the distribution bootstrapable without using any binary. * Cinpy is a Python
library A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
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 JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
Linux (also by Bellard). * Has been used as a reference for the compiled version of the Super Micro-Max Chess program source. * Bun, the JavaScript runtime, uses TCC to expose an API which allows users to compile and run C programs from JavaScript.


History

TCC has its origins in the Obfuscated Tiny C Compiler (OTCC), a program Bellard wrote to win the
International Obfuscated C Code Contest The International Obfuscated C Code Contest (abbreviated IOCCC) is a computer programming contest for Source code, code written in C (programming language), C that is the most creatively obfuscated code, obfuscated. Held semi-annually, it is desc ...
(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. Since Bellard's departure from the project, various people and groups have distributed patches or maintained
forks In cutlery or kitchenware, a fork (from 'pitchfork') is a Eating utensil, utensil, now usually made of metal, whose long handle terminates in a head that branches into several narrow and often slightly curved tine (structural), tines with whic ...
of TCC to build upon or fix issues with TCC. This includes Dave Dodge's collection of unofficial tcc patches,
Debian Debian () is a free and open-source software, free and open source Linux distribution, developed by the Debian Project, which was established by Ian Murdock in August 1993. Debian is one of the oldest operating systems based on the Linux kerne ...
and kfreebsd downstream patches, and grischka's gcc patches.grischka
GCC by TCC (some fixes)
29 September 2005
Grischka also set up a public
Git Git () is a distributed version control system that tracks versions of files. It is often used to control source code by programmers who are developing software collaboratively. Design goals of Git include speed, data integrity, and suppor ...
repository for the project that contains a mob branch where numerous contributions, including a shared build,
cross-compiler A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a PC but generates code that runs on Android devices is a cross compil ...
s, and SELinux compatibility were added. Grischka's GIT repository later became the official TCC repository (linked to by Fabrice Bellard's Savannah project page ).


Current status

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


See also

*
GNU Compiler Collection The GNU Compiler Collection (GCC) is a collection of compilers from the GNU Project that support various programming languages, Computer architecture, hardware architectures, and operating systems. The Free Software Foundation (FSF) distributes ...
*
Portable C Compiler The Portable C Compiler (also known as pcc or sometimes pccm - portable C compiler machine) is an early compiler for the C programming language written by Stephen C. Johnson of Bell Labs in the mid-1970s, based in part on ideas proposed by Alan ...
(PCC) *
LCC (compiler) LCC ("Local C Compiler" or "Little C Compiler") is a small, retargetable compiler for the ANSI C programming language. Although its source code is available at no charge for personal use, it is not open-source software, open-source or free softw ...
*
Small-C Small-C is both a subset of the C programming language, suitable for resource-limited microcomputers and embedded systems, and an implementation of that subset. Originally valuable as an early compiler for microcomputer systems available during t ...
* Small Device C Compiler (SDCC)


References


External links

*
TCC's active mailing listSource code repositoryPTSource IDE
Integrated Development Environment An integrated development environment (IDE) is a Application software, software application that provides comprehensive facilities for software development. An IDE normally consists of at least a source-code editor, build automation tools, an ...
includes TCC. {{CProLang C (programming language) compilers Free and open source compilers Free software programmed in C Software using the GNU Lesser General Public License Assembly language software