r/Compilers • u/dom_aley • Oct 17 '26
Mucc: a self hosting C compiler in one static binary, with its own assembler, linker and musl (x86-64 and ARM64 Linux)
Mucc is a small C compiler for Linux that ships as a single 8.5 MB static file. The preprocessor, assembler, linker, archiver, headers and C library (musl, like zig cc does) are all built in, so you can drop it into an empty container, an old distro or a Raspberry Pi and build C with nothing else installed: no gcc, no binutils, no system headers.
Programs it builds are static, so they run on any x86-64 Linux. There's a native ARM64 build too, and it can cross-compile between the two.
The whole project actually started as a fork of Rui Ueyama's chibicc. I felt more could be done on this design. So now Mucc adds its own assembler and linker, an ARM64 backend, register allocation, the bundled musl, DWARF debug info, C23 support and a reproducible bootstrap chain.
What’s actually working so far
- C17 by default, C23 with `-std=c23`, plus the GNU extensions real code uses
- Self-hosting: each release is built by the one before it, and a Mucc-built Mucc produces byte-identical output
- Real projects build and pass their own test suites: SQLite, Lua, zlib, jq, Redis and Tcl with the bundled musl; CPython and Git with the system glibc
- Same ABI as gcc, so objects from either link together
- Compiles its own 33k lines in 0.46 s (gcc -O0: 1.22 s, gcc -O2: 5.35 s)
What’s currently not working, it does no optimization beyond register allocation and constant folding, so programs run about as fast as gcc -O0. No C++, Linux only. For performance-critical code, use gcc or clang.
If you've got C code it chokes on, or a use for it I haven't thought of, I'd like to hear it.
GitHub: https://github.com/Dom-Yan/Mucc
Website: https://dom-yan.github.io/Mucc/
Thanks to Rui Ueyama for chibicc, and to Fabrice Bellard, whose TinyCC showed how much a small compiler can do.
4
u/kostya27 Oct 17 '26
how this is better/worse than tcc?
2
u/No_Pianist1870 Oct 17 '26
Why can't musl support dlopen ?
2
u/Serious_Pin_1040 Oct 17 '26
I really like it. Three questions:
1, Is it single pass? 2, Performance being 50% of gcc with -O2, do you know what you could do to improve that? 3, Does it handle linker scripts?
1
u/[deleted] Oct 17 '26
That is quite an impressive spec, even with those limitations. How long did it take?
Binary Size I like self-contained products like this! But 8.5MB is quite hefty: is most of that those bundled libraries?
Compilation Speed (This is my special interest!) You mention a build-time for one project of 100Klps, which was only 50% faster than Clang-O0.
Is that the self-compiled version, or optimised via another compiler? Either way, it doesn't strike me as fast. On my machine (which benchmarks at 1700 compared to your 2700). a fast C compiler can manage 500-1000Klps.
So what is causing it to be slow? (For clang and gcc, those are just massive, complex products.)