Stream: git-wasmtime

Topic: wasmtime / issue #2873 RFE: Expose module custom sections


view this post on Zulip Wasmtime GitHub notifications bot (May 19 2021 at 14:55):

alexcrichton commented on issue #2873:

Sorry for the delay in responding here, but thanks for the report!

While wasmtime doesn't currently yet expose an API for this, you can pretty easily build one with the wasmparser crate:

use wasmparser::{Parser, Payload, Result};

fn custom_sections(bytes: &[u8]) -> impl Iterator<Item = Result<(&str, &[u8])>> {
    Parser::new(0).parse_all(bytes).filter_map(|payload| {
        let payload = match payload {
            Ok(s) => s,
            Err(e) => return Some(Err(e)),
        };
        match payload {
            Payload::CustomSection { name, data, .. } => Some(Ok((name, data))),
            _ => None,
        }
    })
}

Would that work for your purposes? Or is there a reason you need an API added to wasmtime itself?

view this post on Zulip Wasmtime GitHub notifications bot (May 20 2021 at 17:40):

FGasper commented on issue #2873:

Is wasmparser available from C? I’m using this from Perl so would need something I can call from C.

Thank you!

FYI, there’s also discussion of adding such an interface to the standard C API:
https://github.com/WebAssembly/wasm-c-api/issues/168#issuecomment-833713577

view this post on Zulip Wasmtime GitHub notifications bot (May 20 2021 at 20:48):

alexcrichton commented on issue #2873:

There is not currently a C API for wasmparser, so if you don't want to write Rust code then this will need to wait until there's a C API binding for this in Wasmtime's C API.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 11 2022 at 03:26):

ajihyf commented on issue #2873:

Sorry for the delay in responding here, but thanks for the report!

While wasmtime doesn't currently yet expose an API for this, you can pretty easily build one with the wasmparser crate:

```rust
use wasmparser::{Parser, Payload, Result};

fn custom_sections(bytes: &[u8]) -> impl Iterator<Item = Result<(&str, &[u8])>> {
Parser::new(0).parse_all(bytes).filter_map(|payload| {
let payload = match payload {
Ok(s) => s,
Err(e) => return Some(Err(e)),
};
match payload {
Payload::CustomSection { name, data, .. } => Some(Ok((name, data))),
_ => None,
}
})
}
```

Would that work for your purposes? Or is there a reason you need an API added to wasmtime itself?

Hi, this approach only accepts raw wasm input. Is it possible to get custom sections from a module which may be deserialized from compiled artifact?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 11 2022 at 09:41):

bjorn3 commented on issue #2873:

I don't think we preserve custom sections in precompiled modules.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2022 at 07:03):

ajihyf commented on issue #2873:

I'm using dynamic linking to run multiple module instances with the same linear memory. The custom section naming "dylink.0" is required to provide proper imports to instantiate the modules. It seems that wasmer supports custom section query API like JavaScript, which works both in raw and compiled modules. Maybe wasmtime should preserve the custom sections, too?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2022 at 15:26):

alexcrichton commented on issue #2873:

To confirm, precompiled artifacts don't store custom sections so this API would not be possible. I'd recommend extracting the custom section and saving it adjacent or next to wasmtime's compiled artifact.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 18 2023 at 15:49):

stevefan1999-personal commented on issue #2873:

This is needed for Den now. For now I have to mask it with not implemented...pity


Last updated: Nov 22 2024 at 17:03 UTC