Skip to content

docs(erlang): design systematic wasm32 -O2 miscompilation coverage (kd-r8h7)#832

Open
brandonpayton wants to merge 1 commit into
mainfrom
gascity/kd-1mr/kd-r8h7-systematic-wasm32-o2-miscompilation-coverage-for-erlang-
Open

docs(erlang): design systematic wasm32 -O2 miscompilation coverage (kd-r8h7)#832
brandonpayton wants to merge 1 commit into
mainfrom
gascity/kd-1mr/kd-r8h7-systematic-wasm32-o2-miscompilation-coverage-for-erlang-

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

What

Design handoff for kd-r8h7 (follow-up to kd-qe2c / PR #824). Adds
docs/plans/2026-07-02-erlang-wasm32-o2-miscompilation-coverage-design.md.

Design only — no coverage, smoke, audit, or upstream work is implemented here.

Why

build-erlang.sh compiles a growing, reactively discovered set of ERTS files
at -O1 to dodge LLVM wasm32 -O2 miscompilations (erl_unicode,
erl_db_util, erl_db_hash, erl_db; erl_bif_chksum via PR #824). Each was
found only when a user hit it — the erlang:md5/1-over-iolist case even broke
on-Kandelo compilation entirely. Other term/iodata-walking files may harbor the
same defect and ship silently until tripped.

The design

  • Bug class: LLVM wasm32 -O2 miscompiles the ESTACK/WSTACK term-traversal
    idiom (a control struct whose pointer fields alias a shadow-stack local
    array). Two facets — aggregate initialization (fixed globally in global.h)
    and optimized traversal codegen (worked around per-file with -O1). The
    init patch is necessary but not sufficient.
  • Three layers: (A) a CI-gated on-Kandelo term/iodata smoke matrix, batched
    into one BEAM boot, so a new miscompilation fails fast; (B) a greppable
    workaround registry + a one-time ESTACK/WSTACK risk audit to make the reactive
    process systematic and bounded — explicitly not blanket -O1; (C) a minimal
    reproducer + upstream LLVM/OTP report with concrete -O1 removal criteria.
  • Notes the current gating trap: erlang.test.ts is skipIf(!hasErlang) and
    does not run in CI; the authoritative gate must run where the OTP runtime tree
    (erlang-otp.tar.zst) is present.

Implementation sequence is broken into candidate child beads; steps 1–4 deliver
the core value at low risk.

🤖 Generated with Claude Code

Add a design handoff for kd-r8h7 under docs/plans/. Characterizes the LLVM
wasm32 -O2 ESTACK/WSTACK miscompilation bug class behind the reactive -O1
downgrades in build-erlang.sh (erl_unicode, erl_db_util, erl_db_hash, erl_db;
erl_bif_chksum via PR #824), and proposes a three-layer strategy:

- Detection: a CI-gated on-Kandelo term/iodata smoke matrix (batched into one
  BEAM boot) so a new miscompilation fails fast instead of shipping silently.
- Containment: a greppable workaround registry + a one-time ESTACK/WSTACK risk
  audit, keeping the reactive process systematic and bounded (not blanket -O1).
- Root cause: a minimal reproducer + upstream LLVM/OTP report with explicit
  -O1 removal criteria.

Design only; implements none of the coverage, smoke, audit, or upstream work.
Follow-up to kd-qe2c (PR #824).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant