Skip to content

Ported the Tiny C Compiler - #182

Merged
FlareCoding merged 7 commits into
masterfrom
pr/tcc-compiler-port
Sep 1, 2026
Merged

Ported the Tiny C Compiler#182
FlareCoding merged 7 commits into
masterfrom
pr/tcc-compiler-port

Conversation

@FlareCoding

@FlareCoding FlareCoding commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Ported tinycc (mob, 2ba12e83) as a userland app with x86_64 and arm64
    backends, defaulting to static ET_EXEC output since the kernel loader
    has no dynamic linking. Both tcc file.c -o out and tcc -run work
    on both architectures.
  • Staged an on-target compile environment (musl headers, libc.a, crt
    start files, libtcc1.a merged with the compiler-rt builtins) into
    /usr on the initrd via the existing rootfs overlay (+4.6 MB).
  • Fixed two aarch64 kernel gaps : trapped EL0 system instructions now
    die with SIGILL instead of panicking the kernel, and SCTLR_EL1.UCT/UCI
    now permit EL0 cache maintenance.

Note

Medium Risk
Kernel paging and EL0 trap handling change privileged configuration and fault dispatch; the bulk of the diff is a large vendored compiler tree with lower direct kernel risk.

Overview
Adds on-target Tiny C Compiler (TCC) as a userland app: vendored upstream snapshot, cross-build for x86_64 and arm64, static tcc binary, and a rootfs overlay (/usr/lib/tcc, musl headers/libs, libtcc1.a with compiler-rt builtins) so tcc -o and tcc -run work without dynamic linking.

AArch64 kernel changes support JIT-style code generation from EL0: paging enables SCTLR_EL1 UCT/UCI so userspace can read CTR_EL0 and run cache maintenance (dc cvau / ic ivau). The EL0 sync trap path recognizes EC_MSR_MRS and delivers SIGILL to the process instead of a kernel fatal trap.

Reviewed by Cursor Bugbot for commit d25ac42. Bugbot is set up for automated code reviews on this repo. Configure here.

Stellux userland had no way to compile programs on the target. Tcc is
small enough to run there and its built-in linker emits the static
ET_EXEC ELF executables the kernel loader accepts, with no fork or
external toolchain needed. The sources are a pinned snapshot of
upstream tinycc (mob branch, 2ba12e83) trimmed to the one-source build
of the x86_64 and arm64 backends, the libtcc1 runtime for both, and
the compiler's private headers. Other target backends, non-ELF output
formats, and the backtrace runtime are omitted.
Compiling on target needs more than the compiler binary: programs
link against musl, the crt start files, and tcc's own runtime
archive. The libtcc1 objects are cross-built per architecture and
merged with the compiler-rt builtins, since musl printf depends on
soft fp128 helpers on aarch64 and tcc only links libtcc1
automatically. The headers, libraries, and start files ride the
existing rootfs overlay into /usr on the initrd, with the libc++ and
kernel UAPI header trees left out because the target provides
neither. The environment adds 4.6 MB to the image.
A userland instruction that traps as a system register or system
instruction access, such as a cache maintenance op the SCTLR
configuration forbids, fell through to the fatal trap path and
panicked the kernel. A process must never be able to take down the
kernel, so this class now dies with SIGILL like other undefined
instruction traps.
Code generators running as regular processes must flush freshly
written instructions to the point of unification before executing
them, and the dc cvau, ic ivau, and CTR_EL0 reads this requires are
undefined at EL0 unless SCTLR_EL1 permits them. UCT and UCI are set
on the BSP during paging init, and APs inherit them through the SMP
startup block.
Deleting the previously staged include tree in place intermittently
failed on macOS hosts when the tree had just been written, aborting
the userland build. The stale tree is now renamed aside, which is
atomic, and the renamed copy is deleted where a partial failure
cannot corrupt the freshly staged environment.
@FlareCoding
FlareCoding merged commit 9b6604f into master Sep 1, 2026
19 checks passed
@FlareCoding
FlareCoding deleted the pr/tcc-compiler-port branch September 1, 2026 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant