Skip to content

port(wasm): Add section emitters for type / import / function / global / export#1987

Open
lapla-cogito wants to merge 2 commits into
wild-linker:mainfrom
lapla-cogito:section_emit
Open

port(wasm): Add section emitters for type / import / function / global / export#1987
lapla-cogito wants to merge 2 commits into
wild-linker:mainfrom
lapla-cogito:section_emit

Conversation

@lapla-cogito
Copy link
Copy Markdown
Member

Part of #1431

@lapla-cogito lapla-cogito changed the title Add section emitters for type / import / function / global / export port(wasm): Add section emitters for type / import / function / global / export May 26, 2026
Comment thread Cargo.toml
uuid = { version = "1.3.0", features = ["v4"] }
wait-timeout = "0.2.0"
wait4 = "0.1.3"
wasm-encoder = "0.248.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have reservations about using wasm-encoder to do writing. Mostly because I don't see how we'll be able to make writing multi-threaded. If you're sure you want to go that route, it's fine, but I expect we won't be able to reach the same level of performance as we have for ELF.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that, with the current wasm-encoder API, what is actually feasible is to generate the metadata on a single thread, generate raw instruction streams for the other sections in parallel across multiple threads, and then merge everything back on a single thread at the end to reconcile the indices. I'm not sure how much performance this would sacrifice, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is generating instruction streams computationally expensive? At least for ELF, most of the work is pretty much using memcpy to copy data around then applying a few relocations. With ELF, the destination of those copies is the actual output file and multiple threads are copying at once, with the destinations being non-overlapping areas of memory. If Wasm has to do a bunch of expensive computation to produce the stream, then that computation might dominate and it might not matter too much. But if like ELF, it's mostly copying data and applying a few relocations, then the part that merges everything back together is likely to be pretty slow, since it will need to perform an additional copy of pretty much the entire output file from a single thread.

Comment thread libwild/src/wasm.rs
}

/// Imported globals in declaration order. Imports of other kinds are skipped.
pub(crate) fn global_imports(&self) -> Result<Vec<WasmGlobalImport<'data>>> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that there are lots of functions in this PR that aren't called

Copy link
Copy Markdown
Member Author

@lapla-cogito lapla-cogito May 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional (the same pattern as wasm.rs, etc.). While much of the layout pipeline remains in TODO state, I'll use these functions after completing that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. How close are we to getting something that can run at least part of the way through the linking process and removing the #[allow(unused)]?

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.

2 participants