0%

s07 — Runtime Bootstrap: Minimal ori_rt Surface

Goal

The minimal runtime surface a trivial native binary needs is emit-able and linkable: entry-point wrapping via ori_run_main, panic, print, and basic RC declarations — proven by an AOT smoke harness that compiles, links, and runs a hello-class program END-TO-END on the host (using a hand-assembled object until s08 supplies real isel).

Implementation Sketch

  • Runtime symbol declaration table in ori_backend mirroring the SSOT at ori_llvm/src/codegen/runtime_decl/runtime_functions.rs (~100 fns) — but ONLY the bootstrap subset declared/emittable now: ori_run_main(fn_ptr)->i32, ori_panic/ori_panic_cstr (C-unwind, noreturn), ori_print/ori_print_int/ori_print_bool/ori_print_float, ori_rc_inc/ori_rc_dec/ori_rc_alloc/ori_rc_free, ori_args_from_argv/ori_args_cleanup, ori_check_leaks. Long-term SSOT decision: extract a backend-neutral runtime-declaration table both backends consume (DRIFT guard) — record as decision; implement the extraction when s12 widens the surface.
  • Attribute fidelity from day one: nounwind vs C-unwind subset honored exactly (ori_panic/ori_panic_cstr/ori_rc_dec_unwind/ori_list_get/assert family unwind; everything else nounwind); c_char per-target width discipline (i8 x86-64 / u8 aarch64); V5 header + immortal sentinel semantics documented in the table.
  • Entry-point wrapper: main(argc, argv) -> args setup -> ori_run_main(_ori_main) -> exit code; mirrors ori_llvm entry_point shape.
  • AOT smoke harness: drives object emission (via the object crate writing a hand-constructed function until s08) + system link against libori_rt.a (RuntimeConfig::detect()), runs the binary, asserts stdout + exit code. The harness IS the s08 pathfinder’s test bed.

Test Strategy

  • Smoke matrix: {hello print, exit-code-only, panic-exits-nonzero, ORI_CHECK_LEAKS=1 clean} on host.
  • Semantic pin: panic path returns the canonical panic exit status and message on stderr (matches LLVM-backend behavior — parity-pinned against an LLVM-built twin binary).
  • Negative pin: declaring a bootstrap fn with the wrong unwind attribute fails the declaration-table consistency test (table vs runtime_functions.rs cross-check).

Work Items

  • Bootstrap runtime declaration table (subset, attribute-faithful, c_char-correct) + consistency cross-check test against runtime_functions.rs; SSOT-extraction decision recorded.
  • Entry-point wrapper generation (main -> ori_run_main) via the object-crate emit path (hand-assembled until s08 isel lands).
  • AOT smoke harness: object-crate emission of a minimal function, system link via RuntimeConfig::detect(), run + assert stdout/exit-code.
  • Smoke matrix green incl. panic parity pin vs an LLVM-built twin + leak-check clean.