...
local expect="$1" crc="$2" want="$3"; shift 3
local log line n=0 from="${HWJS_DEMIT_RESOLVED:-the descriptor emitter}"
for log in "$@"; do
line="$(grep -a -m1 '\[hwjs-descemit\] PLUGIN-PROVENANCE' "$log" 2>/dev/null || true)"
if [[ -n "$expect" && -n "$line" && "$line" != *"PLUGIN-PROVENANCE commit=$expect dirty=0"* ]]; then
fatal "PLUGIN-PROVENANCE mismatch (HwjsDescriptorEmit, split piece $n of $want): expected commit=$expect dirty=0; got: $line. The bytes came from $from. Refusing a stale/mixed descriptor emitter at the consumer's vantage."
fi
if [[ "$crc" == 0 ]]; then
[[ -n "$line" ]] \
|| fatal "split piece $n of $want printed no '[hwjs-descemit] PLUGIN-PROVENANCE' line: the descriptor emitter did not run over it, so its coroutines carry no fork relocation record. Refusing the side module."
grep -a -q '\[hwjs-descemit\] COMPLETENESS .*all_have_records=1' "$log" \
|| fatal "split piece $n of $want printed no '[hwjs-descemit] COMPLETENESS ... all_have_records=1' line: nothing attests that each coroutine in it has a fork relocation record. Refusing the side module."
fi
n=$((n + 1))
done
if [[ "$crc" == 0 && $n -ne $want ]]; then
fatal "the split wrote $want pieces and $n piece logs were read for the descriptor emitter's attestation. A piece nobody read is unattested. Refusing the side module."
fi
return 0
}
# hwjs_descemit_piece_gate_end
if [[ -n "${HWJS_DEMIT_RESOLVED:-}" && $HWJS_SPLIT_N -gt 1 ]]; then
hwjs_descemit_piece_gate "$HWJS_EXPECT_COMMIT" "$rc" "$HWJS_SPLIT_PIECES" ${HWJS_PIECE_ERRS[@]+"${HWJS_PIECE_ERRS[@]}"}
fi
if [[ $rc -ne 0 ]]; then
if rc_reason="$(merged_compile_failure_reason "$rc" "$hwjs_err")"; then
fatal "pinned-clang plugin compile of the merged module failed: $rc_reason merged.bc was $(( $(stat -c %s "$WORK/merged.bc" 2>/dev/null || echo 0) / 1048576 )) MB; identity $([[ -n "$prov_line" ]] && echo "ATTESTED [$prov_line]" || echo UNATTESTED)."
fi
if [[ -n "$prov_line" ]]; then
fatal "pinned-clang plugin compile of the merged module failed (rc=$rc); identity ATTESTED [$prov_line]. The REFUSE/error reason is dumped above — a never-silent stop-and-report from the pinned plugin under the pinned config (RED-knob gate above already passed)."
else
fatal "pinned-clang plugin compile of the merged module failed (rc=$rc) BEFORE emitting PLUGIN-PROVENANCE/SUMMARY — the run's plugin identity is UNATTESTED (the abort preceded the end-of-pass attestation). The error reason is dumped above; the pre-merge RED-knob gate passed and the plugin bytes were snapshotted, but treat any conclusion drawn from this run as provisional until a clean run attests it."
fi
fi
# Guard suite — ported from cc-wasm.sh verbatim in spirit (HWJS-1/2):
grep -q '\[hwjs-coro\] SUMMARY' "$hwjs_err" \
|| fatal "the HwjsCoroutinize pass emitted no SUMMARY — it did NOT run on the merged module. Refusing a silently-uninstrumented image."
# Track E: when the pre-lowering is ACTIVE it must attest it ran AND that zero EH
# constructs survived (the pass's own POST-VERIFY aborts on residue; this vantage
# additionally catches a plugin that silently did not run at all — the exact class
# the coroutinize SUMMARY guard above exists for). I3: an image built under the
# status channel with un-lowered invokes is a silent-transit miscompile.
if [[ $EH_PRELOWER_ACTIVE == 1 ]]; then
grep -q '\[hwjs-eh-prelower\] SUMMARY mode=on .*residual: invokes=0 landingpads=0 resumes=0 personalities=0 typeids=0' "$hwjs_err" \
|| fatal "the EH pre-lowering is ACTIVE (HWJS_STATUS_CHANNEL=${HWJS_STATUS_CHANNEL:-} HWJS_EH_PRELOWER=${HWJS_EH_PRELOWER:-}) but the HwjsEHPreLower pass emitted no 'SUMMARY mode=on ... residual: invokes=0 ...' — it did NOT run on the merged module (stale/wrong plugin, or a load-order regression). An un-pre-lowered module entering the status-channel lowering is the I3 silent-transit hazard (PLAN-CXX-STATUS-CHANNEL §7/§9 R1). Refusing."
fi
# Return-attribute truth: when loaded it must attest it RAN (fns=0 is a
# legitimate verdict — a module whose converted functions carried no lying
# return attrs — but silence is a plugin that did not run: the park-exit
# unreachable class would be silently re-armed).
if [[ -n "${HWJS_RETTRUTH:-}" ]]; then
grep -q '\[hwjs-retattr-truth\] SUMMARY fns=' "$hwjs_err" \
|| fatal "the HwjsRetAttrTruth plugin was loaded but emitted no SUMMARY — it did NOT run on the merged module (stale/wrong plugin, or a load-order regression). A status-channel image without the return-attribute truth pass can carry unreachable park exits in converted functions with frontend return attrs (the measured operator-new churn trap). Refusing."
fi
# Frame deferral (HWJS_CORO_FRAME_DEFER=1; FrameDeferPass.cpp, built into the
# coroutinizer's plugin) runs after CoroSplit, in the compile that runs CoroSplit.
# On the one-compile path that compile loads the coroutinizer and the pass must
# attest it ran: silence is a plugin that predates it, and the image would ship
# stage-1 frames under a flag that says otherwise. Under the split the pieces'
# compile loads no coroutinizer, so the flag does not reach CoroSplit; say so.
if [[ "${HWJS_CORO_FRAME_DEFER:-}" == 1 && "${HWJS_STATUS_CHANNEL:-}" == 1 ]]; then
if [[ ${HWJS_SPLIT_N:-1} -gt 1 ]]; then
echo "wasmld: NOTE: HWJS_CORO_FRAME_DEFER=1 is not applied under WASMLD_HWJS_SPLIT_N=$HWJS_SPLIT_N: CoroSplit runs in the pieces' compile, which does not load the coroutinizer, so it is held off for this link, which keeps stage-1 frames (one per activation)." >&2
else
grep -q '\[hwjs-frame-defer\] SUMMARY fns=' "$hwjs_err" \
|| fatal "HWJS_CORO_FRAME_DEFER=1 with the status channel on, but the coroutinizer emitted no '[hwjs-frame-defer] SUMMARY' — the frame-deferral pass did not run: the plugin this link loaded predates it. The bytes came from $HWJS_PLUGIN_RESOLVED (the plugin home $HWJS_PLUGIN_HOME); refresh THAT home: $HWJS_PLUGIN_REMEDY. The image would carry stage-1 frames under a flag that says otherwise. Refusing."
fi
fi
grep -q 'SUSPEND-PUBLICATION .*protocol_forced=1' "$hwjs_err" \
|| fatal "suspend protocol NOT armed (no 'SUSPEND-PUBLICATION ... protocol_forced=1') — the never-silent detector is dormant. Check HWJS_SUSPEND_PROTOCOL and the plugin build."
grep -q 'PARKED-FLAG .*parked_flag_forced=1' "$hwjs_err" \
|| fatal "parked-flag side channel NOT forced (no 'PARKED-FLAG ... parked_flag_forced=1') — the image is blind to the orphaned-handle witness, or the plugin predates gate 71. Refusing."
grep -q 'PARKED-FLAG .*parked_abi=2' "$hwjs_err" \
|| fatal "parked-flag ABI is not v2 (no 'parked_abi=2') — hwjs_user_rt.c implements the v2 identity ops; a v1 emission links the same symbols at different arity and silently defeats take-side validation. Refusing."
# DRIVE-CONTRACT (HWJS-3 close: FLAT is the default). Accept the contract that
# MATCHES the requested drive mode ($HWJS_DRIVE_FLAT) and refuse a mismatch as
# never-silent — both a leaked flat AND a silent nested downgrade are wrong
# (the crt wasmcc injected is mode-matched; a contract that disagrees with it
# is a broken image, not a tolerable variant). Still refuse the genuinely-
# unsafe v1 / run-to-completion loop (it absorbs yields silently).
# - flat default (HWJS_DRIVE_FLAT=1): require drive_abi=3; drive_abi=2 here
# is a silent downgrade (the flat crt's _start drives drive_abi=3 verdicts
# the nested codegen never emits) -> refuse.
# - nested opt-out (HWJS_DRIVE_FLAT=0): require drive_abi=2; drive_abi=3 is a
# leaked flat emission under the nested crt -> refuse.
# - status channel (HWJS_STATUS_CHANNEL=1, STATUS-CHANNEL-CONTRACT §10):
# require drive_abi=4; a 2/3 contract under the knob means the plugin did
# not honor it (stale plugin / env skew) -> refuse. Conversely a
# drive_abi=4 contract WITHOUT the knob is a leaked status-channel
# emission under a legacy crt/expectation -> refuse (the crt/terminus
# wasmcc injected is knob-matched; a disagreeing contract is a broken
# image). RED arm: HWJS_STATUS_NO_ABI4_ACCEPT (roster-listed) restores
# the pre-acceptance fail-closed refusal, proving the abi-4 acceptance is
# load-bearing rather than a silent widening.
# - anything else (drive_abi=1 / no abi token) -> refuse.
_abi4_accept=1
[[ -n "${HWJS_STATUS_NO_ABI4_ACCEPT:-}" ]] && _abi4_accept=0
if grep -q 'DRIVE-CONTRACT' "$hwjs_err"; then
if [[ "${HWJS_STATUS_CHANNEL:-0}" == "1" && "$_abi4_accept" == "1" ]]; then
grep -q 'DRIVE-CONTRACT .*drive_abi=4' "$hwjs_err" \
|| { grep 'DRIVE-CONTRACT' "$hwjs_err" >&2 || true; \
fatal "HWJS_STATUS_CHANNEL=1 but the drive contract is not drive_abi=4 (status channel) — the plugin did not honor the status-channel knob (stale plugin, or HWJS_CORO_DRIVE_NESTED leaked into the merged compile env). Refusing (a legacy-abi image under the status-channel crt/terminus is a broken image)."; }
elif grep -q 'DRIVE-CONTRACT .*drive_abi=4' "$hwjs_err"; then
grep 'DRIVE-CONTRACT' "$hwjs_err" >&2 || true
if [[ "$_abi4_accept" == "0" ]]; then
fatal "drive contract is drive_abi=4 (status channel) but abi-4 acceptance is RED-disabled (HWJS_STATUS_NO_ABI4_ACCEPT) — the pre-acceptance fail-closed posture. Refusing."
else
fatal "drive contract is drive_abi=4 (status channel) but HWJS_STATUS_CHANNEL is not 1 at this driver — a status-channel emission leaked into a legacy link (driver/plugin env skew: the legacy crt's _start cannot terminate the channel; the §4 termini would never run). Refusing."
fi
elif grep -q 'DRIVE-CONTRACT .*drive_abi=2' "$hwjs_err"; then
[[ "$HWJS_DRIVE_FLAT" == "0" ]] \
|| fatal "drive contract is drive_abi=2 (nested) but the FLAT drive is the active default (HWJS_DRIVE_FLAT=1) — a silent downgrade: the flat crt's _start drives drive_abi=3 verdicts the nested codegen never emits. The plugin did not honor flat (stale plugin? leaked HWJS_CORO_DRIVE_NESTED?). Set HWJS_CORO_DRIVE_NESTED=1 to build nested deliberately, or fix the plugin. Refusing."
elif grep -q 'DRIVE-CONTRACT .*drive_abi=3' "$hwjs_err"; then
[[ "$HWJS_DRIVE_FLAT" != "0" ]] \
|| fatal "drive contract is drive_abi=3 (flat trampoline) but nested was requested (HWJS_CORO_DRIVE_NESTED=1 / HWJS_CORO_DRIVE_FLAT=0) — an unexpected/leaked flat emission under the nested crt. Rebuild without the nested knob (flat is the default), or fix the plugin. Refusing."
else
grep 'DRIVE-CONTRACT' "$hwjs_err" >&2 || true
fatal "drive contract is neither drive_abi=2 (nested park-per-iteration) nor drive_abi=3 (flat trampoline) nor drive_abi=4 (status channel) — a run-to-completion / v1 drive loop absorbs yields silently. HWJS_CORO_DRIVE_TO_COMPLETION leaked, or the plugin emits v1. Refusing."
fi
elif ! grep -q 'SUMMARY coroutinized=0 ' "$hwjs_err"; then
fatal "the merged module coroutinized functions but printed no DRIVE-CONTRACT — pre-gates-73-76 plugin (v1 run-to-completion drive loops). Rebuild the plugin. Refusing."
fi
# ── CHANNEL-ADDRESSING LOCKSTEP (PLAN-THREADS-SINGLE-MEMORY §4 step 2; the
# in-toolchain I3 armor). HwjsCoroutinize and HwjsEHPreLower emit the SAME
# channel loads and each attests its addressing mode per module run
# (`CHANNEL-ADDRESSING pass= mode=`). A skew —
# one pass reading the absolute (lane-0) block while the other reads the
# per-instance address global — is silent transit INSIDE one module (a C++
# handler dispatch consulting a DIFFERENT lane's word than the raise
# wrote); the modes must agree, and must agree with THIS driver's knob.
# RED arm: HWJS_EH_NO_LANE_ADDR forces the pre-lowering absolute under the
# lanes knob — this check is what makes that breach a refusal, not a ship.
if grep -q 'CHANNEL-ADDRESSING' "$hwjs_err"; then
_ca_modes="$(grep -o 'CHANNEL-ADDRESSING pass=[a-z-]* mode=[a-z-]*' "$hwjs_err" | awk '{print $3}' | sort -u)"
[[ "$(wc -l <<<"$_ca_modes")" == "1" ]] \
|| { grep 'CHANNEL-ADDRESSING' "$hwjs_err" >&2 || true; \
fatal "CHANNEL-ADDRESSING SKEW — the two passes attest DIFFERENT channel addressing modes on ONE merged module (lines above): checks emitted by one pass would read a DIFFERENT lane's status word than the other's under threads (the I3-2 silent-transit hazard INSIDE one module; PLAN-THREADS-SINGLE-MEMORY §4 step 2). Rebuild without the skew-inducing knob (HWJS_EH_NO_LANE_ADDR is test-only). Refusing."; }
if [[ "${HWJS_LANE_ADDR:-0}" == "1" ]]; then
[[ "$_ca_modes" == "mode=lane-global" ]] \
|| fatal "this link requests lane-aware channel addressing (HWJS_LANE_ADDRESSED=${HWJS_LANE_ADDRESSED:-} HWJS_RT_LANES=${HWJS_RT_LANES:-}) but the pass attests '$_ca_modes' — a stale plugin (predating step 2) would ship absolute lane-0 checks inside a lane-stamped image. Rebuild the plugin. Refusing."
else
[[ "$_ca_modes" == "mode=absolute" ]] \
|| fatal "the pass attests lane-global channel addressing but this driver's lane-addressing switch is off (HWJS_LANE_ADDRESSED unset/0, HWJS_RT_LANES unset/0/1) — a lane-addressed emission leaked into a single-thread link (env skew into the merged compile). Refusing."
fi
elif [[ "${HWJS_LANE_ADDR:-0}" == "1" ]] && grep -q 'DRIVE-CONTRACT .*drive_abi=4' "$hwjs_err"; then
fatal "this link requests lane-aware channel addressing (HWJS_LANE_ADDRESSED=${HWJS_LANE_ADDRESSED:-} HWJS_RT_LANES=${HWJS_RT_LANES:-}) but the abi-4 pass run printed no CHANNEL-ADDRESSING attestation — pre-step-2 plugin (absolute lane-0 checks). Rebuild the plugin. Refusing."
fi
# BUDGET-KEYING pin (F86, manager directive 2026-06-11; userland twin of
# the cc-wasm.sh pin): printed only when a safepoint was placed (budget
# surface exists). When present it must be the landed keying —
# instance-global storage in a per-instance wasm GLOBAL; the JS pump
# binds the initial budget via __hwjs_budget_set BEFORE ctors/_start.
# When HWJS_CORO_SAFEPOINTS is set the line is mandatory (a safepoints
# build from a pre-F86 plugin carries the retired shared-data budget).
if grep -q 'BUDGET-KEYING' "$hwjs_err"; then
grep -q 'BUDGET-KEYING keying=instance-global budget_storage=wasm-global' "$hwjs_err" \
|| fatal "budget keying is not instance-global/wasm-global (F86) — a linear-memory or lane-array budget is per-execution-context state in cross-instance-visible storage; the retired pre-F86 shape. Refusing."
elif [[ "${HWJS_CORO_SAFEPOINTS:-1}" != "0" ]]; then
# Checkpoints are armed on every link that does not turn them off, so the line is mandatory on
# every such link. (It was keyed on the knob being SET, back when being set was the exception.)
fatal "checkpoints are armed for this link but the pass printed no BUDGET-KEYING line — pre-F86 plugin (shared-data budget). Rebuild the plugin (toolchain/build.sh). Refusing."
fi
# ── EFFECT-FACT-GUARD attestation (2026-08-02). Replaces the withdrawn
# whole-program-safepoints-under-the-status-channel refusal that used to live
# in the pass (CoroutinizePass.cpp, see the WITHDRAWN block there for the full
# history). That refusal's predicate was "a defect exists in another
# repository", which nothing can compute, so it outlived its cause by weeks
# while breaking three rigs, and it was disarmed by merely SETTING
# HWJS_CORO_SAFEPOINT_ONLY to anything at all.
#
# The defect was an effect-fact lie — `returned` surviving onto a coroutine
# ramp — laundered into the frame by the §8 status-channel spill sink, which
# is the only consumer of the poisoned register. It is fixed, and the CLASS is
# caught by llvm's coro::verifyNoEffectFactsOnSplitRamps: module-level, from
# CoroCleanup (the only vantage that sees what ships), Refuse for the
# classified liars, Report for anything a future LLVM adds.
#
# So the predicate that IS computable, and the one enforced here: the merged
# module wasmld just compiled must have been ATTESTED by that guard. An armed
# guard prints the line for every module, clean ones included, on the compiles
# this driver runs with HWJS_STATUS_CLASS_GUARD_ATTEST=1 (hwjs_env), so its
# ABSENCE means exactly one of two things and both are refusals — the LLVM has
# no split-ramp effect-fact guard (stale toolchain), or the guard was disarmed
# with HWJS_STATUS_CLASS_GUARD=0. §8 is live on every drive_abi=4 link, with
# or without safepoints, so this is keyed on the STATUS CHANNEL and not on the
# safepoint knob that merely amplified the original failure ~1000x.
#
# RED (gate non-vacuity, and the only way to rebuild the T2 reproducer):
# HWJS_STATUS_CLASS_GUARD=0 removes the attestation and this gate must refuse.
# HWJS_CORO_SP_STATUS_UNGUARDED=1 is the documented bypass, and is now what it
# always claimed to be — the knob that builds the deliberately-corrupting
# binary. Never in a shipping build.
# ── EFFECT-FACT ATTESTATION GATE (BRINTOS-2764) ───────────────────────────────
# The split-ramp effect-fact attestation is printed by CODEGEN, not by the pass
# plugin, so WHERE it is depends on how the module was compiled. Monolithic: one
# line in the pass log. Split: one line per piece, in that piece's own log, and
# none at all in the pass log.
#
# That difference is why this is a function with a count rather than a grep. Over
# N concatenated piece logs, `grep -q '... refusals=0'` is satisfied by ONE clean
# piece, so the gate quietly becomes an existential — it would pass a link in
# which seven pieces of eight went unaudited, and nothing would error to say so.
# Every piece must attest, and every attestation must be clean.
#
# RED (gate non-vacuity): call it with a log set one short, or with one log whose
# line says refusals=1, and it must refuse. test/split-after-pass-guards.sh.
hwjs_effect_fact_gate() { # ...
local want="$1"; shift
local att clean
# /dev/null never matches and keeps grep off stdin if the set is empty.
att=$(grep -l '\[hwjs-coro\] EFFECT-FACT-GUARD ' /dev/null "$@" 2>/dev/null | wc -l)
clean=$(grep -l '\[hwjs-coro\] EFFECT-FACT-GUARD .* refusals=0 ' /dev/null "$@" 2>/dev/null | wc -l)
if [[ $att -eq $want && $clean -eq $want ]]; then
return 0
fi
if [[ $att -eq $want ]]; then
grep -h '\[hwjs-coro\] EFFECT-FACT-GUARD ' /dev/null "$@" >&2 || true
fatal "the split-ramp effect-fact class guard attested a NON-ZERO refusal count on $((want - clean)) of $want pieces (lines above) — an attribute that promises something by the time the callee returns survived onto a coroutine ramp, and under the status channel the §8 spill sink launders exactly that into the frame slot the resume clone trusts. This is the T2 miscompile class. Refusing."
fi
if [[ -n "${HWJS_CORO_SP_STATUS_UNGUARDED:-}" ]]; then
echo "wasmld: WARNING (EFFECT-FACT-GUARD): building a drive_abi=4 image with NO split-ramp effect-fact attestation on $((want - att)) of $want pieces, because HWJS_CORO_SP_STATUS_UNGUARDED=1 was set. This is the T2 RED-arm bypass and the image may be deliberately miscompiled. Never ship it." >&2
return 0
fi
fatal "drive_abi=4 (status channel) and only $att of $want split pieces printed a '[hwjs-coro] EFFECT-FACT-GUARD' attestation. A piece that codegens without attesting is unaudited, and one unaudited piece is enough for the T2 miscompile. Same causes as the monolithic arm — HWJS_STATUS_CLASS_GUARD=0, or a libLLVM predating coro::verifyNoEffectFactsOnSplitRamps — plus one this arm adds: a piece whose compile printed nothing because it failed before codegen. Refusing rather than shipping an unaudited status-channel image."
}
# hwjs_effect_fact_gate_end
if grep -q 'DRIVE-CONTRACT .*drive_abi=4' "$hwjs_err"; then
# Split: the attestation is one line per piece, in that piece's own log, and
# must be read as a universal — see hwjs_effect_fact_gate.
if [[ $HWJS_SPLIT_N -gt 1 ]]; then
hwjs_effect_fact_gate "$HWJS_SPLIT_PIECES" ${HWJS_PIECE_ERRS[@]+"${HWJS_PIECE_ERRS[@]}"}
elif grep -q '\[hwjs-coro\] EFFECT-FACT-GUARD ' "$hwjs_err"; then
grep -q '\[hwjs-coro\] EFFECT-FACT-GUARD .* refusals=0 ' "$hwjs_err" \
|| { grep '\[hwjs-coro\] EFFECT-FACT-GUARD ' "$hwjs_err" >&2 || true; \
fatal "the split-ramp effect-fact class guard attested a NON-ZERO refusal count on the merged module (line above) — an attribute that promises something by the time the callee returns survived onto a coroutine ramp, and under the status channel the §8 spill sink launders exactly that into the frame slot the resume clone trusts. This is the T2 miscompile class. Refusing."; }
elif [[ -n "${HWJS_CORO_SP_STATUS_UNGUARDED:-}" ]]; then
echo "wasmld: WARNING (EFFECT-FACT-GUARD): building a drive_abi=4 image with NO split-ramp effect-fact attestation, because HWJS_CORO_SP_STATUS_UNGUARDED=1 was set. This is the T2 RED-arm bypass and the image may be deliberately miscompiled. Never ship it." >&2
else
fatal "drive_abi=4 (status channel) but the LLVM that compiled the merged module printed no '[hwjs-coro] EFFECT-FACT-GUARD' attestation. §8 status-channel spill sinking is live on this image, and §8 is the first and only consumer of a register poisoned by an effect-fact lie on a coroutine ramp (the T2 miscompile: \`returned\` on a ramp, wild-writing sqlite-owned heap). The class guard that proves the absence of such lies is coro::verifyNoEffectFactsOnSplitRamps in the pinned llvm-project fork; it attests every module it audits. No line means either (a) HWJS_STATUS_CLASS_GUARD=0 disarmed it — do not do that on a shipping link — or (b) this toolchain's libLLVM predates the guard: rebuild toolchains/llvm-project at the pinned commit. Refusing rather than shipping an unaudited status-channel image. Bypass for the deliberately-corrupting T2 reproducer only: HWJS_CORO_SP_STATUS_UNGUARDED=1."
fi
fi
# REFUSE enforcement (HWJS-2; sole benign class alwaysinline-suspender-
# residual real_uses=0; the weak-empty-default census class is RETIRED at
# membership zero — any refusal here is a FRESH stop-and-report).
# Match the REAL refusal marker `REFUSE fn=` (CoroutinizePass emits
# `[hwjs-coro] REFUSE fn=... reason=...`), NOT the bare substring `REFUSE`:
# benign DS-*-LOWER notices name their RED knob (e.g. `RED: HWJS_FRAMEADDR_REFUSE`),
# where `REFUSE` is part of the knob name and must not trip this never-silent gate.
# F163 (brintos/hwjs-cc#6): NOT a pipe into `grep -q` — the old
# `grep 'REFUSE fn=' | grep -qv ` form let `grep -q`'s early close
# SIGPIPE the left grep once the refusal text spanned more than one stdio
# buffer, and `set -o pipefail` then evaluated the WHOLE condition false —
# the never-silent gate silently SKIPPED on exactly the links with many
# refusals (GNU make shipped 16 refusals as a "successful" link and died
# at run time in set-over-set). Capture, filter, then test — no early-close
# reader anywhere. Gate: test/refuse-gate-sigpipe.sh (RED = the old pipe
# shape demonstrably skipping on the same input).
refuse_lines="$(grep 'REFUSE fn=' "$hwjs_err" || true)"
refuse_nonbenign="$(grep -v 'reason=alwaysinline-suspender-residual.*real_uses=0' <<<"$refuse_lines" || true)"
# libc.so PRODUCER EXEMPTION (WASMLD_LIBC_SO=1 only; PLAN-DYNAMIC-LIBC §3.3): a refused fn whose
# name a HUMAN put in WASMLD_LIBC_SO_UNWIND_WAIVE is legal in libc.so — the pass audited it on
# the cross-module unwind path (XMOD-UNWIND-WAIVER line above is the proof; the pass only waives names
# from that env), PUBLISHED verdict=refused in the partition + refused_exports in the hwjs.abi
# manifest, and every consumer/loader refuses the binding instead. The whole-program rationale
# of this gate ("every caller is in-module") does not hold on a -shared producer; without this
# exemption the plan's named-waiver escape is dead code (the G-D3W arm). Never-silent: each
# exempted name is NOTEd here, the waiver itself was NOTEd at arm setup, and any refused fn NOT
# named in the waiver still hits the fatal below. Pre-dynamic-libc arms (LIBC_SO!=1) are byte-identical.
if [[ "$LIBC_SO" == "1" && -n "$refuse_nonbenign" ]]; then
while IFS= read -r _wvline; do
_wvname="${_wvline#*XMOD-UNWIND-WAIVER fn=}"; _wvname="${_wvname%% *}"
[[ -n "$_wvname" ]] || continue
_wvkept="$(grep -v "REFUSE fn=${_wvname} " <<<"$refuse_nonbenign" || true)"
if [[ "$_wvkept" != "$refuse_nonbenign" ]]; then
echo "wasmld: NOTE (WASMLD_LIBC_SO): refused fn '${_wvname}' is human-waived (WASMLD_LIBC_SO_UNWIND_WAIVE) — published verdict=refused (partition + hwjs.abi refused_exports); consumers and the loader refuse the binding (PLAN-DYNAMIC-LIBC §3.3). Exempting it from the whole-program refused-def fatal (a -shared producer is not whole-program vantage)." >&2
refuse_nonbenign="$_wvkept"
fi
done < <(grep -a 'XMOD-UNWIND-WAIVER fn=' "$hwjs_err" || true)
fi
if [[ -n "$refuse_nonbenign" ]]; then
printf '%s\n' "$refuse_nonbenign" >&2
fatal "the coroutinize pass REFUSED function(s) in the merged module (non-benign class, lines above). At whole-program vantage every caller is in-module, so a refused def is a live ABI chimera. Stop-and-report."
fi
# OBLIGATION-PUBLISH-ALL, userland spelling. The kernel's counter
# (unpublished_cross_tu external-keyed == 0) is a PER-TU obligation: an
# unpublished external suspender means some OTHER TU's callers will not
# seed — the §8b hole. At whole-program vantage there IS no other TU:
# the pass still prints UNPUBLISHED-SUSPENDER for every coroutinized fn
# that keeps external linkage (visibility is linkage-keyed and the merge
# preserves it), and the printed consequence ("per-TU callers will not
# seed") is unreachable by construction — publication is the cross-TU
# protocol this build shape exists to not need (design §1). The hole
# that DOES survive the merge is a NATIVE-STAGE caller of a coroutinized
# external (its call would consume the ramp's return slot as a value:
# the exact §8b shape). So the userland witness is an INTERSECTION
# check, mechanical and loud: no native-stage input may reference any
# coroutinized symbol. (wasm_thread.S calls only _start [export_name-
# exempt, never coroutinized]; the thunks/builtins are leaves — green by
# construction, but checked every link, not audited once.)
# F87 alias arm, merged-module spelling. The kernel pin
# (unpublished_alias=0, coverage-keyed) lives in cc-wasm.sh where the
# external pin lives; HERE the whole-program design logic of the
# external class applies UNCHANGED to aliases: in-module callers
# THROUGH an alias are seeded (the pass strips GlobalAlias at call
# sites — musl's __libc_start_init/__libc_exit_fini shapes fired this
# arm's first hard-zero draft and ARE seeded in-module), so the
# surviving hole is a NATIVE-STAGE caller of the ALIAS NAME, which
# the intersection witness below would MISS if keyed on function
# names alone (coroutinized.txt carried the aliasee's name; the
# native undefined symbol is the alias's). Enforcement: fold every
# suspender-alias NAME into the intersection witness — a native input
# referencing one is the same §8b fatal as referencing the aliasee.
# The census stays loud (NOTE line) so the alias work list is visible
# on every link, never silent.
if grep -q 'unpublished_alias=[1-9]' "$hwjs_err"; then
# One line, all pairs (ticket #12): the work list stays visible on every
# link (never silent), without the per-alias line-per-link repetition.
alias_pairs="$(grep -o 'UNPUBLISHED-SUSPENDER alias=[^ ]* aliasee=[^ ]*' "$hwjs_err" \
| sed 's/UNPUBLISHED-SUSPENDER alias=//; s/ aliasee=/->/' | sort -u | tr '\n' ' ' || true)"
echo "wasmld: NOTE (F87 alias census): suspender-alias(es): ${alias_pairs}" >&2
fi
# NOTE the `|| true` on each grep: under set -e/pipefail a merge with
# ZERO alias lines (or, pathologically, zero coroutinized functions)
# made the group exit nonzero and killed the wrapper SILENTLY after a
# successful compile — first hit by the exec-child image (no
# fork/execve caller -> no alias census lines), 2026-06-11. An empty
# witness list is a legal state, not an error.
{ grep -o 'COROUTINIZE fn=[^ ]*' "$hwjs_err" | sed 's/^COROUTINIZE fn=//' || true
grep -o 'UNPUBLISHED-SUSPENDER alias=[^ ]*' "$hwjs_err" | sed 's/^UNPUBLISHED-SUSPENDER alias=//' || true
} | sort -u > "$WORK/coroutinized.txt"
# A program's own copy of a builtin is not marked native. The backend's calls
# to it have no bracket, so it must not have become a coroutine.
if [[ -s "$WORK/coroutinized.txt" && -n "${_bi_own:-}" ]]; then
_bi_coro="$(LC_ALL=C comm -12 <(LC_ALL=C sort -u "$WORK/coroutinized.txt") <(printf '%s\n' "$_bi_own") || true)"
[[ -z "$_bi_coro" ]] \
|| fatal "the program's own definition of [$(paste -sd' ' - <<<"$_bi_coro")] became a coroutine. The backend creates the calls to these names after the pass, so nothing can drive one that parks. Drop the program's copy and let the compiler-rt TU supply it, or declare it native (annotate(\"hwjs.native.v1\"))."
fi
# With the object the module defines none of its names. That was read off
# a listing of the module where it became whole; it is read again here off
# the object the compile wrote, where a name is one symbol, and a listing
# that fails stops the link. The same listing says which of the names
# merged.o leaves to the object, which the final link line must then carry.
if [[ -n "$HWJS_BUILTINS_OBJECT" ]]; then
_bi_seen="$(hwjs_nm "$WORK/merged.o" 2>"$WORK/builtins.err")" \
|| { cat "$WORK/builtins.err" >&2; fatal "llvm-nm could not list merged.o, so whether it defines one of the builtins object's names cannot be told."; }
builtins_object_unresolved "$_bi_seen"
_bi_names=""; for _bi_key in "${!BUILTINS_OBJECT_NAMES[@]}"; do _bi_names+=" ${_bi_key#:}"; done
_bi_coro="$(LC_ALL=C awk -v names="$_bi_names" '
BEGIN { n = split(names, a, " "); for (i = 1; i <= n; i++) want[a[i]] = 1 }
NF >= 2 && $(NF-1) != "U" && $(NF-1) != "w" && ($NF in want) && !seen[$NF]++ { out = out (out == "" ? "" : " ") $NF }
END { print out }' <<<"$_bi_seen")"
[[ -z "$_bi_coro" ]] \
|| fatal "merged.o defines [$_bi_coro], names of the builtins object: the backend's calls to them bind inside the module. Link with WASMLD_HWJS_BUILTINS_OBJECT=0 and report this: the module should have been found to define the name."
fi
# One that became a coroutine all the same is refused.
if [[ -s "$WORK/coroutinized.txt" && -n "$HWJS_BUILTINS_OBJECT" ]]; then
_bi_names=""; for _bi_key in "${!BUILTINS_OBJECT_NAMES[@]}"; do _bi_names+=" ${_bi_key#:}"; done
_bi_coro="$(LC_ALL=C awk -v names="$_bi_names" '
BEGIN { n = split(names, a, " "); for (i = 1; i <= n; i++) want[a[i]] = 1 }
($0 in want) { out = out (out == "" ? "" : " ") $0 }
END { print out }' "$WORK/coroutinized.txt" || true)"
[[ -z "$_bi_coro" ]] \
|| fatal "[$_bi_coro] became a coroutine in a link that takes compiler-rt's helpers from the builtins object. The backend's calls to these names bind to that function and nothing can drive it. Link with WASMLD_HWJS_BUILTINS_OBJECT=0 and report this: the module should have been found to define the name."
fi
# One awk asks whether any native input's recorded undefined names meet the
# list; only then is each input compared, for the lines the refusal prints.
_nat_any=1
if [[ -s "$WORK/coroutinized.txt" && ${#NATIVE_INPUTS[@]} -gt 0 ]]; then
_nat_undef=""
for nat in "${NATIVE_INPUTS[@]}"; do
if link_facts_v undefined "$nat"; then _nat_undef+="$LINK_FACTS_V"$'\n'; else _nat_undef=""; break; fi
done
if [[ -n "$_nat_undef" ]]; then
_nat_any="$(awk 'NR == FNR { if ($0 != "") c[$0] = 1; next } ($0 in c) { print 1; exit }' "$WORK/coroutinized.txt" - <<<"$_nat_undef")"
fi
fi
if [[ -n "$_nat_any" && -s "$WORK/coroutinized.txt" && ${#NATIVE_INPUTS[@]} -gt 0 ]]; then
for nat in "${NATIVE_INPUTS[@]}"; do
# F163: same SIGPIPE-free discipline as the REFUSE gate above — the old `comm | grep -q .`
# let the reader's early close pipefail the whole condition and skip the §8b check.
_nat_hits="$(link_facts_answer undefined "$nat" | sort -u | \
comm -12 - "$WORK/coroutinized.txt" || true)"
if [[ -n "$_nat_hits" ]]; then
sed "s|^|wasmld: $nat -> |" <<<"$_nat_hits" >&2
fatal "native-stage input '$nat' calls coroutinized function(s) (lines above) — the §8b hole live: a native caller consumes the ramp's frame handle as the return value. The caller must move into the bitcode closure (or be bracketed). Stop-and-report."
fi
done
fi
grep -q 'SUMMARY .*mode=classify-only' "$hwjs_err" \
&& fatal "the pass ran CLASSIFY-ONLY on the merged module — the image is untransformed and would link silently. A stale HWJS_CORO_CLASSIFY_ONLY reached the pass despite the unset."
# ── -shared-only pass-run guards (HWJS-5 M1):
if [[ $IS_SHARED == 1 ]]; then
# TLS CENSUS. Every module lld links defines its OWN __tls_base — a -shared
# module never imports it — and TLS access lowers to local-exec against that
# private global (global.get __tls_base + a link-time offset into this
# module's own .tdata/.tbss). lld's start function points the global at the
# module's data base on the Instance that first initialises the memory, and
# nothing else ever writes it: every later Instance over the same memory (a
# fork child, a new thread, a migrated task) reads 0 there. The loader
# binds those Instances; this link's job is to attest what it built. The
# pass attests the merged module's TLS facts on the TLS-CENSUS line
# (thread_local globals + llvm.threadlocal.address, the complete IR-level
# TLS surface); the line's PRESENCE is itself required, so a plugin that
# cannot attest the census refuses.
#
# Three arms own TLS differently:
# libc.so (WASMLD_LIBC_SO=1) — the process thread-pointer owner: glibc's
# own TLS, sized by the exported __wasm32_get_tls_size/align, bound to
# the pthread block by the host (spike G2, the §9.4 bump).
# the runtime module (WASMLD_RT_SO=1) — may not own TLS: the host binds no
# block for module #0.
# an ordinary side module — owns a PRIVATE block per thread, unrelated to
# the thread pointer: its base is its own global, so it cannot alias
# libc.so's TLS or the main's. It exports the four symbols the loader
# binds it through (below) and may not export a thread_local itself.
grep -q 'TLS-CENSUS tls_globals=' "$hwjs_err" \
|| fatal "-shared: the pass run printed no TLS-CENSUS line — this plugin predates the hwjs.abi manifest work and cannot attest the side module's TLS (the loader binds a .so's per-thread TLS block from that census and the manifest bit). Rebuild the plugin."
if ! grep -q 'TLS-CENSUS tls_globals=0 ' "$hwjs_err"; then
if [[ "$LIBC_SO" == "1" ]]; then
# G2 TLS-CENSUS LIFT. Cross-check the manifest ACTUALLY stamped
# uses_tls=1: a census line without the manifest bit would ship a
# libc.so whose hwjs.abi lies to the loader's §9.3 uses_tls pin — the
# never-silent skew class. (The pass sets flags bit1 from the same
# llvm.threadlocal.address scan that feeds the census — a divergence
# means a mismatched/pre-G2 plugin.)
grep -q 'ABI-MANIFEST section=hwjs.abi .*uses_tls=1' "$hwjs_err" \
|| { grep -E 'TLS-CENSUS|ABI-MANIFEST' "$hwjs_err" >&2 || true; \
fatal "WASMLD_LIBC_SO: the merged closure's TLS-CENSUS names thread_local globals but the hwjs.abi manifest did NOT stamp uses_tls=1 (lines above) — census/manifest SKEW would ship a libc.so whose manifest lies to the loader's §9.3 uses_tls check. Rebuild the plugin (pre-G2 vintage). Refusing the artifact."; }
grep 'TLS-CENSUS' "$hwjs_err" | sed 's/^/wasmld: /' >&2 || true
echo "wasmld: NOTE (G2 TLS-CENSUS LIFT): libc.so is the sanctioned module-#1 TLS owner — ACCEPTING IR TLS (census above; manifest uses_tls=1). The loader MUST size libc.so's bootstrap TLS block via the exported __wasm32_get_tls_size/__wasm32_get_tls_align and bind/dual-write __tls_base (hwjs-rt-abi §12/§9.3)." >&2
elif [[ "$RT_SO" == "1" ]]; then
grep 'TLS-CENSUS' "$hwjs_err" >&2 || true
fatal "WASMLD_RT_SO: the runtime module's merged closure USES TLS (census line above names the thread_local globals) — the host binds no TLS block for module #0, so its thread_local state would be unbound on every Instance after the first. Remove the thread_local state from the runtime module."
else
grep -q 'ABI-MANIFEST section=hwjs.abi .*uses_tls=1' "$hwjs_err" \
|| { grep -E 'TLS-CENSUS|ABI-MANIFEST' "$hwjs_err" >&2 || true; \
fatal "-shared: the merged side module's TLS-CENSUS names thread_local globals but the hwjs.abi manifest did NOT stamp uses_tls=1 (lines above) — the loader decides whether to bind this module's TLS from that bit, so a skewed manifest would leave its __tls_base unbound. Rebuild the plugin. Refusing the artifact."; }
grep 'TLS-CENSUS' "$hwjs_err" | sed 's/^/wasmld: /' >&2 || true
echo "wasmld: NOTE (side-module TLS): the merged side module owns thread_local state (census above; manifest uses_tls=1) — exporting __tls_base/__tls_size/__tls_align/__wasm_init_tls for the loader's per-thread bind; a thread_local may not itself be exported (checked on the final bytes)." >&2
SIDE_TLS=1
fi
fi
# SINGLE-MANIFEST emission: the merged run must have emitted the
# hwjs.abi record (the manifest is how the host loader audits ABI skew).
grep -q 'ABI-MANIFEST section=hwjs.abi' "$hwjs_err" \
|| fatal "-shared: the pass run emitted no ABI-MANIFEST — the .so would carry no hwjs.abi custom section for the host loader's ABI-skew check. Rebuild the plugin (pre-M1?)."
fi
# ── (4) Final native link (no Binaryen, ever, on this arm).
#
# INITIAL-MEMORY AUTO-SIZE (ticket #9). The declared --initial-memory is
# the image's env.user_memory import MINIMUM (the A-5 note above), so the
# default is sized for the COMMON static layout (130 pages) — but a
# big-.bss binary (bzip2recover: 9.3 MB of static arrays) legitimately
# needs more, and wasm-ld is the single authority on the real layout
# ("initial memory too small, N bytes needed"). Rather than duplicating
# its layout math, consume that authoritative number: when the caller did
# NOT pin WASMLD_INITIAL_PAGES, re-link ONCE at exactly the needed size
# (+16 pages so the heap does not grow on the first malloc), with a loud
# NOTE naming both numbers. An EXPLICIT WASMLD_INITIAL_PAGES stays a hard
# contract: too small remains the loud wasm-ld error, never a silent
# override (that pin is how per-process memory floors are enforced).
# ── FLAG EXCLUSIVITY (PLAN-DYNAMIC-LIBC §3.4 (ii), S5 §0): with BOTH --allow-undefined and
# --unresolved-symbols=import-dynamic on one line, --allow-undefined silently WINS regardless of
# order (lld Driver.cpp:865-870) — every undefined datum then binds to the NULL page (RED-1). The
# undefined-symbol policy is ARM-OWNED: refuse caller-supplied spellings that could combine.
# SPELLING/CHANNEL COMPLETENESS (2026-07-16 review): the pinned lld's Options.td declares these
# options with the F/J/Eq classes, which accept BOTH '--' and '-' prefixes (plus the Separate
# '-allow-undefined-file FILE' form), and wasm-ld expands @response-files AFTER this wrapper has
# run — so a single-dash spelling or an '@rsp' carrying the flag slipped the old '--'-only case
# patterns and silently suppressed every GOT.mem import (the exact RED-1 bind this guard exists
# to refuse; CMake/ninja emit @rsp link lines routinely). Guard the FULL post-@-expansion argv
# with prefix-normalized matches. The driver now expands response files itself before it reads
# the line, so the expansion below finds nothing left to open; it stays as the guard's own.
_dyn_scan_flags=()
_dyn_expand_into_scan() { # $1 = arg, $2 = depth
local a="$1" d="$2" rf t
if [[ "$a" == @?* ]]; then
rf="${a#@}"
if [[ -f "$rf" ]]; then
(( d >= 8 )) && fatal "response-file expansion deeper than 8 levels at '@$rf' — refusing to scan an unboundedly nested @rsp chain (flag-exclusivity guard)."
# tokenize on whitespace; strip simple quoting (lld rsp quoting is richer, but a stripped
# token can only make the guard match MORE — fail-loud, never fail-open).
while IFS= read -r -d '' t; do
[[ -n "$t" ]] && _dyn_expand_into_scan "$t" $((d + 1))
done < <(tr -s ' \t\r\n' '\0' < "$rf" | tr -d '"'"'")
return 0
fi
# a non-existent @file reaches wasm-ld verbatim and fails loudly there.
fi
_dyn_scan_flags+=("$a")
}
for _lf in "${LINK_FLAGS[@]}"; do
_dyn_expand_into_scan "$_lf" 0
done
for _lf in "${_dyn_scan_flags[@]}"; do
case "$_lf" in
--allow-undefined|-allow-undefined|--allow-undefined-file|--allow-undefined-file=*|-allow-undefined-file|-allow-undefined-file=*)
# EVERY coro arm, not just the consumer. --allow-undefined is
# --import-undefined + --unresolved-symbols=ignore, and the `ignore` half is precisely the
# address-0 data bind both arms now refuse (see the CORO_UNDEF_FLAG note). One caller-side
# spelling silently restores it — on the consumer arm by out-ranking
# --unresolved-symbols=import-dynamic (lld Driver.cpp:865-870), on the static arm by
# widening --import-undefined back over the DATA class. The caller's own
# --allow-undefined-file= would additionally overwrite the DERIVED undefined-GLOBAL sanction
# with a hand-written list — the shape this mechanism exists to not have.
fatal "caller-supplied '$_lf' on the coro final link line (post-@-expansion argv) — the undefined-symbol policy is ARM-OWNED and this flag re-opens the silent address-0 data bind: --allow-undefined is --import-undefined PLUS --unresolved-symbols=ignore (lld Driver.cpp:865-870), and the \`ignore\` half is what let \`cpuinfo_op\` link as an i32.const 0. The static arm passes --import-undefined (undefined functions import, undefined DATA is a link error) and derives its undefined-GLOBAL sanction from the inputs' symbol tables; the WASMLD_LIBC_IMPORT=1 arm passes --unresolved-symbols=import-dynamic. Drop the caller's flag; a genuinely host-bound FUNCTION import is spelled WASMLD_ALLOW_ENV_IMPORTS=."
;;
--import-undefined|-import-undefined)
fatal "caller-supplied '$_lf' on the coro final link line (post-@-expansion argv) — the undefined-symbol policy is ARM-OWNED. The flag is already the static arm's own, and accepting a caller's copy makes the line's policy depend on argv order rather than on the arm. Drop it."
;;
--unresolved-symbols|--unresolved-symbols=*|-unresolved-symbols|-unresolved-symbols=*)
fatal "caller-supplied '$_lf' on the final link line (post-@-expansion argv) — the undefined-symbol policy is ARM-OWNED (--import-undefined on the static arm; --unresolved-symbols=import-dynamic exactly on WASMLD_LIBC_IMPORT=1, where the witness makes it sound). Mixing spellings resolves silently in --allow-undefined's favor (lld Driver.cpp:865-870); spell the request through the arm knobs (PLAN-DYNAMIC-LIBC §3.4 (ii))."
;;
esac
done
# ── §3.5 force-export OWNER AUDIT (consumer arm): for every hard --export in the link_coro
# surface, record owner = main | both | libc.so | rt. main/both keep the --export; libc.so/rt are
# DROPPED (the loader looks them up on module #1/#0 — first confirmed libc.so-owned case:
# __wasm32_set_signal_region, host-called post-_start); a symbol NO side owns is a loud refusal —
# a wrong-side lookup at load would be silent. The table ships as $OUT.export-owners (the loader's
# lookup table input).
#
# WHY THE RT-IMPORT ARM RUNS IT TOO (2026-08-04). The audit was gated on WASMLD_LIBC_IMPORT=1
# alone, so a WASMLD_RT_IMPORT=1 main WITHOUT a libc.so (the tcl dlopen stub) kept the full hard
# --export list — including the eight runtime-owned names module #0 owns and this image does not
# define. lld's requiredExports check (Writer.cpp:1741-1749) reports a missing --export only when
# unresolvedSymbols is ReportError/Warn, and --allow-undefined set it to IGNORE, so those eight
# exports were SILENTLY dropped from the image and the promise the surface exists to make — "the
# HardwareJS process ABI is a linker invariant, not a per-target opt-in" — was quietly false for
# that binary. Dropping --unresolved-symbols=ignore turned the silence into eight link errors,
# which is how this was found. The fix is not to re-silence it: an export a DIFFERENT module owns
# must be dropped BY OWNER, which is exactly what this audit computes.
if [[ "$LIBC_IMPORT" == "1" || "${WASMLD_RT_IMPORT:-0}" == "1" ]]; then
# The same awk writes the WideSlot readers among them (below) to their own file.
: > "$WORK/promise-readers"
_main_defs="$(run_llvm_bulk hwjs_nm --defined-only "$WORK/merged.bc" ${NATIVE_INPUTS[@]+"${NATIVE_INPUTS[@]}"} 2>/dev/null \
| PR="$WORK/promise-readers" awk '!seen[$NF]++ { print $NF; if ($NF ~ /^__hwjs_promise_a[0-9]+$/) print $NF > ENVIRON["PR"] }')"
_libc_exports=""
if [[ "$LIBC_IMPORT" == "1" ]]; then
if link_facts_v exports "$LIBC_SO_SNAPSHOT"; then
_libc_exports="$LINK_FACTS_V"
else
_libc_exports="$(link_facts_ask_exports "$LIBC_SO_SNAPSHOT" 2>&1)"
fi \
|| { echo "$_libc_exports" >&2; fatal "WASMLD_LIBC_IMPORT: cannot read the export surface of '$WASMLD_LIBC_SO_PATH' (WORK snapshot) — the owner audit and the witness allowlists DERIVE from the built libc.so (never hand-maintained; PLAN-DYNAMIC-LIBC §3.6)."; }
fi
CORO_EXPORTS_AUDITED=()
EXPORT_AUDIT_RAN=1
: > "$WORK/export-owners"
_audit_syms=()
for _ex in "${CORO_EXPORT_SURFACE[@]}"; do
case "$_ex" in --export=*) _audit_syms+=( "${_ex#--export=}" ) ;; esac
done
export_owner_tables "$_main_defs" "$_libc_exports" ${_audit_syms[@]+"${_audit_syms[@]}"} \
|| fatal "force-export OWNER AUDIT: awk could not look the audit's names up in the main's definitions and libc.so's exports."
_owners_main=0; _owners_both=0; _owners_libc=0; _owners_rt=0
for _ex in "${CORO_EXPORT_SURFACE[@]}"; do
case "$_ex" in
--export=*) _sym="${_ex#--export=}" ;;
*) CORO_EXPORTS_AUDITED+=( "$_ex" ); continue ;; # --export-if-defined: cannot mis-fire
esac
export_owner_v "$_sym" || fatal "force-export OWNER AUDIT: no owner answer for '$_sym' — the owner tables were built for other names than the audit asks about."
_owner="$EXPORT_OWNER"
case "$_owner" in
main) _owners_main=$(( _owners_main + 1 )); CORO_EXPORTS_AUDITED+=( "$_ex" ) ;;
both) _owners_both=$(( _owners_both + 1 )); CORO_EXPORTS_AUDITED+=( "$_ex" ) ;;
libc.so) _owners_libc=$(( _owners_libc + 1 )) ;;
rt) _owners_rt=$(( _owners_rt + 1 )) ;;
*)
fatal "force-export OWNER AUDIT: '$_sym' is owned by NO side — not defined in the merged main closure/native inputs, not exported by libc.so (${WASMLD_LIBC_SO_PATH:-}), and not a kernel-runtime name under WASMLD_RT_IMPORT (=${WASMLD_RT_IMPORT:-0}). A wrong-side lookup at load would be silent; refusing at link (PLAN-DYNAMIC-LIBC §3.5)."
;;
esac
printf '%s %s\n' "$_sym" "$_owner" >> "$WORK/export-owners"
done
# The WideSlot readers the kernel runtime binds from the main (see CORO_EXPORTS_DERIVED).
# --export-if-defined, so the entries pass the audit unaudited by the same rule as the rest of
# the if-defined surface: an if-defined export cannot mis-fire on a symbol the main lacks.
# The names differ only in their digits, which order alike in every locale.
CORO_EXPORTS_DERIVED=()
mapfile -t _pr_found < "$WORK/promise-readers"
sorted_v _pr_found ${_pr_found[@]+"${_pr_found[@]}"}
for _psym in ${_pr_found[@]+"${_pr_found[@]}"}; do
CORO_EXPORTS_DERIVED+=( "--export-if-defined=$_psym" )
done
[[ ${#CORO_EXPORTS_DERIVED[@]} -eq 0 ]] \
|| echo "wasmld: NOTE (WideSlot promise readers): exporting ${#CORO_EXPORTS_DERIVED[@]} reader(s) derived from the merged closure [${CORO_EXPORTS_DERIVED[*]#--export-if-defined=}] -- the kernel runtime imports whichever its cascade reads and the loader binds them from the main." >&2
echo "wasmld: NOTE (owner audit): force-export owners recorded (main=$_owners_main both=$_owners_both libc.so=$_owners_libc[dropped] rt=$_owners_rt[dropped]) -> $OUT.export-owners" >&2
fi
finallink_err="$WORK/finallink.err"
if [[ $IS_SHARED == 1 ]]; then
# ── -shared final link: PIC dylib (no memory sizing — the .so lives in
# the MAIN's memory; no crt, no export superset — the caller's --export
# flags arrive via LINK_FLAGS). NATIVE_INPUTS is empty (refused above).
# Side-module TLS export surface. lld synthesizes __tls_size, __tls_align
# and __wasm_init_tls only when something references them, so the hard
# exports are what makes them exist; the loader needs all four to give a
# new thread its own block and to re-bind a replayed Instance.
if [[ "$SIDE_TLS" == "1" ]]; then
LINK_FLAGS+=( --export=__tls_base --export=__tls_size --export=__tls_align --export=__wasm_init_tls )
fi
# libc.so PRODUCER export surface (S2-owed, PLAN-DYNAMIC-LIBC):
# --export=__tls_base — lld exports the synthetic mutable global when explicitly asked
# (Writer.cpp:806-816); the S2 §3 identity design (per-module physical, process-scope
# logical, host dual-write) rides this one flag;
# --export=__libc_start_main — the ONE crossing at the start seam (S2 §6.1), added whenever
# the merged closure DEFINES it (the real libc always; a toy fixture may not);
# WASMLD_LIBC_SO_EXPORTS — the crossing-data surface (S5 §1: stdin/out/err, environ group,
# optind family, in6addr_any, daylight group for musl), spelled by the rig that owns the
# closure; each is a HARD --export (a missing name is refused by (4b), never
# if-defined silence: under --allow-undefined wasm-ld itself says nothing).
if [[ "$LIBC_SO" == "1" ]]; then
LINK_FLAGS+=( --export=__tls_base )
# Global definitions only: a local one (b/d/r/t) cannot be exported, and
# a --export of its name is dropped without a word (glibc's _dlfcn_hook
# is static here and still in the Versions superset).
_dyn_defs="$(hwjs_nm --defined-only "$WORK/merged.bc" 2>/dev/null | awk 'NF >= 2 && $(NF-1) !~ /^[bdrt]$/ {print $NF}' | sort -u)"
line_in_v _dyn_defs __libc_start_main
if [[ $LINE_IN == 1 ]]; then
LINK_FLAGS+=( --export=__libc_start_main )
else
echo "wasmld: NOTE (WASMLD_LIBC_SO): merged closure defines no __libc_start_main — start-seam export skipped (legal only for a toy/fixture closure; the real libc.so always carries it, S2 §6.1)." >&2
fi
if [[ -n "${WASMLD_LIBC_SO_EXPORTS:-}" ]]; then
echo "wasmld: NOTE (WASMLD_LIBC_SO): exporting crossing surface [${WASMLD_LIBC_SO_EXPORTS}] (hard --export each)." >&2
for _dyne in ${WASMLD_LIBC_SO_EXPORTS}; do
LINK_FLAGS+=( "--export=${_dyne}" )
done
fi
# ── G2 §4.1: export the TLS-template SIZING ABI — the module-#1 TLS
# owner's contract with the loader (it sizes libc.so's bootstrap TLS
# block via these before libc.so's ctors, then binds/dual-writes
# __tls_base). if-defined because the sizing accessors come from the
# glibc native-as-bitcode shim (a TLS-less toy closure defines none) and
# __wasm_init_tls is lld-synthesized only for a TLS-bearing image. The
# 29 thread_local names themselves stay hidden and UNexported (asserted
# below + post-link) — only the sizing ABI + the §12 __tls_base global
# cross the seam.
for _tlsx in __wasm32_get_tls_size __wasm32_get_tls_align \
__wasm32_get_tls_base __wasm32_set_tls_base __wasm_init_tls; do
LINK_FLAGS+=( "--export-if-defined=${_tlsx}" )
done
# ── R6 EXPORT-PROMOTION AT SCALE (glibc arm; spike G1 "R6 export
# promotion"). glibc seals its PUBLIC ABI `hidden` in the pool (unlike
# musl's default-visibility pool), so a bare -shared auto-exports NOTHING
# of it — the ~10^3 public names must be promoted EXPLICITLY.
# WASMLD_LIBC_SO_EXPORTS_FILE is the derived public-name SUPERSET (glibc
# Versions union, one name per line). We INTERSECT it with the merged
# closure's DEFINED symbols (authoritative — only what this libc.so
# actually defines is --export'd, so every promoted name is known-present:
# a hard --export, never if-defined silence) and REFUSE loudly if any
# thread_local (the pass's own TLS-CENSUS set) or __GI_ internal alias
# would be promoted.
if [[ -n "${WASMLD_LIBC_SO_EXPORTS_FILE:-}" ]]; then
[[ -f "$WASMLD_LIBC_SO_EXPORTS_FILE" ]] \
|| fatal "WASMLD_LIBC_SO_EXPORTS_FILE=$WASMLD_LIBC_SO_EXPORTS_FILE does not exist — the R6 public-ABI export superset (glibc Versions union) is a required producer input on the glibc export-promotion arm."
# the pass's OWN authoritative thread_local census (names=[...]) — the
# never-silent guard against a superset generator that failed to
# exclude a TLS name (a hard --export of a hidden thread_local would
# force-export a meaningless TP-relative wasm global).
_dyn_tls_names="$(sed -n 's/.*TLS-CENSUS tls_globals=[0-9]* names=\[\(.*\)\].*/\1/p' "$hwjs_err" | tr ' ' '\n' | { grep -E '^[A-Za-z_]' || true; } | LC_ALL=C sort -u)"
LC_ALL=C sort -u "$WASMLD_LIBC_SO_EXPORTS_FILE" > "$WORK/exports.superset"
# re-sort the closure's defined set under the SAME LC_ALL=C collation
# (it was sorted in the caller's locale above) so comm's sorted-order
# contract holds — a locale skew silently drops real exports.
printf '%s\n' "$_dyn_defs" | LC_ALL=C sort -u > "$WORK/exports.defined"
_dyn_promote="$(LC_ALL=C comm -12 "$WORK/exports.superset" "$WORK/exports.defined")"
_dyn_leak_tls="$(LC_ALL=C comm -12 <(printf '%s\n' "$_dyn_promote") <(printf '%s\n' "$_dyn_tls_names") 2>/dev/null)"
_dyn_leak_gi="$(printf '%s\n' "$_dyn_promote" | grep -E '^__GI_' || true)"
if [[ -n "$_dyn_leak_tls" || -n "$_dyn_leak_gi" ]]; then
[[ -n "$_dyn_leak_tls" ]] && printf 'wasmld: promoted thread_local (must stay hidden/TP-relative): %s\n' $_dyn_leak_tls >&2
[[ -n "$_dyn_leak_gi" ]] && printf 'wasmld: promoted __GI_ internal alias: %s\n' $_dyn_leak_gi >&2
fatal "WASMLD_LIBC_SO: the R6 export superset ($WASMLD_LIBC_SO_EXPORTS_FILE) intersects the closure at thread_local and/or __GI_ name(s) named above — force-exporting a hidden thread_local (a TP-relative internal, meaningless as a wasm global export) or a __GI_ PLT-avoidance alias is a broken export surface. Exclude them from the superset generator (they are libc-internal, not the public ABI). Refusing."
fi
_dyn_promote_n="$(printf '%s\n' "$_dyn_promote" | grep -c . || true)"
_dyn_superset_n="$(grep -c . "$WORK/exports.superset" || true)"
echo "wasmld: NOTE (WASMLD_LIBC_SO R6): promoting $_dyn_promote_n public name(s) to the export surface (Versions superset $_dyn_superset_n ∩ closure-defined; $((_dyn_superset_n - _dyn_promote_n)) superset names absent from this wasm32 build — legitimately not built). thread_local + __GI_ excluded." >&2
while IFS= read -r _dynp; do
[[ -n "$_dynp" ]] && LINK_FLAGS+=( "--export=${_dynp}" )
done <<<"$_dyn_promote"
fi
fi
# ── libc.so PRODUCER address-taken-UNDEFINED pre-link GUARD (WASMLD_LIBC_SO
# arm; spike docs/plans/spikes/G1-glibc-pic-pool.md "Residual risks" 1).
# A function whose ADDRESS is taken while it is UNDEFINED in the merged
# closure crashes the pinned wasm-ld in ElemSection::writeBody() ->
# FunctionSymbol::getFunctionIndex() — a SIGSEGV, NOT the clean
# R_WASM_TABLE_INDEX_REL_SLEB error the post-link wrap below catches —
# while building the __indirect_function_table element segment. The
# producer arm refuses native inputs (above), so glibc's native TLS
# accessors + syscall stubs (obj/csu/wasm-thread.o, libglibc_native.a)
# are UNDEFINED unless rebuilt as PIC bitcode; a census found EXACTLY ONE
# address-taken among them (__execve, taken by __spawni). Diagnose it
# HERE, by name, before the crash: intersect merged.o's TABLE_INDEX
# relocation targets (the address-taken set) with its undefined function
# symbols. merged.o is the coroutinized wasm object about to enter
# wasm-ld — the exact input that segfaults. Never a segfault; always a
# named refusal.
if [[ "$LIBC_SO" == "1" ]]; then
_lso_undef="$(hwjs_nm --undefined-only "$WORK/merged.o" 2>/dev/null \
| awk '{print $NF}' | sort -u)"
_lso_ataken="$("$HWJS_LLVM_BIN/llvm-objdump" -r "$WORK/merged.o" 2>/dev/null \
| grep -oE 'R_WASM_TABLE_INDEX[A-Z0-9_]*[[:space:]]+[^[:space:]]+' \
| awk '{print $2}' | sed -E 's/\+[0-9]+$//' | sort -u)"
_lso_atk_undef="$(comm -12 <(printf '%s\n' "$_lso_ataken") <(printf '%s\n' "$_lso_undef") 2>/dev/null)"
# ── RT §11 GOT.func EXEMPTION (PLAN-DYNAMIC-LIBC; hwjs-rt-abi.rst §11
# "The runtime-op callable surface"). The guard above was written for
# NATIVE-shim symbols (glibc's __execve etc.) that the -shared arm refuses
# as inputs: those are expected-STATIC defs which, left undefined, place a
# dead entry in the __indirect_function_table element segment and SIGSEGV
# wasm-ld. But a §11 runtime-op name that a module ADDRESS-TAKES while
# undefined is a legitimate GOT.func IMPORT the host loader binds from the
# process's runtime provider (module #0 / the rt module; §10 partition
# note) — it lowers to a GOT.func. import under the -shared PIC arm,
# NOT an element-segment entry, so it never reaches the ElemSection crash.
# musl's libc.so plain-imports the sentinel; glibc address-takes it
# (llvm.used version-pairing per §8) — the same loader-provided symbol,
# tripping this guard only because glibc takes its address. Exempt EXACTLY
# the §11 RT-owned callable surface (the sentinel __hwjs_ds_region_abi_v2 +
# the frame/parked/park/xfer/drive/sjlj/region/progress ops + the
# compiler-glue thunks incl. the __hwjs_promise_* reader family) — NEVER a
# blanket skip: any NON-§11 address-taken-undefined (a native __execve-class
# shim) STILL fatals below. §10.2 kernel-registry ops (__hwjs_e8_refuse /
# *_lookup) are NOT here — they are vmlinux-owned imports, not §11, and no
# producer address-takes them (out of scope; add by name if one ever does).
_lso_rt_surface="$(printf '%s\n' \
__hwjs_frame_alloc __hwjs_frame_free __hwjs_frame_publish \
__hwjs_set_parked __hwjs_clear_parked __hwjs_take_parked __hwjs_noreturn_completed \
__hwjs_user_park __hwjs_park_take_result __hwjs_slice_enter __hwjs_slice_exit __hwjs_fork_barrier_ok \
__hwjs_xfer_descend __hwjs_xfer_park __hwjs_xfer_return __hwjs_xfer_take \
__hwjs_drive __hwjs_drive_resume __hwjs_drive_done_status \
hwjs_sj_record hwjs_lj_arm_from hwjs_lj_match hwjs_lj_selector hwjs_lj_value hwjs_lj_clear hwjs_lj_unwound hwjs_trap \
__hwjs_ds_region_abi_v2 __hwjs_region_alloc __hwjs_region_save __hwjs_region_restore __hwjs_freea \
__hwjs_register_suspends \
__hwjs_progress_note __hwjs_drive_watch __hwjs_progress_violation __hwjs_set_stall_bound \
__hwjs_pt_count __hwjs_pt_op __hwjs_pt_h __hwjs_pt_owner __hwjs_sanitize_store \
hwjs_resume hwjs_done hwjs_destroy \
| LC_ALL=C sort -u)"
# partition the address-taken-undefined set: §11 names (exact) + the
# __hwjs_promise_* thunk family are EXEMPT (loader-provided GOT.func); the
# residual is the genuine native-shim RED arm.
_lso_atk_refuse="$(printf '%s\n' "$_lso_atk_undef" \
| { grep -vxF -f <(printf '%s\n' "$_lso_rt_surface") || true; } \
| { grep -vE '^__hwjs_promise_' || true; } \
| grep -E '.' || true)"
_lso_atk_exempt="$(LC_ALL=C comm -23 <(printf '%s\n' "$_lso_atk_undef" | LC_ALL=C sort -u) \
<(printf '%s\n' "$_lso_atk_refuse" | LC_ALL=C sort -u) \
| grep -E '.' || true)"
if [[ -n "$_lso_atk_exempt" ]]; then
printf 'wasmld: NOTE (WASMLD_LIBC_SO): address-taken RT §11 GOT.func import(s) resolved by the loader from the runtime provider (hwjs-rt-abi.rst §11) — EXEMPT from the address-taken-undefined refusal: %s\n' $_lso_atk_exempt >&2
fi
if [[ -n "$_lso_atk_refuse" ]]; then
printf 'wasmld: address-taken + UNDEFINED: %s\n' $_lso_atk_refuse >&2
fatal "WASMLD_LIBC_SO: the merged libc.so closure ADDRESS-TAKES function symbol(s) that are UNDEFINED and are NOT part of the RT §11 loader-provided callable surface (named above) — wasm-ld would SIGSEGV building the __indirect_function_table element segment (ElemSection::writeBody -> getFunctionIndex; spike G1 risk 1), not print a clean error. These are native-object symbols the -shared arm refuses as inputs and that were not rebuilt as PIC bitcode: on the glibc arm the known case is __execve (address-taken by __spawni / posix_spawn), which must ride the glibc native-as-bitcode shim ('make -C sysroot glibc-native-bc-pic' -> build/glibc-native-shims.pic.bc, joined via WASMLD_HWJS_TLS_ACCESS_BC). Rebuild the missing symbol(s) as PIC bitcode and re-link. Refusing rather than segfaulting."
fi
fi
# EXPORT_PASS_OWNED_SYMBOLS — a package's version script must not hide the
# PASS's own symbols (brintos/brintium#3; gate:
# test/shared-version-script-pass-abi.sh).
#
# wasmld forwards --version-script to wasm-ld, which is right: wasm
# collapses the versioning half of a GNU version script but honours the
# global:/local: half as export visibility, and consuming it had been
# discarding each module's declared export surface. What it also does is
# apply `local: *` to symbols the package has never heard of. The
# coroutinize pass emits its runtime surface as WEAK definitions —
# @__hwjs_budget, @__hwjs_module_id, the F117 registrars
# (__hwjs_register_suspends / _capsummary / _fpcast_adapter), the promise
# readers, the loud handlers — and no package's script names any of them,
# so applyVersionScript() (lld/wasm/Driver.cpp) calls setHidden(true) on
# every one.
#
# `hidden` is the shared term in all three of the linker's decisions about
# a weak definition in a -shared link, so one setHidden removes three
# things at once: the symbol is not exported (Symbols.cpp isExported), not
# imported (Writer.cpp shouldImport — the clause whose own comment is "we
# need to both import and export the symbol"), and its address-takes
# become internal GOT entries rather than GOT imports (Relocations.cpp
# requiresGOTAccess). The import is the one that matters: the loader binds
# the per-instance budget and the main-/kernel-owned registrar ops through
# env, so a version-scripted side module gets a budget that stays at the
# weak-0 default (every consumer dies in __wasm_call_ctors ->
# __hwjs_budget_sanity before its own code runs) and registers its
# suspends and capability summaries into its OWN weak no-op stubs instead
# of the process and kernel registries — a silent misdispatch, not a load
# refusal. Measured on core-image-brintos-emcraft: 88 of 220 side modules,
# 25 recipes, every one of them a package that passes a version script.
#
# applyVersionScript() skips isExportedExplicit() symbols — "command-line
# exports are authoritative and must never be dropped" — and --export/
# --export-if-defined set forceExport before it runs. So naming them is the
# sanctioned way out, and it is what __hwjs_budget_set/_get and
# __hwjs_drive_abi already get for free from their wasm-export-name attr.
#
# DERIVED FROM THE ARTIFACT, never a list: the pass grows ops, and a list
# written today is wrong the first time it does — silently, in the
# misdispatch direction. llvm-nm separates the classes exactly: W is a
# pass-emitted weak definition (at risk), t/d is already-local (must NOT be
# exported), U is already an import (unaffected). -if-defined because a
# module with no safepoint placed carries no budget global at all.
#
# No-op without a version script: the symbols are already exported there,
# and the re-linked module is identical section for section but for the
# debug name section.
if [[ $IS_SHARED == 1 ]]; then
_pass_owned=()
# `if`, not `&&`: under `set -e` a loop whose LAST iteration ends on a
# false test exits non-zero and takes the whole link with it.
while read -r _kind _name; do
if [[ "$_kind" == "W" ]]; then
_pass_owned+=( "--export-if-defined=$_name" )
fi
done < <(hwjs_nm "$WORK/merged.o" 2>/dev/null \
| awk 'NF >= 2 && $NF ~ /^__hwjs_/ { print $(NF - 1), $NF }')
if [[ ${#_pass_owned[@]} -gt 0 ]]; then
LINK_FLAGS+=( "${_pass_owned[@]}" )
printf 'wasmld: NOTE (EXPORT_PASS_OWNED_SYMBOLS): pinned %d pass-emitted weak symbol(s) against a version script: %s\n' \
"${#_pass_owned[@]}" "${_pass_owned[*]#--export-if-defined=}" >&2
fi
fi
# Every hard --export on this line, the driver's own included, for (4b):
# link_shared runs under --allow-undefined, where wasm-ld drops one it
# cannot define without a word.
caller_export_names hard "${LINK_FLAGS[@]}"
SHARED_EXPORTS_HARD=( ${CALLER_EXPORT_NAMES[@]+"${CALLER_EXPORT_NAMES[@]}"} )
set +e
final_link_head
link_shared "${LINK_FLAGS[@]}" "${FINAL_HEAD[@]}" -o "$OUT" 2>"$finallink_err"
link_rc=$?
set -e
cat "$finallink_err" >&2
if [[ $link_rc -ne 0 ]]; then
# Attributed wrap of the cryptic dso_local/TABLE_INDEX_REL_SLEB refusal
# (issue #52 secondary finding 1's backstop — the path-keyed pool-member
# pre-refuse above catches the configured pool; THIS catches a
# libc-internal-assuming TU arriving from anywhere else).
if grep -q 'R_WASM_TABLE_INDEX_REL_SLEB' "$finallink_err" \
&& grep -qi 'undefined' "$finallink_err"; then
fatal "-shared final link refused with R_WASM_TABLE_INDEX_REL_SLEB relocations against undefined symbol(s) (wasm-ld error above). This is the LIBC-POOL-MEMBER-IN-A-.so shape: the input carries dso_local-keyed address-takes of symbols it expects the surrounding libc to define (glibc's pthread-cleanup handlers are the known case), which a PIC side module cannot express. Pool members / libc-internal TUs cannot ride a -shared link — bind the libc API from the MAIN instead (WASMLD_DYN_EXPORT_LIBC on the main's link) or use a self-contained PIC TU (issue linux-in-the-browser#52)."
fi
# Attributed wrap of the cryptic dso_local/MEMORY_ADDR_REL_SLEB refusal
# (PLAN-DYNAMIC-LIBC "third blocker" backstop). The crt/dynamic
# boundary-definition seed above defines the CLOSED allowlist of hidden
# DATA symbols glibc references dso_local; THIS catches a hidden-data
# REL_SLEB reference to a symbol NOT on that allowlist (a genuinely-missing
# data TU), naming it instead of leaving the cryptic wasm-ld error. Keeps
# the RED arm: only the enumerated crt/dynamic bounds are stubbed; a novel
# undefined data symbol still refuses.
if [[ "$LIBC_SO" == "1" ]] \
&& grep -q 'R_WASM_MEMORY_ADDR_REL_SLEB' "$finallink_err" \
&& grep -qi 'undefined' "$finallink_err"; then
_bnd_resid="$(grep -oE 'R_WASM_MEMORY_ADDR_REL_SLEB is not supported against an undefined symbol `[^`]+`' "$finallink_err" \
| sed -E 's/.*`([^`]+)`.*/\1/' | LC_ALL=C sort -u | tr '\n' ' ')"
fatal "WASMLD_LIBC_SO: -shared final link refused with R_WASM_MEMORY_ADDR_REL_SLEB relocation(s) against undefined DATA symbol(s) [ ${_bnd_resid}] NOT covered by the crt/dynamic boundary-definition seed (wasm-ld error above). A -shared PIC producer lowers a dso_local (hidden) data reference to a fixed-layout REL_SLEB reloc that cannot be left undefined and cannot ride as a GOT import; the non-PIC main link resolves these to 0. Either the symbol is a genuinely-missing pool data TU (add it via build-glibc-libc.sh) or a new inert crt/dynamic boundary that belongs on the seed's allowlist (libexec/brintld, the '_lso_bnd_allow' set). Refusing rather than shipping an unlinkable closure."
fi
exit $link_rc
fi
# ── SINGLE-RECORD MANIFEST invariant, enforced on the FINAL BYTES: lld
# concatenates same-named custom sections, so any second hwjs.abi record
# (a smuggled pre-sectioned object, a future regression) must refuse
# here, at the artifact, not at the host loader. Exactly ONE hwjs.abi
# custom section, carrying exactly ONE v1 record (8 one-byte LEB fields).
manifest_shape="$(hwjs_abi_manifest_shape "$OUT")" || fatal "-shared: could not parse the final .so's custom sections for the hwjs.abi manifest check. Refusing."
# ── SIDE-MODULE TLS AUDIT on the FINAL BYTES. A thread_local's export value
# is its offset into the module's TLS block, and the loader resolves an
# exported data symbol as __memory_base + value — a consumer would bind a
# wrong address with nothing to say so. The drivers compile with
# -fvisibility=default, so a non-static thread_local IS exported unless
# this refuses. The four binding exports must all be present.
if [[ "$SIDE_TLS" == "1" ]]; then
_side_tls_names="$(sed -n 's/.*TLS-CENSUS tls_globals=[0-9]* names=\[\(.*\)\].*/\1/p' "$hwjs_err" | tr ' ' '\n' | { grep -E '^[A-Za-z_]' || true; } | LC_ALL=C sort -u)"
_side_tls_exports="$(export_names "$OUT" 2>&1 | LC_ALL=C sort -u)" || { echo "$_side_tls_exports" >&2; rm -f "$OUT"; fatal "-shared: cannot read the final .so's export surface for the side-module TLS audit. Refusing and removing the artifact."; }
_side_tls_leak="$(LC_ALL=C comm -12 <(printf '%s\n' "$_side_tls_exports") <(printf '%s\n' "$_side_tls_names") 2>/dev/null)"
if [[ -n "$_side_tls_leak" ]]; then
printf 'wasmld: EXPORTED thread_local: %s\n' $_side_tls_leak >&2
rm -f "$OUT"
fatal "-shared: the side module EXPORTS thread_local name(s) named above — an exported thread_local's value is an offset into its TLS block, which a consumer would bind as an address. Give them hidden visibility (or static linkage); a thread_local cannot be shared across modules on this target. Refusing and removing the artifact."
fi
for _side_tls_sym in __tls_base __tls_size __tls_align __wasm_init_tls; do
line_in_v _side_tls_exports "$_side_tls_sym"
[[ $LINE_IN == 1 ]] || {
rm -f "$OUT"
fatal "-shared: the side module owns TLS but its final bytes do not export $_side_tls_sym — the loader cannot bind its per-thread block without it. Refusing and removing the artifact."
}
done
echo "wasmld: NOTE (side-module TLS audit): TLS binding exports present; 0 thread_local exported (of $(printf '%s\n' "$_side_tls_names" | grep -c .) census names)." >&2
fi
if [[ "$LIBC_SO" == "1" || "$RT_SO" == "1" || -n "${WASMLD_HWJS_XMOD_PARTITION_LIBC:-}" ]]; then
# Dynamic-libc arms + the runtime producer (both PUBLISH a partition, so
# both stamp v2): ONE v2 record of exactly 10 LEB fields (8 v1 fields +
# suspender-partition digest + refused-exports count — hwjs-rt-abi §9.4
# bump ceremony; wasmld's byte-shape check updated in LOCKSTEP here; the
# loader-side pin is loader scope).
case "$manifest_shape" in
"1 2 10 "*) : ;;
*)
rm -f "$OUT"
fatal "-shared (dynamic-libc arm): final .so's hwjs.abi manifest is not the ONE v2 10-field record (got 'sections version nfields payload-bytes' = '$manifest_shape', require '1 2 10 *') — the dynamic-libc arms stamp suspender-partition digest + refused-exports as fields 9/10 (PLAN-DYNAMIC-LIBC §3.2). A stale plugin or a second smuggled record; refusing and removing the artifact." ;;
esac
elif [[ "$manifest_shape" != "1 1 8 8 "* ]]; then
rm -f "$OUT"
fatal "-shared: final .so's hwjs.abi manifest is malformed: got 'sections version nfields payload-bytes drive_abi' = '$manifest_shape', require '1 1 8 8 *' (exactly ONE section, ONE v1 record of 8 one-byte LEB fields; only the dynamic-libc partition arms are v2). A second record means a pre-sectioned object reached wasm-ld (lld concatenates same-named custom sections) — the single-record invariant is broken. Refusing and removing the artifact."
fi
# drive_abi FIELD value (manifest field 2) must match this link's drive
# expectation — the byte-shape pin's version-keyed acceptance learning 4
# (STATUS-CHANNEL-CONTRACT §10). The DRIVE-CONTRACT log check above pins
# the pass's claim; this pins the FINAL BYTES the loader will audit, so a
# manifest/log skew (second smuggled record, stale pre-sectioned object)
# cannot ship an .so whose stamped abi lies to the loader's want-table pin.
_mf_drive_abi="$(awk '{print $5}' <<<"$manifest_shape")"
if [[ "${HWJS_STATUS_CHANNEL:-0}" == "1" ]]; then _mf_expect_abi=4
elif [[ "$HWJS_DRIVE_FLAT" == "0" ]]; then _mf_expect_abi=2
else _mf_expect_abi=3; fi
if [[ "$_mf_drive_abi" != "$_mf_expect_abi" ]]; then
rm -f "$OUT"
fatal "-shared: final .so's hwjs.abi manifest stamps drive_abi=$_mf_drive_abi but this link's drive expectation is drive_abi=$_mf_expect_abi (HWJS_STATUS_CHANNEL=${HWJS_STATUS_CHANNEL:-unset}, HWJS_DRIVE_FLAT=$HWJS_DRIVE_FLAT) — manifest/expectation skew: the loader's version-keyed want-table pin would refuse (or worse, accept a mis-stamped image). Refusing and removing the artifact."
fi
# lanes bit (flags bit5, lane_addressed — PLAN-THREADS-SINGLE-MEMORY §4
# step 2): the FINAL BYTES must agree with this driver's lane-addressing switch
# knob, exactly like drive_abi above — a mis-stamped bit would either
# defeat the loader's lane-mixing refusal (bit absent on a lane-addressed
# image: a lane-unaware peer mixes in silently and reads lane 0 from any
# lane, I3-2) or refuse a correct image (bit present on an absolute one).
_mf_flags="$(awk '{print $6}' <<<"$manifest_shape")"
_mf_lane_bit=$(( (_mf_flags & 32) != 0 ? 1 : 0 ))
if [[ "$_mf_lane_bit" != "${HWJS_LANE_ADDR:-0}" ]]; then
rm -f "$OUT"
fatal "-shared: final .so's hwjs.abi manifest stamps flags bit5 lane_addressed=$_mf_lane_bit but this link's lane-addressing switch says $( [[ "${HWJS_LANE_ADDR:-0}" == "1" ]] && echo "lane-aware" || echo "absolute (off)" ) — manifest/knob skew: the loader's lane-mixing refusal (I3-2) would judge this image wrongly. Stale plugin or a smuggled record; refusing and removing the artifact."
fi
# ── libc.so PRODUCER post-link (WASMLD_LIBC_SO=1): cross-verify the PUBLISHED verdicts against the
# FINAL BYTES' name section (the gen-so-import-surface --verify discipline: a fn export is a
# suspender iff its name-section-resolved function has a ".resume" or " (.resume)" clone), then install the
# partition at WASMLD_LIBC_SO_PARTITION_OUT. A publish/artifact divergence is the link-time
# derivation-loss class the digest lockstep exists to make detectable — refuse and remove, never install.
if [[ "$LIBC_SO" == "1" ]]; then
_pverify="$("$BRINT_TOOL" verify-partition "$OUT" "$WORK/partition.pub" 2>&1)" || {
echo "$_pverify" | sed 's/^/wasmld: partition-verify: /' >&2
rm -f "$OUT"
fatal "WASMLD_LIBC_SO: the PUBLISHED partition disagrees with the FINAL .so's name-section verdicts (lines above) — the link-time derivation-loss class the digest lockstep exists to catch. Refusing and removing the artifact (PLAN-DYNAMIC-LIBC §3.2)."
}
echo "wasmld: NOTE (WASMLD_LIBC_SO): $_pverify" >&2
# ── R6 EXPORT AUDIT on the FINAL BYTES (never-silent teeth; spike G2
# §4.1 R6 invariant + G1 R6). The 29 thread_local names (the pass's own
# TLS-CENSUS set) and every __GI_ internal alias MUST stay UNexported: a
# thread_local is TP-relative (its "global" export is a meaningless
# offset a consumer would bind as a real address), and __GI_ is a
# PLT-avoidance internal. They are hidden in the pool (so -shared never
# auto-exports them) and excluded from the R6 promotion superset — but
# assert it on the ARTIFACT, so a future visibility/promotion regression
# refuses HERE rather than shipping a broken export to a live loader.
_dyn_exp_names="$(export_names "$OUT" 2>&1)" || { echo "$_dyn_exp_names" >&2; rm -f "$OUT"; fatal "WASMLD_LIBC_SO: cannot read the final .so's export surface for the R6 thread_local/__GI_ absence audit. Refusing and removing the artifact."; }
_dyn_tls_names_pl="$(sed -n 's/.*TLS-CENSUS tls_globals=[0-9]* names=\[\(.*\)\].*/\1/p' "$hwjs_err" | tr ' ' '\n' | { grep -E '^[A-Za-z_]' || true; } | LC_ALL=C sort -u)"
_dyn_exp_sorted="$(printf '%s\n' "$_dyn_exp_names" | LC_ALL=C sort -u)"
_dyn_exp_tls="$(LC_ALL=C comm -12 <(printf '%s\n' "$_dyn_exp_sorted") <(printf '%s\n' "$_dyn_tls_names_pl") 2>/dev/null)"
_dyn_exp_gi="$(printf '%s\n' "$_dyn_exp_sorted" | grep -E '^__GI_' || true)"
if [[ -n "$_dyn_exp_tls" || -n "$_dyn_exp_gi" ]]; then
[[ -n "$_dyn_exp_tls" ]] && printf 'wasmld: EXPORTED thread_local: %s\n' $_dyn_exp_tls >&2
[[ -n "$_dyn_exp_gi" ]] && printf 'wasmld: EXPORTED __GI_ alias: %s\n' $_dyn_exp_gi >&2
rm -f "$OUT"
fatal "WASMLD_LIBC_SO: the FINAL libc.so EXPORTS thread_local and/or __GI_ name(s) named above — neither is public ABI (a thread_local export is a meaningless TP-relative offset; __GI_ is an internal PLT-avoidance alias). This is the R6 never-silent gate on the artifact (spike G1/G2 R6). Refusing and removing."
fi
echo "wasmld: NOTE (WASMLD_LIBC_SO R6 audit): FINAL .so exports $(printf '%s\n' "$_dyn_exp_sorted" | grep -c .) name(s); 0 thread_local (of $(printf '%s\n' "$_dyn_tls_names_pl" | grep -c .) census names) and 0 __GI_ exported." >&2
# ── libc.so PRODUCER IMPORT-SURFACE AUDIT (S1 disposition closure; PLAN-DYNAMIC-LIBC §3.1).
# Every import of the final .so must be EXPLAINED: (a) self-bound — the module also EXPORTS
# the name (the F87 suspender-alias late-bound self-import + GOT self-resolution classes);
# (b) hwjs runtime/registrar/sentinel ops (__hwjs_*/hwjs_* — module #0/main surface, R4/#45
# loader machinery); (c) the S2-designed late-bound main-side set (tls size/align/init +
# canonical setter); (d) the raw `linux` syscall module; (e) the dylib spine (env memory/
# table/__stack_pointer/__memory_base/__table_base). ANY residue is a LINK FATAL — the known
# class is the compiler-rt builtins (__addtf3 family) when WASMLD_HWJS_LIBC_BUILTINS_BC is
# missing/incomplete; without this gate the residue surfaces as a module-#1 instantiate
# LinkError on a LIVE machine (the never-silent doctrine's exec-time class).
# WASMLD_LIBC_SO_IMPORT_ALLOW: space-separated names the closure's OWNER acknowledges as
# deliberate late-bound imports (the toy fixtures' opaque-escape sinks). Same by-name
# ceremony class as WASMLD_LIBC_SO_UNWIND_WAIVE — each use is a loud NOTE, never a default.
if [[ -n "${WASMLD_LIBC_SO_IMPORT_ALLOW:-}" ]]; then
echo "wasmld: NOTE (WASMLD_LIBC_SO_IMPORT_ALLOW): acknowledging deliberate late-bound import(s) [${WASMLD_LIBC_SO_IMPORT_ALLOW}] in the import-surface audit — the loader must bind each at module-#1 instantiate or refuse loudly." >&2
fi
_iaudit="$("$BRINT_TOOL" libc-import-audit "$OUT" "--allow=${WASMLD_LIBC_SO_IMPORT_ALLOW:-}" 2>&1)" || {
echo "$_iaudit" | sed 's/^/wasmld: import-audit: /' >&2
rm -f "$OUT"
fatal "WASMLD_LIBC_SO: the final .so carries UNEXPLAINED imports (lines above) — each would be an unresolvable binding at module-#1 instantiate on a live machine. Soft-float/wide-int names (__addtf3 class) mean the compiler-rt builtins TU is missing/incomplete: build it ('make -C sysroot builtins-pic') or point WASMLD_HWJS_LIBC_BUILTINS_BC at it. Refusing and removing the artifact (PLAN-DYNAMIC-LIBC §3.1/S1)."
}
echo "wasmld: NOTE (WASMLD_LIBC_SO): $_iaudit" >&2
cp -f "$WORK/partition.pub" "$WASMLD_LIBC_SO_PARTITION_OUT.tmp.$$" \
&& mv -f "$WASMLD_LIBC_SO_PARTITION_OUT.tmp.$$" "$WASMLD_LIBC_SO_PARTITION_OUT" \
|| fatal "WASMLD_LIBC_SO: failed to install the published partition at $WASMLD_LIBC_SO_PARTITION_OUT."
echo "wasmld: NOTE (WASMLD_LIBC_SO): published suspender partition -> $WASMLD_LIBC_SO_PARTITION_OUT (sha256 $(sha256sum "$WASMLD_LIBC_SO_PARTITION_OUT" | cut -c1-16)…; digest lo64 stamped in the hwjs.abi v2 manifest)." >&2
fi
# runtime-module producer: install the published rt partition (its Track
# M record; nothing consumes it yet — the rt ops' suspend surface is
# source-annotated at every consumer compile — but the record must
# exist and travel with the artifact, never-silent).
if [[ "$RT_SO" == "1" ]]; then
# The runtime's partition is legitimately EMPTY (its ops publish no
# partitioned exports — the manifest's digest_lo64 e3b0c44… empty-input
# attestation): the pass then emits no file. Install the honest empty
# record rather than refusing — the manifest still stamps the digest.
[[ -f "$WORK/partition.pub" ]] || : > "$WORK/partition.pub"
cp -f "$WORK/partition.pub" "$WASMLD_RT_SO_PARTITION_OUT.tmp.$$" \
&& mv -f "$WASMLD_RT_SO_PARTITION_OUT.tmp.$$" "$WASMLD_RT_SO_PARTITION_OUT" \
|| fatal "WASMLD_RT_SO: failed to install the published partition at $WASMLD_RT_SO_PARTITION_OUT."
echo "wasmld: NOTE (WASMLD_RT_SO): published runtime suspender partition -> $WASMLD_RT_SO_PARTITION_OUT ($(wc -c < "$WASMLD_RT_SO_PARTITION_OUT") bytes; sha256 $(sha256sum "$WASMLD_RT_SO_PARTITION_OUT" | cut -c1-16)…)." >&2
fi
else
# ── WEAK-UNDEFINED FUNCTIONS libc.so EXPORTS: bound from it at load, as ELF binds them.
# The fixed-layout main is not PIC, and lld's handleWeakUndefines (lld/wasm/SymbolTable.cpp)
# gives every weak-undefined function on a non-PIC link a null-address `unreachable` stub,
# --unresolved-symbols=import-dynamic notwithstanding — so `extern int pthread_create(...)
# __attribute__((weak))` read NULL in the guest although libc.so defines it (libstdc++'s
# __gthread_active_p, getauxval probes). A -shared side module never meets this: it is PIC,
# and lld imports a weak undefined there for the loader to bind. Here the binding bit of each
# such symbol in the relocatable inputs is cleared before the link, so the reference becomes
# the env (and GOT.func) import a strong one gets from module #1. Only names libc.so exports
# as functions are touched: a weak function nothing provides keeps lld's null, the ELF outcome,
# and a name in WASMLD_ALLOW_NULL_WEAK keeps it by request. A native archive member is not
# rewritten; gate (d) after the link still judges whatever stays null-stubbed.
if [[ "$LIBC_IMPORT" == "1" ]]; then
_wb_allow="${WASMLD_ALLOW_NULL_WEAK:-}"
_wb_allow=" ${_wb_allow//,/ } "
_wb_names=()
# Gate (d) after the link takes these names again while no input has been
# rewritten in between.
_wb_listing_ok=0
if _wb_listing="$(run_llvm_bulk hwjs_nm "$WORK/merged.o" ${NATIVE_INPUTS[@]+"${NATIVE_INPUTS[@]}"} 2>/dev/null \
| awk '$1 == "w" { print $NF }' | sort -u)"; then _wb_listing_ok=1; fi
while IFS= read -r _wsym; do
[[ -z "$_wsym" || "$_wb_allow" == *" $_wsym "* ]] && continue
line_in_v _libc_exports "function $_wsym"
[[ $LINE_IN == 1 ]] && _wb_names+=( "$_wsym" )
done <<<"$_wb_listing"
if (( ${#_wb_names[@]} )); then
_wb_bound=()
_wb_i=0
for _wb_in in "$WORK/merged.o" ${NATIVE_INPUTS[@]+"${NATIVE_INPUTS[@]}"}; do
file_kind_v "$_wb_in"
[[ "$FILE_KIND" == wasm ]] || continue
_wb_i=$(( _wb_i + 1 ))
_wb_out="$WORK/weak-bound.$_wb_i.o"
_wb_did="$("$BRINT_TOOL" strong-undefs "$_wb_in" "$_wb_out" "${_wb_names[@]}" 2>&1)" || { echo "$_wb_did" >&2; fatal "WASMLD_LIBC_IMPORT: could not clear the weak binding of [${_wb_names[*]}] in '$_wb_in' — left weak, lld would null-stub what libc.so defines."; }
[[ -z "$_wb_did" ]] && { rm -f "$_wb_out"; continue; }
_wb_listing_ok=0
if [[ "$_wb_in" == "$WORK/merged.o" ]]; then
mv -f "$_wb_out" "$WORK/merged.o"
else
for _wb_k in "${!NATIVE_INPUTS[@]}"; do
[[ "${NATIVE_INPUTS[$_wb_k]}" == "$_wb_in" ]] && NATIVE_INPUTS[$_wb_k]="$_wb_out"
done
fi
while IFS= read -r _wsym; do _wb_bound+=( "$_wsym" ); done <<<"$_wb_did"
done
if (( ${#_wb_bound[@]} )); then
echo "wasmld: NOTE (weak-undefined): fn [$(printf '%s\n' "${_wb_bound[@]}" | sort -u | tr '\n' ' ' | sed 's/ $//')] exported by libc.so — imported from it, so the loader binds each as ELF would (a weak function nothing provides keeps lld's null)." >&2
fi
fi
fi
set +e
final_link_head
link_coro "${LINK_FLAGS[@]}" "${FINAL_HEAD[@]}" "${NATIVE_INPUTS[@]}" -o "$OUT" 2>"$finallink_err"
link_rc=$?
set -e
if [[ $link_rc -ne 0 ]]; then
needed_bytes="$(grep -oE 'initial memory too small, [0-9]+ bytes needed' "$finallink_err" | grep -oE '[0-9]+' | head -1 || true)"
if [[ -n "$needed_bytes" && -z "${WASMLD_INITIAL_PAGES:-}" ]]; then
auto_pages=$(( (needed_bytes + 65535) / 65536 + 16 ))
if (( auto_pages > MAX_PAGES )); then
cat "$finallink_err" >&2
fatal "static layout needs $needed_bytes bytes ($auto_pages pages incl. headroom), which exceeds --max-memory=$MAX_PAGES pages. Raise WASMLD_MAX_PAGES deliberately."
fi
echo "wasmld: NOTE (initial-memory auto-size): the default $INIT_PAGES pages is too small for this image's static layout ($needed_bytes bytes needed) — re-linking at $auto_pages pages. Pin WASMLD_INITIAL_PAGES to make the floor an explicit contract." >&2
INIT_PAGES=$auto_pages
link_coro "${LINK_FLAGS[@]}" "${FINAL_HEAD[@]}" "${NATIVE_INPUTS[@]}" -o "$OUT" \
|| { link_rc=$?; fatal "final link failed again after initial-memory auto-size to $auto_pages pages (rc=$link_rc; error above)."; }
else
cat "$finallink_err" >&2
exit $link_rc
fi
else
cat "$finallink_err" >&2
fi
fi # IS_SHARED final-link split
# ── (4b) THE LINK LINE'S HARD --export REQUESTS, against the final bytes.
# wasm-ld writes an export entry only for a symbol the image defines
# (lld/wasm/Writer.cpp, calculateExports): it never aliases an imported
# function, so a --export of a name the image only imports emits nothing.
# It reports that only under --unresolved-symbols=report-all or warn (the
# requiredExports loop). The WASMLD_LIBC_IMPORT=1 program line runs under
# import-dynamic and the -shared line under --allow-undefined, and both
# drop the request with exit 0. So read the image's export section and
# refuse a requested name it does not carry: on a program, the caller's
# requests; on a side module, every hard request on its line.
# --export-if-defined is not checked: being silent about an absent symbol is
# what that spelling asks for.
if [[ $IS_SHARED == 1 ]]; then
_cx_want=( ${SHARED_EXPORTS_HARD[@]+"${SHARED_EXPORTS_HARD[@]}"} )
else
_cx_want=( ${CALLER_EXPORTS_HARD[@]+"${CALLER_EXPORTS_HARD[@]}"} )
fi
if [[ ${#_cx_want[@]} -gt 0 ]]; then
_cx_final="$("$BRINT_TOOL" exports "$OUT" --with-kind 2>&1)" \
|| { echo "$_cx_final" >&2; rm -f "$OUT"; fatal "cannot read the final image's export section to check the link line's --export requests. Refusing and removing the artifact."; }
_cx_final_names="$(awk 'NF >= 2 {print $2}' <<<"$_cx_final" | LC_ALL=C sort -u)"
_cx_missing=()
mapfile -t _cx_missing < <(LC_ALL=C comm -23 <(printf '%s\n' "${_cx_want[@]}" | LC_ALL=C sort -u) \
<(printf '%s\n' "$_cx_final_names"))
if [[ ${#_cx_missing[@]} -gt 0 ]]; then
# Read with the export reader, not llvm-nm, which refuses some linked
# modules outright ("global named more than once" on libc.so). A read
# that fails leaves the names unclassified; it never stops the refusal.
_cx_imports_ok=1
_cx_imports="$("$BRINT_TOOL" bound-imports "$OUT" 2>/dev/null | LC_ALL=C sort -u)" || _cx_imports_ok=0
_cx_named=()
for _cx_name in "${_cx_missing[@]}"; do
if [[ $_cx_imports_ok != 1 ]]; then
_cx_named+=("$_cx_name (not exported)")
continue
fi
line_in_v _cx_imports "$_cx_name"
if [[ $LINE_IN == 1 ]]; then
_cx_named+=("$_cx_name (imported, not defined)")
else
_cx_named+=("$_cx_name (neither defined nor imported)")
fi
done
rm -f "$OUT"
fatal "the link line asks to --export [$(IFS=,; echo "${_cx_named[*]}")] and the final image does not export it. wasm-ld writes an export only for a symbol this image defines: a name the image imports is not re-exported, and a name another module defines is that module's export, not this one's. Define it in the image, or spell the request --export-if-defined if its absence is acceptable. Refusing and removing the artifact."
fi
echo "wasmld: NOTE (hard exports): all ${#_cx_want[@]} name(s) the link line asks to --export are in the final image's export section." >&2
fi
# ── (5) RESIDUAL-INTRINSIC witness (FINDING 15's hole, closed at the
# link, 2026-06-11): --allow-undefined lets an UN-LOWERED llvm.*
# intrinsic survive as a synthesized wasm import — the image links
# silently and refuses to INSTANTIATE at run ("missing import
# env.llvm.coro.suspend"). First hit: the F89 sigsetjmp lowering
# leaking llvm.coro.suspend as an address-taken elem entry. Any llvm.*
# import in the FINAL image is an escaped intrinsic = refuse loudly.
#
# Binaryen (wasm-dis/wasm-opt) is RETIRED with emsdk, so this is now an
# emsdk-free, LLVM-only check that ACTUALLY RUNS against the final wasm:
# llvm-nm reads the linked image and an un-lowered intrinsic surfaces as
# an undefined `llvm.*` symbol (the synthesized import). A raw scan of
# the binary for `llvm.`-prefixed import-name strings is the backstop
# when llvm-nm is unavailable. The check runs UNCONDITIONALLY and is
# LOUD — if no tool can perform it, that itself is a build refusal,
# never a silent skip.
# OUT_LISTING_OK=1: _out_syms is a listing of the final image from an llvm-nm
# that succeeded, which the preemptibility scan below reads again.
residual=""; OUT_LISTING_OK=0
if [[ -x "$HWJS_NM" ]]; then
if _out_syms="$(hwjs_nm "$OUT" 2>/dev/null)"; then OUT_LISTING_OK=1; fi
nm_llvm_import_v _out_syms
if [[ $NM_LLVM_IMPORT == 1 ]]; then
nm_part_v _out_syms undefined
residual="$(awk '{print $NF}' <<<"$NM_PART" | grep '^llvm\.' | sort -u | head -5 || true)"
fi
elif command -v grep >/dev/null 2>&1; then
residual="$(grep -a -o 'llvm\.[A-Za-z0-9._]\+' "$OUT" 2>/dev/null \
| sort -u | head -5 || true)"
else
fatal "RESIDUAL-INTRINSIC witness cannot run: neither llvm-nm ('$HWJS_NM') nor grep is available to scan the final image for un-lowered llvm.* intrinsic imports. Refusing rather than silently skipping the check."
fi
[[ -z "$residual" ]] \
|| fatal "final image carries residual UN-LOWERED intrinsic import(s): ${residual} — an escaped llvm.* intrinsic survived to the binary (it would fail at instantiate, far from its cause). Refusing."
# ── (5b) PREEMPTIBILITY — the image property, checked against the FINAL BYTES ────────────────
#
# WHAT THIS REPLACES. Preemptibility used to be a convention: a comment in the loader, a sentence
# in six link recipes, and six function names typed into three distro Makefiles. Nothing compared
# any of it to the image that came out. A recipe that forgot the knob produced an image that could
# not be preempted and nothing said so; the loader's one check read a single bit that a
# three-checkpoint image and a whole-program image set identically.
#
# THE PROPERTY, stated over the artifact rather than over the build: every function DEFINED in
# this image either has no loop, or has only loops that provably terminate, provably yield, or
# carry a budget checkpoint in a frame that can park — or is in the exempt surface (the manual
# drive loop, and anything explicitly annotated native). The pass computes that over the merged
# module and stamps the verdict into hwjs.abi flags (bit6 with bit2: none / scoped /
# whole-program). This block reads the verdict back OFF THE FINAL BYTES — not off the log, not off
# an env var — and decides whether it is the verdict this link was supposed to produce.
#
# BOTH SIDES ARE DERIVED, NEITHER IS DECLARED. The expectation comes from whether checkpoints were
# armed for this link; the attestation comes from the artifact. There is no list of images, no list
# of functions, and no per-recipe opt-in to keep in sync with anything.
#
# THE DEFAULT IS THE STRONG ONE. Checkpoints are on unless someone turned them off, so an ordinary
# link is required to attest whole-program. HWJS_PREEMPTIBLE=none is the way to say otherwise, and
# it is a declaration in the link that produces the image rather than a name in a table somewhere
# else. It does not work on a lane-addressed link — see the second refusal.
{
_pm_want="${HWJS_PREEMPTIBLE:-}"
if [[ -z "$_pm_want" ]]; then
# No declaration: the demand follows the pass's own default. HWJS_CORO_SAFEPOINTS is
# value-keyed in the pass (unset/1 = armed, 0 = disarmed); mirror that reading exactly, so the
# driver and the pass can never disagree about what was asked for.
case "${HWJS_CORO_SAFEPOINTS:-}" in
0) _pm_want=none ;;
""|1) _pm_want=whole-program ;;
*) fatal "HWJS_CORO_SAFEPOINTS='${HWJS_CORO_SAFEPOINTS}' — value-keyed knob: 1 (armed), 0 (disarmed), or unset (armed, the default). Refusing to guess." ;;
esac
fi
case "$_pm_want" in
none|whole-program) ;;
scoped) fatal "HWJS_PREEMPTIBLE=scoped is not a thing a link may ask for. 'scoped' is a MEASUREMENT — it is what an image attests when checkpoints are armed and some loop in it still has neither a checkpoint nor a proof. It promises a consumer nothing, so demanding it would be demanding nothing while looking like a requirement. Ask for whole-program (and fix whatever the PREEMPT-OPEN census names), or declare none." ;;
*) fatal "HWJS_PREEMPTIBLE='$_pm_want' — accepted values are 'whole-program' (this image must be preemptible everywhere) and 'none' (this image is deliberately not preemptible; the reason belongs in the recipe next to the knob). Refusing to guess." ;;
esac
# Read the verdict off the artifact. The manifest is emitted by the ONE merged-module pass run
# on every coro-arm link now, static mains included, so its ABSENCE here is itself a finding: it
# means the plugin that compiled this module predates the attestation and cannot make the claim.
_pm_flags="$("$BRINT_TOOL" abi "$OUT" flags 2>&1)" \
|| { echo "$_pm_flags" >&2; rm -f "$OUT"; fatal "PREEMPTIBILITY: could not parse the final image's custom sections for the hwjs.abi manifest. Refusing and removing the artifact."; }
case "$_pm_flags" in
ABSENT)
rm -f "$OUT"
fatal "PREEMPTIBILITY: the final image carries NO hwjs.abi manifest, so it makes no claim about whether it can be preempted. Every coro-arm wasmld link runs the merged-module pass exactly once and that run emits the manifest — its absence means the loaded plugin predates the attestation. Rebuild it (toolchain/build.sh). Refusing and removing the artifact rather than shipping an image whose preemptibility nothing can state." ;;
MALFORMED)
rm -f "$OUT"
fatal "PREEMPTIBILITY: the final image's hwjs.abi manifest has fewer than 8 fields — flags is field 8 and is not there. A truncated or foreign record reached the artifact. Refusing and removing it." ;;
''|*[!0-9]*)
rm -f "$OUT"
fatal "PREEMPTIBILITY: unexpected hwjs.abi flags read '$_pm_flags' off the final image. Refusing and removing the artifact." ;;
esac
_pm_got=$(( (_pm_flags & 64) != 0 ? 2 : ((_pm_flags & 4) != 0 ? 1 : 0) ))
_pm_got_name=none; [[ $_pm_got == 1 ]] && _pm_got_name=scoped; [[ $_pm_got == 2 ]] && _pm_got_name=whole-program
_pm_open="$(grep -m20 '\[hwjs-coro\] PREEMPT-OPEN ' "$hwjs_err" 2>/dev/null || true)"
_pm_census="$(grep -m1 '\[hwjs-coro\] PREEMPT-CENSUS ' "$hwjs_err" 2>/dev/null || true)"
# REFUSAL 1 — this link was supposed to produce a preemptible image and did not.
if [[ "$_pm_want" == "whole-program" && $_pm_got != 2 ]]; then
[[ -n "$_pm_census" ]] && echo "$_pm_census" >&2
[[ -n "$_pm_open" ]] && echo "$_pm_open" >&2
rm -f "$OUT"
fatal "PREEMPTIBILITY: this link asked for a preemptible image and produced one that attests preemptibility=${_pm_got_name}. The functions listed above (PREEMPT-OPEN) each carry at least one loop with neither a budget checkpoint nor a proof that it yields; a task inside one of them reaches no slice boundary, which means (1) a fork quiesce over its lanes cannot complete and fork() returns EAGAIN on a deadline — a failure no Linux produces — and (2) a pending signal is never dispatched, because delivery happens at a checkpoint breath, so ^C on a spinning guest does nothing. Fix the named functions, or state the exemption where the image is built with HWJS_PREEMPTIBLE=none and say why next to it. Refusing and removing the artifact."
fi
# REFUSAL 2 — a lane-addressed image is held to whole-program whatever the link declares.
# A declaration is a statement about ONE image; lane addressing is a statement about how it
# shares a machine with its own siblings. A lane executing a syscall-free loop holds the whole
# process at the quiesce gate, so "I meant to do that" is not an available answer here.
if [[ "${HWJS_LANE_ADDR:-0}" == "1" && $_pm_got != 2 ]]; then
[[ -n "$_pm_census" ]] && echo "$_pm_census" >&2
[[ -n "$_pm_open" ]] && echo "$_pm_open" >&2
rm -f "$OUT"
fatal "PREEMPTIBILITY: this link is LANE-ADDRESSED but the image attests preemptibility=${_pm_got_name}. Sibling lanes run concurrently in one process: a lane inside a syscall-free unbounded loop never reaches a slice boundary, so an all-lanes fork quiesce cannot complete and every other lane waits out the deadline, and no lane's pending signals are dispatched. HWJS_PREEMPTIBLE=none does NOT waive this — it is a statement about one image, and this is a property of how that image shares a machine. Arm checkpoints and clear the PREEMPT-OPEN census above. Refusing and removing the artifact."
fi
# REFUSAL 3 — the one class the pass cannot see: functions that arrive at the final link ALREADY
# NATIVE. They never enter the merged module, so no analysis in the pass has an opinion about
# them, and the verdict above quantifies over a set that does not contain them. wasm has
# structured control flow, so this is decidable and cheap rather than an analysis: the only
# backward branch in wasm is a branch to a `loop` label, so "this native input can hold the CPU"
# is a scan of its code section for the opcode.
#
# Intersected with the final image's own defined symbols, because an archive member that lld
# never pulled is not in the artifact and the property quantifies over the artifact. That is the
# same shape as the native-stage §8b intersection above — both sides computed from artifacts.
#
# Not a list and not a waiver: the day someone adds a loop to the hand-written wasm thread
# trampoline, this link fails. compiler-rt's __udivmodti4, the one loop the native archive
# carried, no longer reaches here: a program or a side module takes the bitcode builtins TU
# instead, or that TU compiled once. The object is not among NATIVE_INPUTS: the pass has seen every
# function in it and its stamp carries the pass's count of them ("THE BUILTINS OBJECT").
if [[ "$_pm_want" == "whole-program" && ${#NATIVE_INPUTS[@]} -gt 0 ]]; then
[[ -x "$HWJS_OBJDUMP" ]] \
|| fatal "PREEMPTIBILITY: llvm-objdump ('$HWJS_OBJDUMP') is not executable, so the native-stage inputs [${NATIVE_INPUTS[*]}] cannot be scanned for unpreemptible loops. A native-stage input never reaches the coroutinize pass, so nothing else in this build has an opinion about it. Refusing rather than silently skipping the check (point WASMLD_HWJS_OBJDUMP at the pinned llvm-objdump)."
# Read as a set: the defined lines are those that do not start with a space.
if [[ $OUT_LISTING_OK == 1 ]]; then
_pm_defined="$(awk '!/^ / {print $NF}' <<<"$_out_syms")"
else
_pm_defined="$(hwjs_nm --defined-only "$OUT" 2>/dev/null | awk '{print $NF}' | LC_ALL=C sort -u)"
fi
[[ -n "$_pm_defined" ]] \
|| fatal "PREEMPTIBILITY: llvm-nm read no defined symbols from the final image, so the native-stage loop scan cannot be intersected with what actually landed in it. Refusing rather than scanning nothing and passing."
_pm_loopy=""
for _nat in "${NATIVE_INPUTS[@]}"; do
if link_facts_v loops "$_nat"; then
_nat_loops="$LINK_FACTS_V"
else
_nat_loops="$(link_facts_ask_loops "$_nat" || true)"
fi
[[ -z "$_nat_loops" ]] && continue
while IFS= read -r _lf; do
[[ -z "$_lf" ]] && continue
line_in_v _pm_defined "$_lf"
if [[ $LINE_IN == 1 ]]; then _pm_loopy+=" $_nat -> $_lf"$'\n'; fi
done <<<"$_nat_loops"
done
echo "wasmld: NOTE (PREEMPTIBILITY): scanned ${#NATIVE_INPUTS[@]} native-stage input(s) for wasm \`loop\` opcodes reaching the final image — $( [[ -z "$_pm_loopy" ]] && echo "none" || echo "$(grep -c . <<<"$_pm_loopy") found" ). The pass never sees these, so nothing else in this build has an opinion about them." >&2
if [[ -n "$_pm_loopy" ]]; then
printf '%s' "$_pm_loopy" >&2
rm -f "$OUT"
fatal "PREEMPTIBILITY: this image attests preemptibility=whole-program, but the function(s) listed above arrived as NATIVE-STAGE link inputs and contain a wasm \`loop\`. A native-stage input never reaches the HwjsCoroutinize pass: its back-edges carry no budget checkpoint and its frames have nowhere to park, so the whole-program verdict — which quantifies over the merged module — does not cover them, and the image's claim is wider than its evidence. Rebuild the input as BITCODE so the single merged-module pass run covers it, or take it out of the link. Refusing and removing the artifact."
fi
fi
echo "wasmld: NOTE (PREEMPTIBILITY): image attests preemptibility=${_pm_got_name}; this link required ${_pm_want}. ${_pm_census:-}" >&2
}
# ── (6) PHANTOM-IMPORT witness (ticket #4). --allow-undefined (which the
# coro link NEEDS: linux.syscall / hwjs_suspend.park are genuine imports)
# also lets ANY undefined symbol become a synthesized env.* function
# import that traps at first call — so every autoconf AC_CHECK_FUNCS
# link-probe answered "yes" and bash shipped importing env.tputs/tgetent
# because configure's termcap search "passed" against no library. A
# STATIC whole-program image has a closed sanctioned surface — linux.*,
# hwjs_suspend.*, env.user_memory — and anything else is a phantom:
# refuse it AT THE LINK, naming every symbol, not at the first call in a
# booted machine. A dlopen-capable DYNAMIC MAIN (WASMLD_DYNAMIC_MAIN/
# _MODULE) additionally imports ONLY env.__indirect_function_table — its
# env FUNCTION surface is exactly as closed as a static image's, because
# the host instantiates a MAIN against the bare kernel ABI (worker.mjs
# filterImports binds env fns only for dlopen'd .so loads). The retired
# blanket "dynamic" mode here sanctioned every env fn import for the
# DYNAMIC_MAIN glibc arm, so the 2026-07-05 pool restructure's dropped
# nscd client stubs shipped as env.__nscd_* imports that failed bash//init
# instantiate on the live glibc machine (superproject issue #27) — the
# exact trap this witness exists to refuse. Only an actual -shared side
# module (open-world by design: the host binds its env fn imports from
# the main image / kernel registry; unresolved ones hit the E8 registry
# refuse at load — that world's loud path) gets the open env fn surface.
# WASMLD_ALLOW_ENV_IMPORTS
# (comma-separated names) is the explicit, loudly-NOTEd escape hatch for
# a deliberate extra host binding.
# ── THE ADDRESS-ONLY IMPORT'S TYPE, on a main with needed libraries. clang
# types a function it only takes the address of as void() when the TU cannot
# lower the real type (a vtable slot for a virtual whose return type is only
# forward-declared). import-dynamic imports it as env. () -> nil beside
# its GOT.func slot, the library exports the real signature, and the loader's
# instantiate refuses the pair: every libkj consumer died on
# kj::ExceptionCallback::getThreadInitializer. The retype gives such an
# import its provider's type (libc.so first, then the needed list, the
# loader's binding order), only where no call in the main targets it.
# RED arm: WASMLD_NEEDED_LIBS_NO_IMPORT_RETYPE=1 leaves the placeholder.
# Test: test/needed-import-retype.sh.
if [[ "$LIBC_IMPORT" == "1" && $IS_SHARED != 1 && ${NEEDED_SO_SNAPSHOTS[0]+x} == x \
&& -z "${WASMLD_NEEDED_LIBS_NO_IMPORT_RETYPE:-}" ]]; then
_rt_out="$("$BRINT_TOOL" import-retype "$OUT" "--objdump=$HWJS_OBJDUMP" \
"$LIBC_SO_SNAPSHOT" "${NEEDED_SO_SNAPSHOTS[@]}" 2>&1)" \
|| { echo "$_rt_out" >&2; rm -f "$OUT"; fatal "WASMLD_NEEDED_LIBS: cannot compare the final image's function imports with the types its needed libraries export (reason above). An import typed apart from its export fails the loader's instantiate. Refusing and removing the artifact."; }
while IFS= read -r _rt_line; do
[[ -n "$_rt_line" ]] && echo "wasmld: NOTE (WASMLD_NEEDED_LIBS): import type: $_rt_line" >&2
done <<<"$_rt_out"
fi
IMPORT_WITNESS=( "$BRINT_TOOL" import-witness )
witness_mode=static
[[ "$DYNAMIC_MAIN" != "0" || "$DYNAMIC_MODULE" != "0" ]] && witness_mode=dynamic-main
for _wa in "${args[@]}"; do
[[ "$_wa" == "-shared" || "$_wa" == "--shared" ]] && witness_mode=dynamic
done
witness_args=( "$OUT" "--mode=$witness_mode" )
# PLAN-HWJS-RT-PSABI R4: a runtime-import dynamic main (WASMLD_RT_IMPORT=1,
# the wasmcc arm that excludes hwjs_user_rt from the merge) may import
# exactly the kernel-provided runtime's callable surface — the witness's
# grown-by-name allowlist, never a blanket allow.
if [[ "${WASMLD_RT_IMPORT:-0}" == "1" && "$witness_mode" == "dynamic-main" ]]; then
echo "wasmld: NOTE (WASMLD_RT_IMPORT): sanctioning the kernel-provided runtime's callable surface as main imports (PLAN-HWJS-RT-PSABI R4; loader binds module #0)." >&2
witness_args+=( "--rt-import" )
fi
# Dynamic-libc consumer (PLAN-DYNAMIC-LIBC): sanction env. BY NAME from libc.so's fn-export
# list and GOT.mem./GOT.func. BY NAME from its data/fn-export lists — all DERIVED by the
# witness from the built artifact. This is a SOUNDNESS gate, not hygiene: under import-dynamic a
# misspelled extern datum links rc=0 as a plausible GOT.mem import (RED-1's silent NULL bind class
# made a BUILD failure here, never an exec-time LinkError). The partition file additionally gates
# every libc-bound env fn import: absent-from-partition = link fatal, never an orphan.
if [[ "$LIBC_IMPORT" == "1" ]]; then
echo "wasmld: NOTE (WASMLD_LIBC_IMPORT): sanctioning libc.so's derived export surface (env fns + GOT.mem/GOT.func by name) + requiring every libc-bound import in the published partition (PLAN-DYNAMIC-LIBC)." >&2
# WORK snapshots, not the staged paths (TOCTOU close): the witness judges the same
# immutable pair the pass consumed and the post-link checks hash.
witness_args+=( "--libc-import" "--libc-so=$LIBC_SO_SNAPSHOT" "--suspenders-partition=$LIBC_PARTITION_CONSUMED" )
# ...and the needed libraries' surfaces. Without these the by-name soundness gate
# (S5 change (i)) refuses every import a package library answers, so the gate would
# have to be dropped wholesale to link a needed-main — turning a soundness check into
# an off switch. Extending it per artifact keeps the check, and keeps it derived.
for _nsnap in ${NEEDED_SO_SNAPSHOTS[@]+"${NEEDED_SO_SNAPSHOTS[@]}"}; do
witness_args+=( "--needed-so=$_nsnap" )
done
fi
if [[ -n "${WASMLD_ALLOW_ENV_IMPORTS:-}" ]]; then
echo "wasmld: NOTE (WASMLD_ALLOW_ENV_IMPORTS): sanctioning extra env function imports [${WASMLD_ALLOW_ENV_IMPORTS}] — a deliberate host binding, acknowledged on the link line." >&2
witness_args+=( "--allow-env=$WASMLD_ALLOW_ENV_IMPORTS" )
fi
set +e
phantom="$("${IMPORT_WITNESS[@]}" "${witness_args[@]}" 2>&1)"
witness_rc=$?
set -e
if [[ $witness_rc -eq 1 ]]; then
echo "$phantom" | sed 's/^/wasmld: phantom import: /' >&2
rm -f "$OUT" # never leave a trapping-at-first-call artifact for a later stale use
fatal "final image imports symbol(s) outside the sanctioned surface (lines above) — undefined symbols were synthesized into env.* imports that TRAP at first call (--allow-undefined's dark side; the AC_CHECK_FUNCS false-yes). The symbol is misspelled, the providing library is missing from the link line, or a genuinely-host-bound import needs WASMLD_ALLOW_ENV_IMPORTS= acknowledged explicitly. Refusing at the link, not at the first call."
elif [[ $witness_rc -ne 0 ]]; then
echo "$phantom" >&2
rm -f "$OUT"
fatal "PHANTOM-IMPORT witness failed to attest the image (rc=$witness_rc, output above) — an unverifiable import surface is a refusal, never a silent pass."
fi
# ── Dynamic-libc consumer post-link (WASMLD_LIBC_IMPORT=1; PLAN-DYNAMIC-LIBC §3.2/§3.4).
if [[ "$LIBC_IMPORT" == "1" ]]; then
# (a) D2 DIGEST LOCKSTEP: the partition file this main CONSUMED must be the one the staged
# libc.so PUBLISHED — libc.so's hwjs.abi v2 field 9 records sha256-lo64 of its published
# partition bytes; a mismatch is the partition-N-vs-libc.so-M skew class, refused at LINK here
# (the loader repeats the refusal at LOAD via the digests both artifacts carry — L2).
# TOCTOU-CLOSED (2026-07-16): every hash below is taken over the WORK SNAPSHOTS captured
# before the pass ran (the same bytes the pass consumed), and the CONSUMED digest is
# additionally READ BACK off $OUT's own hwjs.abi v2 field 9 (stamped by the pass at
# merged-codegen time) and required to equal sha256-lo64(snapshot partition) — so a
# producer rebuild swapping the staged pair mid-link can neither pass the lockstep nor
# skew what the needed-list records.
_part_sha="$(sha256sum "$LIBC_PARTITION_CONSUMED")"
_part_sha="${_part_sha%% *}"
if link_facts_v abi_digest "$LIBC_SO_SNAPSHOT"; then
_libc_digest="$LINK_FACTS_V"
else
_libc_digest="$(link_facts_ask_abi_digest "$LIBC_SO_SNAPSHOT" 2>&1)"
fi || {
echo "$_libc_digest" >&2
rm -f "$OUT"
fatal "WASMLD_LIBC_IMPORT: cannot read the suspender-partition digest off '$WASMLD_LIBC_SO_PATH' (WORK snapshot; output above) — an artifact without the D2 stamp is not a consumable libc.so (built through WASMLD_LIBC_SO=1?)."
}
if [[ "${_part_sha:0:16}" != "$_libc_digest" ]]; then
rm -f "$OUT"
fatal "WASMLD_LIBC_IMPORT: DIGEST SKEW — the consumed partition file '$WASMLD_HWJS_XMOD_SUSPENDERS' (sha256 ${_part_sha:0:16}…) is NOT the partition libc.so '$WASMLD_LIBC_SO_PATH' published (manifest records ${_libc_digest}…). A main linked against partition N running against libc.so M is exactly the skew class the never-silent doctrine exists for (PLAN-DYNAMIC-LIBC §3.2). Regenerate/relink against the matching pair."
fi
# (a2) CONSUMED-DIGEST READBACK: $OUT's OWN hwjs.abi v2 field 9 was stamped BY THE PASS with
# sha256-lo64 of the partition bytes it ACTUALLY CONSUMED at merged-codegen time
# (CoroutinizePass PartitionConsume → xmodPartition().VerdictDigestLo64). Requiring it to equal the
# snapshot's hash proves end-to-end that the pass-consumed bytes ARE the bytes the lockstep
# above judged and the needed-list below stamps — the authoritative consumed value, immune to
# any staged-path swap (and a tripwire on snapshot-plumbing bugs). A mismatch is a stale-file/
# plumbing refusal, never installable.
_consumed_digest="$("$BRINT_TOOL" abi "$OUT" digest 2>&1)" || {
echo "$_consumed_digest" >&2
rm -f "$OUT"
fatal "WASMLD_LIBC_IMPORT: cannot read the CONSUMED partition digest off the main's own hwjs.abi manifest (output above) — without the readback the digest lockstep cannot attest what the pass actually consumed (PLAN-DYNAMIC-LIBC §3.2)."
}
if [[ "${_part_sha:0:16}" != "$_consumed_digest" ]]; then
rm -f "$OUT"
fatal "WASMLD_LIBC_IMPORT: CONSUMED-DIGEST MISMATCH — the main's own hwjs.abi records the pass consumed partition bytes with sha256-lo64 ${_consumed_digest}…, but the snapshot this link hashes/stamps is ${_part_sha:0:16}… (a mid-link partition swap or snapshot-plumbing bug). The digest lockstep would otherwise certify verdicts the pass never saw. Refusing."
fi
# (a3) TRACK M CHECK-EMITTING LOCKSTEP (PLAN-CXX-STATUS-CHANNEL §7; I3's link-time half —
# the loader repeats it at exec/dlopen). Both artifacts' hwjs.abi flags bit4 (check_emitting)
# must AGREE: a check-emitting main over a non-check-emitting libc.so (or the converse) lets
# a status-channel raise transit uninstrumented frames SILENTLY — the §9 R1 miscompile class.
# Absent bit (legacy v1/v2 artifact) reads 0, which mixes identically to a deliberate
# non-check-emitting build — refuse both, naming both sides and both bit values.
_ce_pair="$("$BRINT_TOOL" abi "$OUT" bits "$LIBC_SO_SNAPSHOT" 2>&1)" || {
echo "$_ce_pair" >&2
rm -f "$OUT"
fatal "WASMLD_LIBC_IMPORT: cannot read the check_emitting/lane_addressed flags (hwjs.abi flags bits 4/5) off the main and/or libc.so (output above) — without them the Track M / lane mixing refusals cannot be decided (PLAN-CXX-STATUS-CHANNEL §7; PLAN-THREADS-SINGLE-MEMORY §4 step 2). Refusing."
}
read -r _main_bits _libc_bits <<<"$_ce_pair"
_main_ce="${_main_bits%,*}"; _main_la="${_main_bits#*,}"
_libc_ce="${_libc_bits%,*}"; _libc_la="${_libc_bits#*,}"
if [[ "$_main_ce" != "$_libc_ce" ]]; then
rm -f "$OUT"
fatal "WASMLD_LIBC_IMPORT: CHECK-EMITTING MISMATCH — the main '$OUT' attests check_emitting=$_main_ce but libc.so '$WASMLD_LIBC_SO_PATH' attests check_emitting=$_libc_ce (hwjs.abi flags bit4). Mixing check-emitting and non-check-emitting modules lets a status-channel throw/longjmp transit an UNINSTRUMENTED frame silently — the I3 silent-transit miscompile (PLAN-CXX-STATUS-CHANNEL §7/§9 R1). Rebuild the pair in lockstep: both with HWJS_STATUS_CHANNEL=1, or neither. Refusing and removing the artifact."
fi
# (a3′) LANE-ADDRESSED LOCKSTEP (PLAN-THREADS-SINGLE-MEMORY §4 step 2;
# I3-2's link-time half — the loader repeats it at exec/dlopen). Both
# artifacts' hwjs.abi flags bit5 (lane_addressed) must AGREE: a
# lane-unaware module reading absolute __hwjs_status_channel inside a
# laned process reads LANE 0 from ANY lane — silent transit of every
# non-NORMAL outcome raised on lanes >= 1. Absent bit (legacy artifact)
# reads 0, which mixes identically to a deliberate single-lane build —
# refuse both directions, naming both sides and both bit values.
if [[ "$_main_la" != "$_libc_la" ]]; then
rm -f "$OUT"
fatal "WASMLD_LIBC_IMPORT: LANE-ADDRESSED MISMATCH — the main '$OUT' attests lane_addressed=$_main_la but libc.so '$WASMLD_LIBC_SO_PATH' attests lane_addressed=$_libc_la (hwjs.abi flags bit5). Mixing a lane-addressed module with a lane-unaware one lets the lane-unaware side read LANE 0's status word from ANY lane — silent transit under threads (I3-2; PLAN-THREADS-SINGLE-MEMORY §4 step 2). Rebuild the pair in lockstep: both with HWJS_RT_LANES>1, or neither. Refusing and removing the artifact."
fi
# (b) NEEDED-LIST carrier (D4): ONE carrier — a post-link custom section on the main (the
# wasm.linux.exec appending precedent, binfmt.rst:190-195), naming the digest-qualified libc.so
# plus the consumed-partition sha256, both hashed over the WORK SNAPSHOTS (the pair this main
# was actually linked against — content-addressed staging then binds the loader to the same
# generation). The lld-emitted dylink.0 (MEM_INFO, an import-dynamic side effect) is TOLERATED
# but its NEEDED subsection is deliberately unused (two carriers invite skew — the §3.4
# single-carrier rule). Kernel binfmt/exec-header tolerance of dylink.0-on-mains is an L1 gate
# (PLAN-DYNAMIC-LIBC §3.4), pinned by test/m5-libc-so-roundtrip.sh GREEN-5: the REAL kernel parser
# (arch/wasm32/kernel/wasm_module.c, the wasm32_user_exec_load/-exec_image validation path)
# compiled host-side accepts a dynamic-libc main carrying dylink.0 + THIS appended section; the
# loader-side (module-#1 graph walk) half stays L2.
_libc_sha="${LINK_FACTS_SHA[$LIBC_SO_SNAPSHOT]:-}"
[[ -n "$_libc_sha" ]] || _libc_sha="$(sha256sum "$LIBC_SO_SNAPSHOT" | awk '{print $1}')"
# libc.so FIRST — the loader instantiates in list order and module #1 is libc by
# construction; the rest follow in link order. The suspenders digest stays a
# top-level scalar because it is libc.so's alone: no other library publishes one
# (a per-library partition is its own milestone; see the design record).
_needed_json="\"libc.so.$_libc_sha\""
for _nn in ${NEEDED_SO_NAMES[@]+"${NEEDED_SO_NAMES[@]}"}; do
_needed_json="$_needed_json,\"$_nn\""
done
"$BRINT_TOOL" append-section "$OUT" "wasm.linux.needed" "{\"needed\":[$_needed_json],\"suspenders_sha256\":\"$_part_sha\"}" \
|| { rm -f "$OUT"; fatal "WASMLD_LIBC_IMPORT: failed to append the wasm.linux.needed custom section — a needed-list-less dynamic main cannot be loaded (D4)."; }
echo "wasmld: NOTE (WASMLD_LIBC_IMPORT): needed-list appended (wasm.linux.needed: libc.so.${_libc_sha:0:16}…${NEEDED_SO_NAMES[0]+ + ${#NEEDED_SO_NAMES[@]} package library/libraries: ${NEEDED_SO_NAMES[*]}}; suspenders sha256 ${_part_sha:0:16}…) — the ONE carrier (dylink.0 NEEDED deliberately unused, §3.4)." >&2
# (c) install the §3.5 owner-audit sidecar next to the artifact (the loader's lookup input).
cp -f "$WORK/export-owners" "$OUT.export-owners" 2>/dev/null \
|| fatal "WASMLD_LIBC_IMPORT: owner-audit sidecar missing — the audit did not run?"
# (d) WEAK-UNDEFINED FUNCTION gate (2026-07-16; the S5 (vi) weak-disposition rule made
# complete). The pinned lld's handleWeakUndefines (lld/wasm/SymbolTable.cpp:1163, called at
# Driver.cpp:1700-1704) is gated ONLY on !ctx.isPic — which the dynamic-libc fixed-layout non-PIE main
# IS — and is NOT disabled by --unresolved-symbols=import-dynamic: every weak-undefined
# FUNCTION reference is silently bound to a hidden null-address `unreachable` stub, NO import
# materializes, and the witness/partition/owner audits are structurally blind to it. ELF
# semantics would bind the ref from the needed libc.so at load; here `if (weak_fn)` silently
# skips and a direct call traps — the RED-1 silent-wrong-binding class on ordinary inputs
# (libstdc++/libgcc __pthread_key_create-style probes; the rt's own weak `freea` delegation
# is the S5 freea-phantom's provenance, same lld gating). Weak DATA is fine: its GOT.mem
# import DOES materialize and the by-name witness judges it. Gate: any weak-undefined fn in
# the merged closure that libc.so EXPORTS (a loader-bindable ref lld just nulled) is FATAL
# unless acknowledged by name in WASMLD_ALLOW_NULL_WEAK; a name libc.so does NOT export
# passes with a loud NOTE (genuinely-null weak probe — the ELF-equivalent outcome).
# Since the pre-link weak bind above imports every such name it can rewrite, what reaches
# the FATAL is a reference it could not (a native archive member's).
if [[ "${_wb_listing_ok:-0}" == 1 ]]; then
_weak_fn_undefs="$_wb_listing"
else
_weak_fn_undefs="$(run_llvm_bulk hwjs_nm "$WORK/merged.o" ${NATIVE_INPUTS[@]+"${NATIVE_INPUTS[@]}"} 2>/dev/null \
| awk '$1 == "w" { print $NF }' | sort -u)"
fi
if [[ -n "$_weak_fn_undefs" ]]; then
_out_bound="$("$BRINT_TOOL" bound-imports "$OUT" 2>&1)" || { echo "$_out_bound" >&2; rm -f "$OUT"; fatal "WASMLD_LIBC_IMPORT: cannot enumerate the final image's imports for the weak-undefined gate. Refusing rather than silently skipping."; }
_null_weak_allow="${WASMLD_ALLOW_NULL_WEAK:-}"
_null_weak_allow="${_null_weak_allow//,/ }"
_null_weak_allow=" ${_null_weak_allow%"${_null_weak_allow##*[!$'\n']}"} "
while IFS= read -r _wsym; do
[[ -z "$_wsym" ]] && continue
# materialized as a real import (env fn / GOT.func / GOT.mem) — the loader binds it; judged by the witness above.
line_in_v _out_bound "$_wsym"
[[ $LINE_IN == 1 ]] && continue
line_in_v _libc_exports "function $_wsym"
if [[ $LINE_IN == 1 ]]; then
if [[ "$_null_weak_allow" == *" $_wsym "* ]]; then
echo "wasmld: NOTE (WASMLD_ALLOW_NULL_WEAK): weak-undefined fn '$_wsym' IS exported by libc.so but its null-stub binding is explicitly acknowledged — 'if (${_wsym})' stays false in this main by deliberate choice." >&2
else
rm -f "$OUT"
fatal "WEAK-UNDEFINED fn '$_wsym' was silently bound to a NULL-address unreachable stub by lld (handleWeakUndefines runs on every non-PIE link, import-dynamic notwithstanding) — but libc.so EXPORTS '$_wsym', so the loader COULD bind it and ELF semantics WOULD: 'if ($_wsym)' silently skips and a direct call traps unreachable at run time (the RED-1 silent-wrong-binding class). Acknowledge the null binding explicitly with WASMLD_ALLOW_NULL_WEAK=$_wsym, or make the reference strong so it imports (PLAN-DYNAMIC-LIBC §3.4 (vi))."
fi
else
echo "wasmld: NOTE (weak-undefined): fn '$_wsym' null-stubbed by lld; libc.so does not export it — the genuinely-null weak-probe outcome (ELF-equivalent). On the record, never silent." >&2
fi
done <<<"$_weak_fn_undefs"
fi
fi
# ── SHARED_NEEDED (hwjs-cc#128): a side module's own needed list. The shared
# objects this -shared link resolved (the driver's -lNAME and by-path hits,
# handed over as WASMLD_SHARED_SIBLING_LIBS, plus any -lNAME this linker
# resolved itself) are still not link inputs; they are recorded here, through
# the same needed_so_record a main uses, so the soname and digest are derived
# one way. The payload is the main's grammar without the libc.so head and the
# partition digest, which are a main's alone: {"needed":[".",...]}.
# libc.so is never an entry (needed_so_record refuses it): a side module binds
# libc through the main's module #1. RED arm: WASMLD_SHARED_NO_NEEDED=1.
if [[ $IS_SHARED == 1 && "$LIBC_SO" != "1" && "$RT_SO" != "1" && -f "$OUT" \
&& "${WASMLD_SHARED_NO_NEEDED:-0}" != "1" ]]; then
_shn_paths=()
IFS=':' read -r -a _shn_paths <<<"${WASMLD_SHARED_SIBLING_LIBS:-}"
_shn_out="$(real_path "$OUT")" \
|| fatal "SHARED_NEEDED: cannot resolve the output '$OUT'."
for _shp in ${_shn_paths[@]+"${_shn_paths[@]}"} ${SHARED_NEEDED_PATHS[@]+"${SHARED_NEEDED_PATHS[@]}"}; do
[[ -n "$_shp" ]] || continue
file_kind_v "$_shp"
if [[ "$FILE_KIND" != wasm ]]; then
echo "wasmld: NOTE (SHARED_NEEDED): '$_shp' is not a wasm module (an ld script or a host object) — not recorded (hwjs-cc#128)." >&2
continue
fi
if [[ "$(real_path "$_shp")" == "$_shn_out" ]]; then
echo "wasmld: NOTE (SHARED_NEEDED): '$_shp' is this link's own output — not recorded (hwjs-cc#128)." >&2
continue
fi
needed_so_record "$_shp" "SHARED_NEEDED"
done
if [[ ${NEEDED_SO_NAMES[0]+x} == x ]]; then
_shn_json=""
for _nn in "${NEEDED_SO_NAMES[@]}"; do
_shn_json="${_shn_json:+$_shn_json,}\"$_nn\""
done
"$BRINT_TOOL" append-section "$OUT" "wasm.linux.needed" "{\"needed\":[$_shn_json]}" \
|| { rm -f "$OUT"; fatal "SHARED_NEEDED: failed to append wasm.linux.needed to the side module '$OUT'."; }
echo "wasmld: NOTE (SHARED_NEEDED): side-module needed list appended (wasm.linux.needed: ${NEEDED_SO_NAMES[*]}) — a main that links this module copies them into its own list, and dlopen loads them before it (hwjs-cc#128)." >&2
fi
fi
# The §3.5 owner-audit sidecar for the RT-import-only arm (the libc.so-consumer arm installs its
# own copy above, inside the needed-list/digest block it belongs to). The table is the loader's
# lookup input: it says which of the process ABI's force-exports this image owns and which the
# loader must find on another module. An image whose surface was audited must ship it, or the
# loader is back to guessing which module answers a lookup.
if [[ "$EXPORT_AUDIT_RAN" == "1" && "$LIBC_IMPORT" != "1" && -f "$OUT" ]]; then
cp -f "$WORK/export-owners" "$OUT.export-owners" \
|| fatal "owner-audit sidecar: cannot install '$OUT.export-owners' — the audit ran but its table cannot travel with the artifact, so a loader lookup would have to guess the owning module."
echo "wasmld: NOTE (owner audit): sidecar installed -> $OUT.export-owners" >&2
fi
# ── (9) DYNAMIC-MAIN SUSPENDER PUBLICATION (BRINTOS-2323) ─────────────────
#
# WASMLD_DYNMAIN_SUSPENDERS_OUT= — the producer path a dlopen-capable
# dynamic main did not have. libc.so publishes a partition
# (WASMLD_LIBC_SO_PARTITION_OUT) and so does the runtime module
# (WASMLD_RT_SO_PARTITION_OUT); a MAIN published nothing, so a side module
# linked against it learned nothing about which of the main's exports park.
# The pass then falls back to attribute keying, which for an ordinary C
# declaration in an ordinary header means NATIVE for every one of them — the
# blanket, not a narrowing, exactly as the -shared partition-drop was
# (SHARED_PARTITION_CONSUME) before it was closed.
#
# What that costs, measured on this image rather than argued: python3 exports
# 1504 functions of which 1275 are coroutines; the crc32c extension imports 33
# names from env and 8 of them are in that set, PyModule_Create2 and
# PyArg_ParseTuple among them. Its own PyInit_crc32c is coroutinized and calls
# PyModule_Create2 BARE — no clear_parked before, no take_parked after —
# because the seed said native. The callee parks anyway, and the next park
# trips "set-over-set: parked slot not empty at a new park". That is the
# first-import trap, and it is at first import because PyModule_Create2 is
# what a module init calls.
#
# DERIVED FROM THE ARTIFACT, not from the pass. A ramp `f` is a coroutine iff
# the module carries `f.resume` (`f (.resume)` for a demangled C++ name, see
# _hwjs_coro_export_names), so the verdicts can be read off the bytes
# this link just produced — the same derivation, character for character, that
# the needed-library seed uses on a needed .so (BRINTOS-1634). No new build
# input, no new pass knob, and nothing to keep in sync with the pass's
# internals: the file states what the artifact IS.
#
# NAMES-ONLY BY CONSTRUCTION, and that is the form the consumer wants. The
# -shared arm forwards WASMLD_HWJS_XMOD_SUSPENDERS to HWJS_CORO_XMOD_SUSPENDERS,
# the names-only knob, which the pass UNIONS with any verdict partition
# (libc.so's) and cross-checks. Publishing a " " file here would
# be handed to the names-only parser and seed every native verdict line
# may-suspend — the trap the SHARED_PARTITION_CONSUME carry names.
#
# NEVER-SILENT: a main with no name section cannot be classified, and guessing
# either way re-creates one of the two mis-partition traps. Refuse.
if [[ -n "${WASMLD_DYNMAIN_SUSPENDERS_OUT:-}" ]]; then
[[ $IS_SHARED != 1 ]] \
|| fatal "WASMLD_DYNMAIN_SUSPENDERS_OUT on a -shared link — a side module is not a main and publishes no main partition; a package library publishes the same names list through WASMLD_SO_SUSPENDERS_OUT, and the libc.so and runtime producers through WASMLD_LIBC_SO_PARTITION_OUT and WASMLD_RT_SO_PARTITION_OUT (BRINTOS-2323)."
[[ "$DYNAMIC_MAIN" != "0" ]] \
|| fatal "WASMLD_DYNMAIN_SUSPENDERS_OUT requires WASMLD_DYNAMIC_MAIN=1 — a static main has no dlopen path, so nothing can ever consume the partition and publishing one would assert a binding surface this image does not have (BRINTOS-2323)."
[[ -f "$OUT" ]] \
|| fatal "WASMLD_DYNMAIN_SUSPENDERS_OUT: the final image '$OUT' is not there to derive the partition from (BRINTOS-2323)."
_dmraw="$WORK/dynmain-suspenders.raw"
_dmerr="$WORK/dynmain-suspenders.err"
_dmrc=0
"$BRINT_TOOL" coro-exports "$OUT" --census > "$_dmraw" 2>"$_dmerr" || _dmrc=$?
if (( _dmrc )); then
[[ -s "$_dmerr" ]] && sed 's/^/wasmld: dynmain-partition: /' "$_dmerr" >&2
fatal "WASMLD_DYNMAIN_SUSPENDERS_OUT: cannot derive the suspend partition from '$OUT' (its reason above) — a main whose coroutine exports cannot be classified would leave every consumer .so seeding them NATIVE wholesale, which is the set-over-set orphan this partition exists to prevent. Link the main with its name section intact (BRINTOS-2323)."
fi
# stderr is NOT merged into the derivation, for the same reason and by the
# same rule as the needed seed above: a warning would otherwise be
# published verbatim as a NAME.
_dmcensus="$(grep -m1 '^exports=' "$_dmerr" 2>/dev/null || true)"
if grep -qv '^exports=' "$_dmerr" 2>/dev/null; then
echo "wasmld: NOTE (WASMLD_DYNMAIN_SUSPENDERS_OUT): the reader wrote to stderr while classifying '$OUT' (kept OUT of the partition):" >&2
grep -v '^exports=' "$_dmerr" >&2 || true
fi
# The same three-in-one filter the needed seed runs, and it must be the same
# one: drop the reserved namespaces the pass hard-refuses (a runtime op must
# never be seeded through a partition), and dedup. A main's export list is
# already unique, so the dedup is belt-and-braces rather than load-bearing —
# kept so the two derivations cannot drift apart.
awk 'NF && $0 !~ /^(__hwjs_|hwjs_|llvm\.|env\.|GOT\.)/ && !seen[$0]++' \
"$_dmraw" > "$WORK/dynmain-suspenders.txt"
_dmkept=$(wc -l < "$WORK/dynmain-suspenders.txt")
_dmall=$(awk 'NF' "$_dmraw" | wc -l)
# Installed even when EMPTY, and deliberately. A recipe that publishes this
# file makes its existence a build contract its consumers depend on, so a
# main that happens to coroutinize nothing must leave an honest empty record
# rather than no record — the same call the rt producer makes above. The
# CONSUMER skips an empty file, because the pass refuses an empty list.
cp -f "$WORK/dynmain-suspenders.txt" "$WASMLD_DYNMAIN_SUSPENDERS_OUT.tmp.$$" \
&& mv -f "$WASMLD_DYNMAIN_SUSPENDERS_OUT.tmp.$$" "$WASMLD_DYNMAIN_SUSPENDERS_OUT" \
|| fatal "WASMLD_DYNMAIN_SUSPENDERS_OUT: failed to install the published partition at $WASMLD_DYNMAIN_SUSPENDERS_OUT (BRINTOS-2323)."
echo "wasmld: NOTE (WASMLD_DYNMAIN_SUSPENDERS_OUT): published dynamic-main suspender partition -> $WASMLD_DYNMAIN_SUSPENDERS_OUT ($_dmkept coroutine export(s) of $_dmall derived${_dmcensus:+, $_dmcensus}; $(( _dmall - _dmkept )) dropped as reserved-namespace or duplicate; sha256 $(sha256sum "$WASMLD_DYNMAIN_SUSPENDERS_OUT" | cut -c1-16)…)." >&2
if [[ "$_dmkept" == "0" ]]; then
echo "wasmld: NOTE (WASMLD_DYNMAIN_SUSPENDERS_OUT): the partition is EMPTY — this main exports no coroutine, so every consumer .so keeps its attribute-keyed seed. Honest empty record installed; a consumer must skip an empty partition rather than hand the pass an empty list." >&2
fi
fi
# ── (10) SIDE-MODULE SUSPENDER PUBLICATION ────────────────────────────────
#
# WASMLD_SO_SUSPENDERS_OUT= — (9)'s names list, published by a package
# LIBRARY rather than a main. It is for a library whose ABI is bound by
# modules that do not link it: CPython's extensions call the C API without
# naming libpython (upstream links them against it only on Android and
# Cygwin), so neither the needed-library seed nor the sibling seed reaches
# them, and once libpython is shared the main no longer defines that API and
# (9) cannot describe it. The consumer is unchanged: a module linked with
# WASMLD_DYNMAIN_SUSPENDERS= seeds from it, names only.
#
# The derivation is _hwjs_coro_export_names, the one the needed and sibling
# seeds run on a .so; (9) still carries its own copy. The filter is (9)'s.
# The knob's misplacements are refused at the top, before the link.
if [[ -n "${WASMLD_SO_SUSPENDERS_OUT:-}" ]]; then
[[ -f "$OUT" ]] \
|| fatal "WASMLD_SO_SUSPENDERS_OUT: the final module '$OUT' is not there to derive the partition from."
_soraw="$WORK/so-suspenders.raw"
_soerr="$WORK/so-suspenders.err"
: > "$_soraw"
if ! _hwjs_coro_export_names "$OUT" "$_soraw" "$_soerr"; then
[[ -s "$_soerr" ]] && sed 's/^/wasmld: so-partition: /' "$_soerr" >&2
fatal "WASMLD_SO_SUSPENDERS_OUT: cannot derive the suspend partition from '$OUT' (its reason above) — a library whose coroutine exports cannot be classified would leave every consumer seeding them NATIVE, which is the set-over-set trap."
fi
if [[ -s "$_soerr" ]]; then
echo "wasmld: NOTE (WASMLD_SO_SUSPENDERS_OUT): the reader wrote to stderr while classifying '$OUT' (kept OUT of the partition):" >&2
cat "$_soerr" >&2
fi
awk 'NF && $0 !~ /^(__hwjs_|hwjs_|llvm\.|env\.|GOT\.)/ && !seen[$0]++' \
"$_soraw" > "$WORK/so-suspenders.txt"
_sokept=$(wc -l < "$WORK/so-suspenders.txt")
# Installed even when EMPTY, for (9)'s reason: the file is a build contract.
cp -f "$WORK/so-suspenders.txt" "$WASMLD_SO_SUSPENDERS_OUT.tmp.$$" \
&& mv -f "$WASMLD_SO_SUSPENDERS_OUT.tmp.$$" "$WASMLD_SO_SUSPENDERS_OUT" \
|| fatal "WASMLD_SO_SUSPENDERS_OUT: failed to install the published partition at $WASMLD_SO_SUSPENDERS_OUT."
echo "wasmld: NOTE (WASMLD_SO_SUSPENDERS_OUT): published side-module suspender partition -> $WASMLD_SO_SUSPENDERS_OUT ($_sokept coroutine export(s))." >&2
fi
exit 0
fi
# ============================================================
# LEGACY ARM (Asyncify substrate) — RETIRED
# ============================================================
#
# The Asyncify arm's whole reason to exist was Binaryen's
# `wasm-opt -O2 --asyncify` post-link pass (+ optional --fpcast-emu). emsdk
# is gone, Binaryen is not part of the toolchains LLVM build, and the
# substrate is being retired in favor of the coro arm (WASMLD_HWJS=1). So a
# real legacy link can no longer be performed — and rather than re-add a
# dead $EMSDK path that fails obscurely (or, worse, silently produce a
# NON-asyncified binary that looks like a fork regression), we refuse it
# LOUDLY and by name.
#
# An OUT-less invocation (e.g. `--version` / a configure -shared feature
# probe) needs no Binaryen — it is a plain wasm-ld pass-through, which is
# now fully emsdk-free (WASM_LD resolves from the toolchains build). Keep
# that alive on both arms so probes still work; the coro arm only reaches
# here for such an OUT-less probe.
#
# A probe names nothing to link. A line that does -- an existing file or a
# -l -- and carries no -o is a link whose image wasm-ld would write to a.out
# with no pass run over it and no check made of it, exit 0. Refused.
if [[ -z "$OUT" ]]; then
for a in "$@"; do
if [[ "$a" == -l?* || "$a" == -l || "$a" == --library || "$a" == --library=?* || ( "$a" != -* && -f "$a" ) ]]; then
echo "wasmld: FATAL: no -o