Skip to content

Latest commit

 

History

7,901 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goken9cc

goken9cc is a portable, multi-architecture toolchain — C compilers, assemblers, and linkers — together with a minimalist C library, rooted in Ken Thompson's legendary work on the Plan 9 and Inferno operating systems. First extended by Go developers, this toolchain now brings cross-platform support for Linux, macOS, and Windows while preserving the simplicity, elegance, and efficiency of the original Plan 9 tools.

See https://www.youtube.com/watch?v=E3iUpyqKvgk for a presentation of the project.


News

  • Q3 2026 — v0.4 (in progress): a big unification release.
    • imported the arm and x86 toolchains (5a/5c/5l, 8a/8c/8l) from the Principia Softwarica project and fixed the many mismatches against the older kencc-derived variants (kept side by side as 5ak/8ak, etc.)
    • fix native macOS (Mach-O) output for amd64 and arm64 (6l/7l)
    • fix native Windows (PE) output for amd64 and x86 (6l/8l)
    • early WebAssembly backend (ea/ec/el) fully written by Claude Code
    • ported a large batch of 9front fixes (mostly Cinap lenrek work) into the mips and arm64 toolchains (va/vc/vl, 7a/7c/7l)
    • brought up riscv64 for real (it was only commented-out stubs before)
    • self-hosted libc.a derived from Plan 9 libc, built entirely by goken's own compilers with no gcc involved, for every Linux arch this project targets (arm64, amd64, 386, arm, mips, riscv, riscv64), with syscalls declared through a small Go-mksyscall.sh-inspired generator (see tests/c/hello_libc), and extended also to macOS and Windows
    • fixed the arm and mips emulators (5i/vi) so they actually run their Plan 9 hello-world tests
    • much richer test infra: tests now run for many architectures under qemu/Linux, and many operating systems with wine (for Windows) and Node (for wasm) all from Linux CI; also check output against expected.txt instead of just checking the build succeeds; new tests/s/variants and tests/c/variants compare the object files and executables produced by the principia vs. kencc lineages to catch mismatches
    • bootstrapped: you can compile goken using goken on arm64 (7a/7c/7l)
  • Q2 2026 — v0.3: presented goken9cc at IWP9, the International Workshop on Plan 9.
  • Q1 2026 — v0.2: added Plan 9 pcc to compile legacy Unix programs (called APE in Plan 9); started using AddressSanitizer (configure -asan) to catch memory bugs in the toolchain itself; wrote up the project for an IWP9 paper submission.
  • Q4 2025 — v0.1: first working release — a Plan 9-style toolchain (compilers, assemblers, linkers for arm, x86, mips, and early riscv, plus an arm/mips emulator and the acid debugger) able to cross compile Principia Softwarica's own pc/pi operating system targets from Linux and macOS.
  • Q3 2025 — Beta: arm64 and arm32 ELF Linux binaries actually working; imported mk, rc, ed, and other core utilities from Principia Softwarica so the repo is self-contained.
  • Q2 2025 — Alpha: project started — forked the Go repository at its October 2010 commit, refocused on the C toolchain (keeping Go stuff for testing purpose), first (untested) imports of the mips (Plan 9), arm64 (Charles Forsyth), and riscv (Richard Miller) toolchains, first Docker/Nix/CI setup.

