
Tiny C Compiler - sndean
http://bellard.org/tcc/
======
buserror
I'm a HUGE fan of TCC -- I've recently added a pretty cool feature to simavr:
a way to translate the whole AVR core into 'C' and JIT compile it using libtcc
(the backend of tcc).

Result is amazing speed for emulation!

[https://github.com/buserror/simavr/tree/jit-
wip](https://github.com/buserror/simavr/tree/jit-wip)

~~~
marktangotango
That's awesome, can you give a quick rundown here, or have you blogged about
it? One question I have is around symbol resolution. Can the in memory piece
of tcc compiled code see all the symbols in your program (ie the host exe) for
example?

~~~
buserror
I haven't posted about it yet, as I wanted to clean up the branch before I do,
and I ran out of time; work to catch up and so on :-)

libtcc is /massively/ clever, it will 'link back' to your (exported) ELF
symbols automatically. Basically it links the piece of code to your current
running process, with all it's libs etc.

So if you have a function blob(int); in your main program, just call it from
the C you generate, and it'll Just Works.

For my own purpose, I decided to trim down the headers I would have to include
in the generated C and made some sort of simpler 'trampoline', but it's not
strictly necessary.

------
dwheeler
Tiny C compiler (tcc) is really cool. I used it as a test case in my diverse
double-compiling (DDC) work to counter the trusting trust attack:
[http://www.dwheeler.com/trusting-trust/](http://www.dwheeler.com/trusting-
trust/)

There has been some continued development of tcc; the GitHub repository here
has changes through April 2016:
[https://github.com/TinyCC/tinycc](https://github.com/TinyCC/tinycc)

~~~
cygx
The github repo is just a mirror, development happens on repo.or.cz [1]

[1] [http://repo.or.cz/tinycc.git](http://repo.or.cz/tinycc.git)

~~~
kzrdude
Eh what, on the mob branch? Master untouched for three years.

~~~
cygx
Mob is the main development branch, open to all. Master is the release branch,
and as no release has been cut for a couple of years, it is indeed rather
stale.

 _edit:_ If you want to get an idea about what happens in TCC-land, you should
check out the mailing list archives [1], eg a recent-ish status update [2].

[1] [http://lists.nongnu.org/archive/html/tinycc-
devel/](http://lists.nongnu.org/archive/html/tinycc-devel/)

[2] [http://lists.nongnu.org/archive/html/tinycc-
devel/2016-11/ms...](http://lists.nongnu.org/archive/html/tinycc-
devel/2016-11/msg00032.html)

------
drtse4
For those who missed it like me, Fabrice just released a RISC-V emulator, HN
discussion here:
[https://news.ycombinator.com/item?id=13210711](https://news.ycombinator.com/item?id=13210711)

~~~
FullyFunctional
Now there's a fun little Xmas break project: port tinycc to RISC-V. I don't
expect it to be too hard. Extra credit for using the compressed instruction
where possible.

------
kashyapc
Related: Based on the Tiny C Compiler, a demo program ('TCCBOOT', also from
Fabrice) mentioned in the "News" section in the URL from the OP was part of
the QEMU Advent calendar:

    
    
      http://www.qemu-advent-calendar.org/2016/#day-16

~~~
agumonkey
I looked at the source thinking I could port it to newer kernels but .. alas
it's way above my level.

~~~
satysin
Perhaps it is above your level today but why not give it a shot anyway? You
won't get to that level without pushing yourself.

~~~
agumonkey
I gave it a shot, and it was way above my head. tccboot involves kernel
trickery that Belliard himself wrote as not safe at all and just there to make
it run a bit. I'm not even kernel developper level, I have no idea how I could
migrate this to linux 3.x or 4.x.

~~~
kashyapc
/me nods. While preparing that QEMU Advent image, I spent little (admittedly
too little) time to see if I can get newer Kernels work with TCC, and quickly
came to a somewhat similar conclusion. (While also realizing limits on my
abilities - not a Kernel developer either).

Also a quick look at the upstream tinycc-devel list tells me that, a patched
2.4.26 Kernel (32 bit) was still the latest compatible version with TCC --
[https://lists.nongnu.org/archive/html/tinycc-
devel/2015-11/m...](https://lists.nongnu.org/archive/html/tinycc-
devel/2015-11/msg00071.html)

~~~
agumonkey
brohug

------
faragon
Please add "(2013)" to the title.

TCC is an amazing project, and very useful, as there are few multiplatorm "C99
enough" compliant compilers. Also, it is suitable for using C as scripting
language (!)

P.S. Fabrice Bellard is a genius.

------
spc476
I've been using TCC for a few years, and even wrote a Lua module
([https://github.com/spc476/lua-
conmanorg/blob/master/src/tcc....](https://github.com/spc476/lua-
conmanorg/blob/master/src/tcc.c)) for it. I used that to write another Lua
module to load modules written in C directly from source
([https://github.com/spc476/lua-
conmanorg/blob/master/lua/cc.l...](https://github.com/spc476/lua-
conmanorg/blob/master/lua/cc.lua)). I still consider this use more for
experiments than production level.

I've also used it to get something like closures for C.

------
jamesu
I experimented with using TCC as an experimental native code compilation
backend for a scripting language. Was pretty impressed how easy it was to
embed compared to some other solutions I tried.

~~~
chubot
Interesting, did your scripting language compile to C first? I'd be interested
to see how you integrated TCC if it's available.

~~~
buserror
Check my other post: I've recently made a Atmel AVR translator to C and JIT
compile it with libtcc. It's actually pretty trivial!

[https://github.com/buserror/simavr/tree/jit-
wip](https://github.com/buserror/simavr/tree/jit-wip)

------
justinsaccount
I used TCC a lot back in 2003 or so for schoolwork. I had an ancient pentium 1
thinkpad someone had given me that I used for all my programming assignments.
TCC compile times were basically instantaneous for simple C programs, I
remember using the `tcc -run` hasbbang feature too.

~~~
agumonkey
As mentioned above, there's tccboot which is live from source linux. It took
between 5 and 10 seconds on my centrino laptop...

------
fithisux
It is a pitty that qcc (tcc + qemu codegen) never took off.

