Registry Mirror
Skip to content

Conversation

@avrabe

@avrabe avrabe commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Problem (#546, milestone-1c)

synth compile x.wat -b aarch64 produced correct A64 machine code but wrapped it in the CLI's ARM ELF container (ELF32 / EM_ARM / ET_EXEC) instead of the AArch64 backend's own EM_AARCH64 ELF64 relocatable object. The codegen was already right; only the container was wrong. The backend already had a unit-tested elf::build_relocatable_object producing the correct EM_AARCH64 object — the CLI just wasn't calling it.

Fix

The CLI has two ELF-assembly sites and -b aarch64 fell through both into the ARM builder. Both are now routed on backend.name() == "aarch64":

  • multi-function --all-exports path: new first arm of the elf_data match, placed ahead of the has_external_relocations || relocatable arm so -b aarch64 --relocatable isn't stolen into the ARM builder. is_aarch64 is also folded into produced_relocatable (correct ET_REL summary) and dwarf_effective (honest "no DWARF yet" warning).
  • single-function path: mirror the same branch.

Both delegate to synth_backend_aarch64::elf::build_relocatable_object, mirroring the existing RISC-V build_multi_func_riscv_elf precedent.

Discriminator note: keyed on backend.name(), not target_spec.family — cortex_a53() is ArchFamily::ArmCortexA (isa AArch64), not ArchFamily::AArch64, so a family check would misroute.

The ARM and RISC-V ELF paths are untouched.

Verification

  • pyelftools on synth compile scripts/repro/aarch64_add_538.wat -b aarch64 -o /tmp/a.o --all-exports:
    class: 64
    machine: EM_AARCH64
    type: ET_REL
    FUNC add STB_GLOBAL
    FUNC muladd STB_GLOBAL
    FUNC const_sub STB_GLOBAL
    FUNC xor_or STB_GLOBAL
    
  • Differential scripts/repro/aarch64_add_538_differential.py: PASS — 8/8 vs wasmtime (third oracle).
  • Frozen anchors cargo test -p synth-cli --test frozen_codegen_bytes: 3/3 (control_step 0x00210A55, flight_algo 0x07FDF307 unchanged — ARM/RV32 output bit-identical).
  • cargo fmt --check clean; cargo clippy -p synth-cli -p synth-backend-aarch64 --all-targets -- -D warnings clean; both crates' test suites green.

Closes #546.

🤖 Generated with Claude Code

…#538)

Milestone-1c: `synth compile x.wat -b aarch64` wrapped the correct A64
`.text` in the CLI's ARM ELF container (ELF32 / EM_ARM / ET_EXEC) instead
of the AArch64 backend's own EM_AARCH64 ELF64 relocatable object. The
codegen was already correct; only the container was wrong.

Both CLI ELF-assembly sites are fixed by routing on `backend.name() ==
"aarch64"` (not target family — `cortex_a53()` is `ArchFamily::ArmCortexA`
with isa AArch64, so a family check would misroute into the ARM builder):

- multi-function `--all-exports` path: new first arm in the `elf_data`
  match (ahead of `has_external_relocations || relocatable`, so
  `-b aarch64 --relocatable` isn't stolen into the ARM builder), plus
  `is_aarch64` folded into `produced_relocatable` and `dwarf_effective`.
- single-function path: mirror the same branch.

Both delegate to the backend's existing, unit-tested
`synth_backend_aarch64::elf::build_relocatable_object`, mirroring the
RISC-V `build_multi_func_riscv_elf` precedent. ARM and RISC-V ELF paths
are untouched.

Verification:
- pyelftools on the acceptance object: ELFCLASS64 / EM_AARCH64 (183) /
  ET_REL with global STT_FUNC symbols add, muladd, const_sub, xor_or.
- scripts/repro/aarch64_add_538_differential.py: PASS (8/8 vs wasmtime).
- frozen_codegen_bytes 3/3 (control_step 0x00210A55, flight_algo
  0x07FDF307 unchanged — ARM/RV32 output bit-identical).
- cargo fmt --check clean; clippy -D warnings clean on synth-cli +
  synth-backend-aarch64; both crates' test suites green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 21.42857% with 22 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

@avrabe
avrabe merged commit e2d871d into main Jul 1, 2026
24 of 25 checks passed
@avrabe
avrabe deleted the fix/546-aarch64-elf64 branch July 1, 2026 16:17
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.

aarch64 backend emits A64 code in an ELF32/EM_ARM header (should be ELF64/EM_AARCH64) — output rejected by aarch64 tools

1 participant