Registry Mirror
Skip to content

Conversation

@avrabe

@avrabe avrabe commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

What

A wit-bindgen core always exports cabi_realloc and cabi_realloc_wit_bindgen_<ver>, and synth bound every wasm export GLOBAL. Two such objects could not be linked into one image (duplicate symbol: cabi_realloc). gale worked around this with objcopy --localize-symbol, an edit made after synth that synth's provenance never recorded.

synth compile --local-export NAME (repeatable) binds that export name STB_LOCAL in the relocatable object instead of GLOBAL.

  • What stays the same. The function is still compiled and placed. In-object calls and table slots still reach it. .text is byte-identical to the compile without the flag. The flag works per name: another export name of the same function stays GLOBAL unless you name it too.
  • ARM Thumb-2 and A32. build_relocatable_elf binds the export symbol, or its alias, LOCAL. The builder's existing locals-first sort keeps symbol order and sh_info correct.
  • AArch64, ELF and Mach-O. ObjectFunction::local_symbols is read in the shared plan_object, so both containers agree by construction. Mach-O shows the symbol as non-external.
  • Recorded. The --emit-provenance sidecar gets "local_exports" (left out when empty). The --sbom metadata gets a synth:local-export property for each name.
  • Refused loudly (non-zero exit; the message names the flag and the name):
    • a NAME that is not an export the object places;
    • __synth_start, which the embedder must call from outside;
    • a set that would leave nothing GLOBAL: every export, or the root of a --func-name/--func-index --relocatable compile;
    • a self-contained Cortex-M image or A32 image;
    • the single-function path;
    • -b riscv: the RV32 writer binds every function symbol GLOBAL and has no locals-first ordering;
    • -b x86_64, through its refused-flag list;
    • the transpiler backends.
  • Exports that must stay reachable by construction. The only one found is __synth_start. The __synth_ prefix is already refused as an export name (Relocatable objects define only one name per function: other export names of the same index are silently dropped #1746), and no path emits an async-edge export.

Evidence

Real-linker co-link (crates/synth-cli/tests/local_export_1726.rs). Two modules both export cabi_realloc, plus a_entry or b_entry. Each pair gets a final link (-e a_entry).

The mandatory linker is the Rust toolchain's own rust-lld in its GNU flavor (rustc --print sysroot → lib/rustlib/<host>/bin/rust-lld -flavor gnu). Every CI job that runs cargo test has it, so the link legs never skip. If rust-lld is missing, the test FAILS with a message; I checked this with a fake sysroot. arm-none-eabi-ld and ld.lld on PATH add optional extra legs.

config linker without flag with --local-export cabi_realloc
cortex-m3 --relocatable rust-lld (mandatory); arm-none-eabi-ld, ld.lld (extra) refused, duplicate symbol: cabi_realloc / multiple definition of 'cabi_realloc' links; cabi_realloc LOCAL ×2 in the image, entries GLOBAL
cortex-r5 --relocatable rust-lld; arm-none-eabi-ld, ld.lld refused links
-b aarch64 rust-lld; ld.lld refused, duplicate symbol: cabi_realloc links
  • Symtab legs. The symtab is read with the object crate. With the flag, cabi_realloc is exactly one LOCAL defined symbol, the entries stay GLOBAL, every LOCAL precedes every non-local, and sh_info points at the first non-local. Without the flag, the GLOBAL definitions the two objects share are exactly {cabi_realloc}.
  • Mutation. I disabled the LOCAL binding in both writers. 4 of the 6 tests went red: all three co-link legs and the alias leg. Each test checks the symbol table before it links, so on mutated code the tests stop at the symbol-table assertions. To show the link leg is also red on its own, I linked the mutated binary's --local-export objects with rust-lld -flavor gnu for all three configs. All three were refused with duplicate symbol: cabi_realloc.
  • Unit test. object_plan::local_symbols_are_planned_local_and_ordered_first_1726 checks the binding, the growth of the locals-first prefix, relocation resolution through the reordering, and unchanged text.
  • Other tests in that file: a per-name alias leg; a table of all 9 refusals; the provenance and SBOM record, and its absence without the flag.

Execution (crates/synth-oracle/tests/local_export_1726_oracle.rs, hosted harness against kiln):

check result
GLOBAL a_entry → LOCAL cabi_realloc, 5-call sequence through linear memory, cortex-m4 + cortex-m3 10 of 10 steps agree with kiln
.text with the flag vs without byte-identical
potency: a LOCAL body with a different heap base disagrees on every step

oracle-kiln.yml:

  • added a pin on ORACLE local-export: 10 steps agree with kiln across 2 targets;
  • the integration-binary count of 2 passed moves from 1 to 2, because this binary is the second one.

I replayed the step's whole run: block against a local CARGO_TERM_COLOR=always log of cargo test -p synth-oracle --features exec. Exit 0.

Byte identity without the flag. Base binary main c0bd12a3 against this branch. Inputs: every .wat/.wasm under scripts/repro, tests, examples (278 files). Configurations (7): -t cortex-r5 image, -t cortex-m4f image, -t cortex-m3 --relocatable, the same with --emit-provenance --sbom (sidecars compared, SOURCE_DATE_EPOCH pinned), -t cortex-r5 --relocatable, -b aarch64, -b riscv.

identical differing refused by both exit mismatch
1245 0 701 0

Gates

gate exit
cargo fmt --check 0
cargo +1.100.0 clippy --workspace --all-targets -- -D warnings 0
cargo clippy -p synth-oracle --features exec --all-targets -- -D warnings 0
cargo test -p synth-cli --no-fail-fast (incl. frozen_codegen_bytes, 10 passed) 0
cargo test -p synth-core -p synth-backend-aarch64 -p synth-backend-x86_64 --no-fail-fast 0
cargo test -p synth-oracle / --features exec 0 / 0 (--features exec: first commit; no oracle code changed in the rust-lld commit)
scripts/claim_check.py claims.yaml (82/82) and --metric 0 / 0
oracle-wiring-check 0

Docs

  • the CLI help text;
  • docs/embedder-abi-relocatable-arm.md ("Keeping an export out of the link");
  • docs/embedder-abi-relocatable-aarch64.md;
  • FEATURE_MATRIX: a new row plus the CLI row. I edited the template scripts/templates/feature_matrix.md.tmpl and regenerated with --emit-status.

Not in this PR

  • RV32 support. The RV32 writer has no LOCAL symbols at all; even its internal func_N labels are GLOBAL. Localizing exports there alone would not make two RV32 objects co-link, so the flag is refused by name on RV32.
  • Executing the linked two-object image. The hosted harness runs one object against one wasm module. The execution check covers the localized object alone; the link leg covers the pair.

Refs #1726

🤖 Generated with Claude Code

https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L

avrabe and others added 2 commits December 4, 2026 21:50
…AArch64)

