small self hosting C compiler
C Makefile Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test Tests for pointer arith Dec 4, 2015

A small, fast C compiler suite.

Join the chat at

  • Small.
  • Fast.
  • Consistent.
  • High quality.
  • Low complexity.
  • No dependencies.
  • No fussy configuration.
  • Painless cross compiling.
  • Just work.

You should be able to get a C compiler, assembler, linker and libc for any supported target in less than 30 seconds.


Requires an external C compiler and gnu binutils (for now), and I have only tested it on linux 64 bit so far.

The code does use anonymous union extensions, so your compiler will need to support them too.

$ make


$ make test
$ make selfhost # self hosting


Stage 1.

Self hosting x86_64, dumb backend.

Stage 2.

Self hosting arm, something like raspberry pi/android.

Stage 3.

Build small clean C code bases like 8cc, tcc, sbase.

Stage 4.

Build musl libc.


  • Build more programs.
  • Replace gnu as with our own assembler.
  • Replace ld with our own static linker.
  • Build OS kernels.
  • SSA backend.


Pre stage 2. Self hosting with lots of missing common cases. Though technically these bugs can be fixed with the compiler itself :). It uses it's own stubbed out headers and cannot correctly process system headers yet (Help wanted).


Contributors welcome, preferrably discuss on gitter before starting something. Even contributing self contained test cases is useful.

Code layout

  • Libraries are in src/*
  • Commands are in src/cmd/*

If you are unsure about the purpose of a library, check the header which should give a short description.

Code style

Follow Plan9 style conventions. Headers are not allowed to include other headers to eliminate circular dependencies and increase build speed. src/u.h is the only exception to this rule.

Bug fixes and issues

Try and attach a single source file which exibits your issue. If possible reduce the test case by hand until it is as small as possible.

Try and follow the general template changed where needed:

What are you trying to do:
What you expected to happen:
What actually hapened:

Try and add a small self contained file which reproduces the issue.

In general each bug fix or change should add a test file which triggers the bug.

Memory management

The compiler does not explicitly free memory. Peak memory usage while self hosting is approximately 2Mb, so it should not be an issue, even for planned targets/hosts like the raspberry pi.

This actually simplifies the code and probably makes it faster because allocations can be pointer bumps.

Useful Links