Skip to content

fix(target): validate IR layouts and ELF object identities - #217

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:fix/target-contract-layout
Sep 24, 2026
Merged

LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:fix/target-contract-layout

Conversation

@LunaStev

@LunaStev LunaStev commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

whale ir lower --target banana previously accepted an arbitrary target with an AMD64 layout. Select the supported x86_64-whale-linux contract before input I/O, derive its 64-bit little-endian layout, and reject unsupported targets even with --no-verify. Library lowering and verification also reject target/layout mismatches.

A dependency-free whale-target workspace crate shares target and object identity between IR and object consumers. Objects retain machine, format, byte order, and address width. Both ELF writer entry points and linker inputs reject unsupported identities before interpreting them as AMD64. Valid AMD64 ELF headers and output bytes remain unchanged.

Motivation

Closes #21. Closes #85.

Official reference updates and verified code examples: wavefnd/wave-platform#69 (merge after this implementation).

Aggregate size/offset/stride calculation remains #105. Object reading, ABI code generation, full executable linking, initialization tracking, and weak-symbol precedence are outside this change.

Target and compatibility impact

  • Only x86_64-whale-linux is a supported IR output target. Host triples and other target strings are not accepted aliases.
  • ObjectFile::new(ObjectFormat::ELF64) retains its AMD64 behavior. Explicit metadata uses ObjectFile::with_target; object.format moves to object.target.format.
  • ir::DataLayout and ir::Endian remain re-exported at their existing paths. Existing test fixtures now use a supported target to reach their intended validation checks.
  • Other machine enum variants describe identity only; they do not add encoders. MSRV remains 1.86.0. No new registry dependencies or external assembler.

Validation

Linux x86_64, Rust 1.96.0; all Cargo checks used the lockfile and offline cached dependencies after initial dependency retrieval.

  • Observed the new unsupported-target CLI regression fail before implementation; it now covers absent and valid input files, output preservation, and --no-verify.
  • cargo test --workspace --locked --offline: 108 passed.
  • cargo test --workspace --all-features --locked --offline: 130 passed.
  • cargo +1.86.0 test --workspace --all-features --locked --offline --target-dir /tmp/whale-target-msrv: 130 passed.
  • cargo clippy --workspace --all-targets --locked --offline -- -D warnings, with and without --all-features: passed.
  • cargo build --workspace --locked --offline, with and without --all-features: passed; python3 tools/ci_smoke.py --binary target/debug/whale --socket disabled/enabled passed for the corresponding builds with empty PATH.
  • cargo fmt --all -- --check, git diff --check, and warning-free all-feature workspace rustdoc: passed.
  • python3 -m unittest discover -s tools -p 'test_*.py' -v: 8 passed.
  • New object tests decode ELF header fields independently and reject unsupported metadata through both writer entry points. Linker tests cover invalid inputs in either order; IR tests check name and layout mismatches.

Cross-host, QEMU, coverage, and release-mode checks are left to the registered GitHub CI jobs; they were not rerun locally.

Checklist

  • Commits include my DCO Signed-off-by line and preserve existing attribution.
  • Tests cover the changed behavior.
  • User-facing changes include README/help updates and a separate official-documentation PR.
  • Final diff reviewed; unrelated formatting and refactors excluded.
  • License notices and repository policies preserved.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev
LunaStev merged commit d16c96a into wavefnd:master Sep 24, 2026
22 checks passed
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.

Store target architecture and format identity in the object model Validate IR target selection and derive a matching data layout

1 participant