Two wit-bindgen cores both export cabi_realloc, so co-linking their
relocatable objects failed with a duplicate symbol and needed an objcopy
--localize-symbol step outside synth. --local-export NAME (repeatable)
binds that export name LOCAL in the ARM Thumb-2/A32 relocatable builder
and in the shared AArch64 object plan (ELF and Mach-O); the function stays
in the object and .text is unchanged. Recorded in the provenance sidecar
(local_exports) and SBOM (synth:local-export). Refused loudly for a name
the object does not export, __synth_start, a set leaving nothing GLOBAL,
self-contained images, the single-function path, RV32, x86-64 and the
transpiler backends.

Evidence: real-linker co-link test (red without the flag) on cortex-m3,
cortex-r5 and aarch64; hosted execution oracle vs kiln; byte-identity
sweep 1245 identical / 0 differing without the flag. oracle-kiln.yml:
"2 passed" integration count 1 -> 2 plus the new ORACLE pin.

Refs #1726

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L
The co-link legs skipped when neither arm-none-eabi-ld nor ld.lld was on
PATH, and CI's Test job installs neither, so the red/green link evidence
would have passed vacuously there. The mandatory leg now resolves rust-lld
from the Rust toolchain (`rustc --print sysroot` ->
lib/rustlib/<host>/bin/rust-lld, `-flavor gnu`) for the cortex-m3,
cortex-r5 and aarch64 configurations, and FAILS with a message when it is
missing. PATH linkers remain optional extra legs.

Refs #1726

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L
@codecov

codecov Bot commented Dec 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.02762% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/synth-cli/src/main.rs 92.96% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@avrabe
avrabe added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit ab9e022 Dec 5, 2026
89 checks passed
@avrabe
avrabe deleted the v092-local-export-1726 branch December 5, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant