Skip to content

4.4 Self-Hosting & Cross-Compilation #34

Description

@Mathnerd314

Function: Produce a compiler for the language written in the language itself, verifiable via multi-stage bootstrap (stage-0 → stage-1 → stage-2, byte-for-byte fixpoint check). Cross-compilation is the compiler instantiated with a different target triple. Seed maintenance mitigates "Trusting Trust" attacks. Goal is to compile itself for arbitrary targets without an external host compiler. dev

Inputs:

  • Source of the eight core Futamura artifacts written in the language itself ((i), (s), (c), (g_p), (n), (r), (b), plus residual program machinery).
  • A seed compiler: minimal trusted external compiler capable of running the language (could be an interpreter; could be a compiled prior version).
  • Host and target triples (build system, host system, target system — following the standard three-way distinction). gnu
  • Compiler "ways": incompatible configurations for runtime, profiling, heap, etc.

Outputs: Self-hosted compiler binary per supported target; cross-compiler binaries for each (host, target) pair; reproducible bootstrap chain with hash records.

  • (c) applied to the compiler's own source gives a new version of the compiler.
  • (b(c, \text{compiler source})) gives a standalone self-hosted binary.
  • Cross-compilation is (c) instantiated with a different target triple, producing a compiler artifact that runs on the host but targets another machine. gnu

Processing

  • Bootstrap stages (following standard multi-stage bootstrap): github
    • Stage 0: compile compiler source using seed to produce stage-0 compiler binary.
    • Stage 1: run stage-0 compiler on compiler source to produce stage-1 binary.
    • Stage 2: run stage-1 compiler on compiler source to produce stage-2 binary.
    • Verify: check stage-1 and stage-2 outputs are byte-for-byte identical (or otherwise reproducibly equivalent) to confirm fixpoint.
  • Cross-compilation: apply the same stages but configure the back-end (codegen, ABI, OS bindings) for a different target triple. The host compiler cross-compiles; the resulting artifact runs on the target.
  • Conditional compilation: use compiler "ways" and target triple flags to include/exclude features (e.g., disable JIT for bare-metal targets, strip profiling for release images, enable secure-enclave memory mode).
  • Seed maintenance: keep a seed compiler/interpreter at a known-good version; seed itself is periodically refreshed by a previous verified self-hosted build (Trusting Trust mitigation).

Outputs

  • Self-hosted compiler binary for each supported target.
  • Cross-compiler binaries for each (host, target) pair.
  • Reproducible bootstrap chain (stage-N binaries, hash records).

Depends on

  • 4.3 Futamura artifact suite (provides (c), (s), (b), (n)).
  • 2.3 Global codegen (provides back-end code generation for targets).
  • 0.7 Name resolution (must handle cross-compiled standard library declarations).
  • 4.2 Build engine (orchestrates the multi-stage pipeline).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions