Skip to content

[wasm-split] Don't split trapping globals#8742

Open
aheejin wants to merge 1 commit into
WebAssembly:mainfrom
aheejin:wasm_split_fuzz_fix3
Open

[wasm-split] Don't split trapping globals#8742
aheejin wants to merge 1 commit into
WebAssembly:mainfrom
aheejin:wasm_split_fuzz_fix3

Conversation

@aheejin
Copy link
Copy Markdown
Member

@aheejin aheejin commented May 21, 2026

Trapping globals, which became possible with the custom-descriptor proposal, should stay in the primary module because we have to preserve their trapping behavior upon instantiation.

Also, note that we remove unused globals here:

if (!inPrimary && usingSecondaries.empty()) {
// It's not used anywhere, so delete it. Unlike other unused module items
// (memories, tables, and tags) that can just sit in the primary module
// and later be DCE'ed by another pass, we should remove it here, because
// an unused global can contain an initializer that refers to another
// global that will be moved to a secondary module, like
// (global $unused i32 (global.get $a)) // $a is moved to a secondary
globalsToRemove.push_back(global->name);

But trapping globals shouldn't be removed even when they are unused to preserve the trapping behavior.

In case someone wants to split modules assuming traps never happen, this also adds --traps-never-happen option to wasm-split, in which case we can freely split or remove trapping globals.

Trapping globals, which became possible with the custom-descriptor
proposal, should stay in the primary module because we have to preserve
their trapping behavior upon instantiation.

Also,note that we remove unused globals here:
https://github.com/WebAssembly/binaryen/blob/17a90787bae4f4544e25b3e7833da076e0d543de/src/ir/module-splitting.cpp#L896-L903
But trapping globals shouldn't be removed even when they are unused to
preserve the trapping behavior.

In case someone wants to split modules assuming traps never happen, this
also adds `--traps-never-happen` option to wasm-split, in which case we
can freely split or remove trapping globals.
@aheejin aheejin requested a review from tlively May 21, 2026 01:08
@aheejin aheejin requested a review from a team as a code owner May 21, 2026 01:08
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