Ported the Tiny C Compiler - #182
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
backends, defaulting to static ET_EXEC output since the kernel loader
has no dynamic linking. Both
tcc file.c -o outandtcc -runworkon both architectures.
start files, libtcc1.a merged with the compiler-rt builtins) into
/usr on the initrd via the existing rootfs overlay (+4.6 MB).
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
tccbinary, and a rootfs overlay (/usr/lib/tcc, musl headers/libs,libtcc1.awith compiler-rt builtins) sotcc -oandtcc -runwork without dynamic linking.AArch64 kernel changes support JIT-style code generation from EL0: paging enables SCTLR_EL1
UCT/UCIso userspace can readCTR_EL0and run cache maintenance (dc cvau/ic ivau). The EL0 sync trap path recognizesEC_MSR_MRSand 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.