Kern
On this page

M4a: freestanding C -Os size baselines

Measured 2026-11-23 on macOS. All sizes are bytes. These are size-only images, not runnable firmware: main is the link entry, with no reset handler, vector table, data initialization or BSS clearing. The placeholder UART and GPIO addresses are not a board definition. No QEMU or execution is involved.

Reproduce

export PATH="/opt/homebrew/opt/llvm/bin:/opt/homebrew/bin:$PATH"
sh scripts/mcu/c-size.sh

Tool versions: Arm GNU Toolchain 14.3.Rel1 GCC 14.3.1 20250623; Homebrew clang 23.1.6; Homebrew LLD 23.1.6; Arm GNU Toolchain 14.3.Rel1 GNU size 2.44.0.20250616. The script checks all four tools. For each program empty, hello, blinky, sieve, the exact compile/link commands are the following, with $program and $elf substituted (the script uses a temporary directory for $elf):

arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Os -ffreestanding -fno-builtin -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -nostdlib -Wl,--gc-sections -Wl,-T,scripts/mcu/c-reference/size.ld "scripts/mcu/c-reference/$program.c" -o "$elf"
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -Os -ffreestanding -fno-builtin -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -nostdlib -Wl,--gc-sections -Wl,-T,scripts/mcu/c-reference/size.ld "scripts/mcu/c-reference/$program.c" -o "$elf"
clang --target=riscv32-unknown-elf -march=rv32imac -mabi=ilp32 -fuse-ld=lld -Os -ffreestanding -fno-builtin -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -nostdlib -Wl,--gc-sections -Wl,-T,scripts/mcu/c-reference/size.ld "scripts/mcu/c-reference/$program.c" -o "$elf"
arm-none-eabi-size -A "$elf"

The script sums .text + .rodata + .data as flash and .data + .bss + .stack as static RAM. The linker reserves 1,024 bytes in .stack and aligns .bss to eight bytes; this reservation is an assumption, not measured peak stack usage or a proof that recursive Fibonacci fits. .data is empty for all these images. Debug/non-allocated metadata is excluded. There is no libc, newlib startup, printf, heap, vector table, interrupt code, clock setup or real UART driver.

Measurements

TargetProgram.text.rodata.data.bssStackFlashRAM
Cortex-M3empty4000102441024
Cortex-M3hello2415001024391024
Cortex-M3blinky140001024141024
Cortex-M3sieve14000411210241405136
Cortex-M4F, soft floatempty4000102441024
Cortex-M4F, soft floathello2415001024391024
Cortex-M4F, soft floatblinky140001024141024
Cortex-M4F, soft floatsieve14000411210241405136
RV32IMACempty4000102441024
RV32IMAChello3415001024491024
RV32IMACblinky140001024141024
RV32IMACsieve17200411210241725136

Candidate Kern budgets

The M4 plan calls for code size within 1.5× C -Os. The flash targets below apply ceil(1.5 × flash) to this stripped-down corpus. The RAM column is a separate provisional planning allowance using the same multiplier; the plan does not establish a 1.5× RAM rule. These are comparison targets, not board-ready firmware limits or replacements for the existing example budgets. A fair gate must use matching workloads, stack reservations and runtime boundaries. In particular, comparing an ELF with mandatory startup to this startup-free baseline would charge Kern for functionality absent in C.

TargetProgramCandidate flashProvisional RAM
Cortex-M3empty61536
Cortex-M3hello591536
Cortex-M3blinky211536
Cortex-M3sieve2107704
Cortex-M4F, soft floatempty61536
Cortex-M4F, soft floathello591536
Cortex-M4F, soft floatblinky211536
Cortex-M4F, soft floatsieve2107704
RV32IMACempty61536
RV32IMAChello741536
RV32IMACblinky211536
RV32IMACsieve2587704

Comparability

  • Empty is a bare function; even its 1 KiB RAM is solely the arbitrary stack reservation. Real firmware needs startup and often vectors.
  • Hello performs unpaced writes to a placeholder register; it omits actual UART setup, status polling and semihosting. Blinky toggles a placeholder register without SysTick or delay, so it is not the plan's blinky + SysTick.
  • Sieve follows the same sieve and recursive Fibonacci algorithms as bench/sieve.c, but uses 4,096 static bytes rather than 50 million heap bytes, 32-bit rather than 64-bit values, fib(20) rather than fib(38), and volatile result stores rather than formatted output. Its code and RAM are therefore not directly comparable to that hosted benchmark. A Kern comparison must match these exact choices; its MCU recursion policy also needs to permit this workload or use a separately specified equivalent.

Source: M4-SIZES.md in the repository.