Native Cortex-M3 size gate
Measured 2026-11-23 from bc29445 on macOS with both stage0 and self-hosted
compilers, using Arm GNU size 2.44.0.20250616. Both produced the same sizes in
bytes. Reproduce with python3 bench/size_mcu.py after building the compilers;
--json FILE saves machine-readable results. Pass compiler paths to select
one or more explicitly. sh scripts/mcu-size.sh measures and enforces the gate.
The native ELF contains a vector table, startup, and semihosting support; it is
for QEMU mps2-an385, not qualified board firmware.
| Program | ELF bytes | .text | .rodata | .data | .bss | Flash | Static RAM |
|---|---|---|---|---|---|---|---|
| arithmetic | 12156 | 2438 | 1335 | 0 | 0 | 3773 | 0 |
| blinky | 9284 | 470 | 60 | 0 | 0 | 530 | 0 |
| empty | 8868 | 140 | 0 | 0 | 0 | 140 | 0 |
| fib | 9612 | 708 | 174 | 0 | 0 | 882 | 0 |
| hello | 8892 | 152 | 19 | 0 | 0 | 171 | 0 |
| overflow | 9156 | 408 | 49 | 0 | 0 | 457 | 0 |
Flash is .text + .rodata + .data; static RAM is .data + .bss.
ELF headers, non-loadable metadata, stack and heap are excluded from both totals.
ELF bytes are reported for inspection only, not used as a budget. These totals
are not full board memory requirements; stack usage is not measured.
Budgets and regression rule
Budgets are bytes, with roughly 15% flash headroom rounded upward and 32 bytes
of static RAM headroom. bench/size_mcu_budgets.json is the gate's authoritative
baseline and budget. Each compiler and each program must fit both budgets;
exceeding either fails. Growth strictly greater than 5% over the recorded flash
or static RAM baseline warns, even when within budget. Any positive static RAM
use warns against the current zero baseline. New fixtures require explicit
baseline and budget entries; missing or extra entries fail the gate. Baselines
and budgets should change only with a reviewed explanation of the size change.
| Program | Flash budget | Static RAM budget |
|---|---|---|
| empty | 165 | 32 |
| hello (semihosting) | 200 | 32 |
| fib | 1020 | 32 |
| blinky | 610 | 32 |
| arithmetic | 4350 | 32 |
| overflow | 530 | 32 |
C -Os comparison
M4-SIZES.md reports Cortex-M3 flash of 4 bytes for empty, 39 for hello,
14 for blinky and 140 for sieve. The corresponding Kern measurements are
140, 171 and 530 bytes for empty, hello and blinky (35×, 4.38× and 37.86×),
respectively. These are illustrative, not equivalent workload ratios:
C has no vectors or startup; its hello writes unpaced to a placeholder UART,
while Kern uses semihosting with a different string; C blinky toggles a GPIO
forever, while Kern prints a bounded counter. C reserves 1024 stack bytes,
whereas the static RAM metric here excludes stack. There is no matching C
reference for Kern's iterative fib, arithmetic, or overflow, and no matching
Kern sieve. The 1.5× C target in the plan cannot be fairly gated by these
mismatched fixtures. The budgets above guard the current native examples,
including their startup and runtime, until matched workloads exist.