Stream: git-wasmtime

Topic: wasmtime / issue #11300 Invalid ELF Headers when precompi...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 22 2025 at 15:23):

anlavandier opened issue #11300:

Test Case

Wasm Component bytecode
Wasm Component source code
All the relevant code I used is in this repo

Steps to Reproduce

$ cargo-component --version
cargo-component 0.21.1
fn main() -> Result<()> {
    let mut config = Config::new();
    if let Err(error) = config.target("pulley32") {
        eprintln!(
            "this Wasmtime was not built with the correct compiler backend \
             enabled: {error:?}",
        );
        return Ok(());
    }

    // Create an `Engine` with that configuration.
    let engine = match Engine::new(&config) {
        Ok(engine) => engine,
        Err(error) => {
            println!("Wasmtime build is incompatible with config: {error:?}");
            return Ok(());
        }
    };

    // Pre-compile a Wasm program.
    let wasm = include_bytes!("../../add/target/wasm32-wasip1/release/add.wasm");

    let precompiled = engine.precompile_component(wasm)?;

    // Write the pre-compiled program to a file.
    //
    // Note that the `.cwasm` extension is conventional for these files, and is
    // what the Wasmtime CLI will use by default, for example.
    std::fs::write("add_wasm32-wasip1.cwasm", &precompiled)?;

    // And we are done -- now a different Wasmtime embedding can load and run
    // the pre-compiled Wasm program from that `add.cwasm` file!
    Ok(())
}
use wasmtime::{component::Component, *};

fn main () {
    if let Err(e) = run_wasmtime() {
        println!("{:?}", defmt::Debug2Format(&e))
    }
}


fn run_wasmtime() -> wasmtime::Result<()> {
    let mut config = Config::default();

    config.target("pulley32")?;
    let engine = Engine::new(&config)?;
    let component_bytes  = include_bytes!("../../component-add/add_wasm32-wasip1.cwasm");

    let _component = match unsafe { Component::deserialize_raw(&engine, component_bytes.as_slice().into()) } {
        Ok(comp) => comp,
        Err(error) => {
            println!("failed to deserialize pre-compiled module: {:?}", defmt::Debug2Format(&error));
            return Ok(());
        }
    };
    println!("Deserialized Component");
    Ok(())
}

Expected Results

See Deserialized Component on stdout

Actual Results

failed to deserialize pre-compiled module: failed to parse precompiled artifact as an ELF

Caused by:
    Invalid ELF header size or alignment

Versions and Environment

Wasmtime version or commit: 34.0.1

Operating system: Ubuntu 22.04 LTS

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Jul 22 2025 at 15:23):

anlavandier added the bug label to Issue #11300.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 22 2025 at 16:41):

bjorn3 commented on issue #11300:

One issue at least is that there is a version mismatch between the compiling and executing side. The first uses wasmtime 34.0.1 while the second uses 34.0.2. You need an exact math.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 22 2025 at 22:56):

pchickey closed issue #11300:

Test Case

Wasm Component bytecode
Wasm Component source code
All the relevant code I used is in this repo

Steps to Reproduce

$ cargo-component --version
cargo-component 0.21.1
fn main() -> Result<()> {
    let mut config = Config::new();
    if let Err(error) = config.target("pulley32") {
        eprintln!(
            "this Wasmtime was not built with the correct compiler backend \
             enabled: {error:?}",
        );
        return Ok(());
    }

    // Create an `Engine` with that configuration.
    let engine = match Engine::new(&config) {
        Ok(engine) => engine,
        Err(error) => {
            println!("Wasmtime build is incompatible with config: {error:?}");
            return Ok(());
        }
    };

    // Pre-compile a Wasm program.
    let wasm = include_bytes!("../../add/target/wasm32-wasip1/release/add.wasm");

    let precompiled = engine.precompile_component(wasm)?;

    // Write the pre-compiled program to a file.
    //
    // Note that the `.cwasm` extension is conventional for these files, and is
    // what the Wasmtime CLI will use by default, for example.
    std::fs::write("add_wasm32-wasip1.cwasm", &precompiled)?;

    // And we are done -- now a different Wasmtime embedding can load and run
    // the pre-compiled Wasm program from that `add.cwasm` file!
    Ok(())
}
use wasmtime::{component::Component, *};

fn main () {
    if let Err(e) = run_wasmtime() {
        println!("{:?}", defmt::Debug2Format(&e))
    }
}


fn run_wasmtime() -> wasmtime::Result<()> {
    let mut config = Config::default();

    config.target("pulley32")?;
    let engine = Engine::new(&config)?;
    let component_bytes  = include_bytes!("../../component-add/add_wasm32-wasip1.cwasm");

    let _component = match unsafe { Component::deserialize_raw(&engine, component_bytes.as_slice().into()) } {
        Ok(comp) => comp,
        Err(error) => {
            println!("failed to deserialize pre-compiled module: {:?}", defmt::Debug2Format(&error));
            return Ok(());
        }
    };
    println!("Deserialized Component");
    Ok(())
}

Expected Results

See Deserialized Component on stdout

Actual Results

failed to deserialize pre-compiled module: failed to parse precompiled artifact as an ELF

Caused by:
    Invalid ELF header size or alignment

Versions and Environment

Wasmtime version or commit: 34.0.1

Operating system: Ubuntu 22.04 LTS

Architecture: x86_64


Last updated: Dec 06 2025 at 06:05 UTC