Skip to content

support cooperative multithreading ABI in wit_component::linking - #2581

Merged
dicej merged 5 commits into
bytecodealliance:mainfrom
dicej:linking-coop-multithreading
Jul 28, 2026
Merged

dicej merged 5 commits into
bytecodealliance:mainfrom
dicej:linking-coop-multithreading

Conversation

@dicej

@dicej dicej commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator
  • Handle __init_stack_pointer global variable imports
  • Update EncodingState::create_export_task_initialization_wrappers to look for component exports in both the main module and library modules
  • Ensure __wasm_init_{async_}task is re-exported from the main module if it is exported from a library so that EncodingState::create_export_task_initialization_wrappers can find and use it
  • Call __wasm_init_task if present before calling __wasm_call_ctors or _initialize

I've tested this using WASI-SDK's main branch, slightly modified to allow cooperative multithreading in shared libraries.

- Handle `__init_stack_pointer` global variable imports
- Update `EncodingState::create_export_task_initialization_wrappers` to look for component exports in both the main module _and_ library modules
- Ensure `__wasm_init_{async_}task` is re-exported from the main module if it is exported from a library so that `EncodingState::create_export_task_initialization_wrappers` can find and use it
- Call `__wasm_init_task` if present before calling `__wasm_call_ctors` or `_initialize`

I've tested this using WASI-SDK's main branch, slightly modified to allow
cooperative multithreading in shared libraries.
@dicej
dicej requested a review from alexcrichton July 28, 2026 15:38
@dicej
dicej requested a review from a team as a code owner July 28, 2026 15:38
@alexcrichton

Copy link
Copy Markdown
Member

Oh, also, there's a lot of hardcoding of various strings here, do you think it would be reasonable to consolidate things in fewer locations?

dicej added 3 commits July 28, 2026 13:50
…g init function

Previously, this only checked for such an export in the same library that
exports the `__wasm_call_ctors` or `_initialize` functions, whereas it should
have checked for it in all the libraries.
@dicej

dicej commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Oh, also, there's a lot of hardcoding of various strings here, do you think it would be reasonable to consolidate things in fewer locations?

I just pushed an update. Let me know if you think more needs to be done.

@alexcrichton alexcrichton left a comment

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.

Technically the string literals at least for _initialize and __wasm_init_task and such are duplicated throughout encoding.rs and validation.rs which is what I was primarily worried about, but don't feel the need to take those on here.

@alexcrichton

Copy link
Copy Markdown
Member

(CI failure due to MSRV as well)

@dicej
dicej enabled auto-merge July 28, 2026 22:15
@dicej
dicej added this pull request to the merge queue Jul 28, 2026
Merged via the queue into bytecodealliance:main with commit 5690296 Jul 28, 2026
37 checks passed
@dicej
dicej deleted the linking-coop-multithreading branch July 28, 2026 22:30
WorldSEnder pushed a commit to WorldSEnder/wasm-tools that referenced this pull request Jul 29, 2026
…ecodealliance#2582)

bytecodealliance#2581 was a bit too
aggressive about calling that function, which we need only call at most once
before the first `__wasm_call_ctors` or `_initialize` function.
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
wasm-tools 1.255.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Fix generating deeply nested WIT types in `wit-smith` by @alexcrichton in bytecodealliance/wasm-tools#2576
* wasm-tools mutate: validate the input module before mutating by @SAY-5 in bytecodealliance/wasm-tools#2577
* link tag imports to exports instead of synthesizing tags by @dicej in bytecodealliance/wasm-tools#2580
* Fix folded branch hints by @vouillon in bytecodealliance/wasm-tools#2578
* support cooperative multithreading ABI in `wit_component::linking` by @dicej in bytecodealliance/wasm-tools#2581
* avoid calling `__wasm_init_task` more than once in `init` module by @dicej in bytecodealliance/wasm-tools#2582
* Support `__wasm_{g,s}et_{tls_base,stack_pointer}` in `wit-component` by @alexcrichton in bytecodealliance/wasm-tools#2584
* fix table resolution for `thread.new-indirect` intrinsic calls by @dicej in bytecodealliance/wasm-tools#2585
* Release wasm-tools 1.255.0 by @github-actions[bot] in bytecodealliance/wasm-tools#2586


**Full Changelog**: https://github.com/bytecodealliance/wasm-tools/compare/v1.254.0...v1.255.0</pre>
  <p>View the full release notes at <a href="https://github.com/bytecodealliance/wasm-tools/releases/tag/v1.255.0">https://github.com/bytecodealliance/wasm-tools/releases/tag/v1.255.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!15533
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