goken9cc's direct ancestor is fork-kencc, now deprecated in its favor:

  • 2025 — fork-kencc v0.4: added a Dockerfile and CI.

  • 2024 — fork-kencc v0.3: slow resume of the project with basic CI.

  • 20192024: Hiatus (working on https://semgrep.dev)

  • 2018 — fork-kencc v0.2: got it building also on Linux and Windows.

  • 2014 — fork-kencc v0.1: project started — forked the kencc toolchain from Plan 9 (actually from https://code.google.com/p/ken-cc/ which was forked from inferno which itself derived from Plan 9), keep just the x86 and arm toolchains, got it building on macOS, and did a big code reorganization.

See changes.txt for the detailed changelog.


Features

  • Portable: It can build on Linux, macOS, and Windows (WSL, Cygwin) (TODO Plan 9 and xv6) using gcc or clang or a bootstrapped version of itself, on 32 bits or 64 bits machines
  • Multi-OS support: Link C and assembly programs that can run on Linux, macOS, Windows, and Plan 9 (TODO xv6)
  • Multi-architecture support: Build C and assembly programs targeting the 386 (a.k.a. x86), amd64 (a.k.a. x86_64), arm, arm64 (a.k.a. aarch64), riscv (a.k.a. riscv32), riscv64, and mips architectures, plus experimental WebAssembly (wasm) support
  • Cross-compilers: Build C programs targeting different platforms from different platforms (e.g., you can build from a Linux x86 machine a binary for macOS arm64)
  • Compact and efficient: A lightweight compiler toolchain designed for speed and simplicity.
  • Heritage: Based on the Plan 9 and Inferno OS compilers developed by Ken Thompson and others.
  • Go-era improvements: Enhanced and extended by contributors from the Go language community for multi-platform support.
  • Open and extensible: Designed to be easy to understand, modify, and integrate into new projects, thanks to its reasonable size and the use of Literate programming, which explains the code in depth (see https://principia-softwarica.org); it takes more than a license to make code truly open.

Getting Started

Building from source

git clone https://github.com/aryx/goken9cc.git
cd goken9cc
./configure
./scripts/build-mk.sh
./scripts/promote-mk.sh
. env.sh
mk
mk install

You can also play with the $ostype and $objtype environment variables for cross compiling.


Architecture Naming Convention

goken9cc, like Plan 9, uses single-character codes for architectures. Each tool is prefixed with this code:

Code Arch Compiler Assembler Linker Object ext
5 arm 5c 5a 5l .5
6 amd64 6c 6a 6l .6
7 arm64 7c 7a 7l .7
8 x86 (386) 8c 8a 8l .8
e wasm ec ea el .e
i riscv ic ia il .i
j riscv64 jc ja jl .j
v mips vc va vl .v

Pipeline: .c → compiler (Xc) → assembler (Xa) → linker (Xl) → X.out


History

This repository was originally a fork of the assemblers, linkers, and C compilers as well as supporting libraries (e.g., lib9, libmach, pkg/runtime) in the Go repository in October 2010 at this precise commit: https://github.com/golang/go/commit/99a10eff16b79cfb8ccf36e586532a40b17a203c (see pad.org for an explanation of why I forked at this precise commit).

The C toolchain that was part of the Go repository was actually itself a fork of the "kencc" toolchain in inferno-os at https://github.com/inferno-os/inferno-os (in the utils/ subdirectory) as well as code from the plan9port https://github.com/9fans/plan9port which both were themselves forks of the kencc toolchain in the plan9 operating system at https://github.com/plan9foundation/plan9

The main improvements in the Go repository to the C toolchain compared to the original kencc toolchain in Plan 9 were the support for other operating systems such as Linux, macOS, and Windows (and not just Plan9), with the management of binary formats such as ELF (for Linux), machO (for macOS), and PE (for Windows) as well as the management of syscalls to those different operating systems. Another nice improvement was the support for the DWARF debugging format so the generated binaries could be debugged using gdb (instead of just the Plan9 acid debugger).

This fork was then further extended to add more architectures such as arm64 (thanks to the work of Charles Forsyth) and riscv (thanks to the work of Richard Miller) that were not in the Go repo but scattered around in "kencc-derived" repositories.

More work was done then to make all of this work together, to support the latest Linux, macOS, and Windows to reach a point where one could use goken9cc to compile goken9cc itself on many architectures and many operating systems.

AI disclaimer

95% of the code in goken9cc was written by humans (mostly Ken Thompson, Rob Pike, Charles Forsyth, Richard Miller, and other Plan 9 contributors), and for the most part written more than 30 years ago. What I did was essentially to package those old toolchains together and then use AI to write the remaining 5% so that the toolchains could work not just on Plan 9 for Plan 9 but also on and for Linux, macOS, and Windows (imitating for the most part what was done by Go developers for the Go language).

All the clerical work of finding the right syscall numbers for each architecture and operating systems for the multiplatform C library in goken9cc (see lib_core/libc/{arch,syscall,os}) was done by Claude Code, inspired by what Go developers did for Go (see the GO/pkg/{syscall,runtime} directories).

The entire wasm backend was written by Claude Code.

Most of the architecture and operating system bugfixes were done by Claude Code.

Most of the code written by AI is clearly marked with a special claude: comment at the front and part of a commit authored by Claude code. You can use the scripts/ai_percentage.py to get authorship LOC statistics across the different directories in goken9cc.


Environment variables

build time: objtype ostype

run time: for all: GOROOT (used for "#9/..." paths) for mk: MKSHELL for rc: RCMAIN for yacc: YACCPAR

About

goken9cc — A portable, multi-architecture toolchain (C compilers, assemblers, and linkers) rooted in Ken Thompson's Plan 9 and Inferno toolchains, extended by Go developers to also support Linux, macOS, and Windows.

Resources

Stars

25 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages