Skip to content

Stage chain links stage2 against seed-built runtime and bridge objects (D30 mixed-world link, #761 class) #1815

Closed

Description

@ehartford

Symptom

The stage chain links stage2 (code compiled by stage1) against runtime and bridge objects compiled by the seed, and embeds the same seed-built objects in stage2 and stage3 for the programs they link. Nothing fails today only because no runtime seam has changed representation since the pinned seed; the &str → {ptr, len} change (#1810) changes the physical form of every &str parameter of with_*/wl_* functions, and stage2 would pass fat views to seed-built bodies that read a header pointer.

Evidence

rt_f64_fixed_digits compiles to a different frame in the two runtime builds, so it identifies which object a binary linked (llvm-objdump -d --disassemble-symbols=_rt_f64_fixed_digits, main checkout, 2026-09-27 battery tree):

binary code compiled by prologue runtime linked
out/bootstrap/bin/with-stage1 seed sub sp, sp, #0xb80 out/bootstrap-lib/rt_core.o (seed)
out/stage/bin/with-stage2 stage1 sub sp, sp, #0xb80 out/bootstrap-lib/rt_core.o (seed)
out/release/bin/with stage2 sub sp, sp, #0xbc0 out/lib/rt_core.o (stage2)

Root cause

  • run_with_compiler_build_action for stage1 calls prepare_bootstrap_link_root, which deletes out/lib's runtime objects; out/lib's runtime and bridge objects are compiled by with-stage2 (build.w rt-core-object … fiber-core-object, llvm-bridge-object, clang-bridge-object), so when stage1 links stage2 the first root with objects is out/bootstrap-lib (link_stage_resolve_runtime_root, src/compiler/Link.w).
  • stage-embedded-objects-asm (embedded in stage2 and stage3) copies the bootstrap-embedded inputs: "Stage2 and stage3 use the same bootstrap runtime blobs".

Why nothing caught it

The D30 generation check (link_stage_runtime_dir_is_this_generation) is skipped whenever WITH_OUT_DIR is set: the build's say-so vouches for a root it did not build with the linking generation. A tool stayed silent.

Fix

Each stage links, and embeds, runtime/bridge objects compiled by the compiler that compiled its code (stage2 ⇐ stage1-built objects; stage3 and the release ⇐ stage2-built out/lib), and a build-owned runtime root records its producer so a link through it refuses objects from another compiler generation (D30: "A runtime object built by a different compiler generation must never be linked"; #761 class).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtooling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions