-
Notifications
You must be signed in to change notification settings - Fork 858
[wasm-split] Do not split out the start function #8711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -353,10 +353,10 @@ struct ModuleSplitter { | |
| classifyFunctions(); | ||
| moveSecondaryFunctions(); | ||
| thunkExportedSecondaryFunctions(); | ||
| shareImportableItems(); | ||
| indirectReferencesToSecondaryFunctions(); | ||
| indirectCallsToSecondaryFunctions(); | ||
| exportImportCalledPrimaryFunctions(); | ||
| shareImportableItems(); | ||
| setupTablePatching(); | ||
| } | ||
| }; | ||
|
|
@@ -432,11 +432,11 @@ void ModuleSplitter::classifyFunctions() { | |
| configSecondaryFuncs.insert(funcs.begin(), funcs.end()); | ||
| } | ||
| for (auto& func : primary.functions) { | ||
| // The start function must always be kept in the primary module. | ||
| if (func->imported() || !configSecondaryFuncs.contains(func->name) || | ||
| segmentReferrers.contains(func->name)) { | ||
| segmentReferrers.contains(func->name) || func->name == primary.start) { | ||
|
Comment on lines
+435
to
+437
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just do something like if (primary.start)
primaryFuncs.insert(primary.start)at the start of the function, rather than in this loop?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need the if's else not to happen, though. That is, we need to add it in the primary and not in the secondary. If the loop body is not modified, it will add it to the second. |
||
| primaryFuncs.insert(func->name); | ||
| } else { | ||
| assert(func->name != primary.start && "The start function must be kept"); | ||
| allSecondaryFuncs.insert(func->name); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -296,6 +296,13 @@ void splitModule(const WasmSplitOptions& options) { | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| if (function->name == wasm.start) { | ||||||||||||||||||||||||||||||
| if (!options.quiet) { | ||||||||||||||||||||||||||||||
| std::cerr << "warning: cannot split out start function " << func | ||||||||||||||||||||||||||||||
| << "\n"; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+299
to
+305
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you do the same thing in binaryen/src/tools/wasm-split/wasm-split.cpp Line 437 in b5b9ebd
Then we don't need to do anything in Also while you're at it you can add this there too, to be consistent with binaryen/src/tools/wasm-split/wasm-split.cpp Lines 286 to 298 in b5b9ebd
|
||||||||||||||||||||||||||||||
| if (!options.quiet && options.keepFuncs.contains(func)) { | ||||||||||||||||||||||||||||||
| std::cerr << "warning: function " << func | ||||||||||||||||||||||||||||||
| << " was to be both kept and split. It will be split.\n"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
|
|
||
| ;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t -o %t.wasm | ||
| ;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=PRIMARY | ||
| ;; RUN: wasm-dis %t1.wasm | filecheck %s --check-prefix=MOD1 | ||
| ;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=MOD2 | ||
| ;; RUN: wasm-dis %t3.wasm | filecheck %s --check-prefix=MOD3 | ||
|
|
||
| ;; The start function, $C, cannot be split it, and will remain in the primary. | ||
|
|
||
| (module | ||
| ;; PRIMARY: (type $0 (func)) | ||
|
|
||
| ;; PRIMARY: (import "placeholder.2" "0" (func $placeholder_0)) | ||
|
|
||
| ;; PRIMARY: (table $0 1 funcref) | ||
|
|
||
| ;; PRIMARY: (elem $0 (i32.const 0) $placeholder_0) | ||
|
|
||
| ;; PRIMARY: (export "C" (func $C)) | ||
|
|
||
| ;; PRIMARY: (export "table" (table $0)) | ||
|
|
||
| ;; PRIMARY: (start $C) | ||
| (start $C) | ||
|
|
||
| ;; MOD1: (type $0 (func)) | ||
|
|
||
| ;; MOD1: (import "primary" "table" (table $timport$0 1 funcref)) | ||
|
|
||
| ;; MOD1: (import "primary" "C" (func $C (exact))) | ||
|
|
||
| ;; MOD1: (func $A | ||
| ;; MOD1-NEXT: (call $A) | ||
| ;; MOD1-NEXT: (call_indirect (type $0) | ||
| ;; MOD1-NEXT: (i32.const 0) | ||
| ;; MOD1-NEXT: ) | ||
| ;; MOD1-NEXT: (call $C) | ||
| ;; MOD1-NEXT: ) | ||
| (func $A | ||
| (call $A) | ||
| (call $B) | ||
| (call $C) | ||
| ) | ||
|
|
||
| ;; MOD2: (type $0 (func)) | ||
|
|
||
| ;; MOD2: (import "primary" "table" (table $timport$0 1 funcref)) | ||
|
|
||
| ;; MOD2: (elem $0 (i32.const 0) $B) | ||
|
|
||
| ;; MOD2: (func $B | ||
| ;; MOD2-NEXT: (drop | ||
| ;; MOD2-NEXT: (i32.const 42) | ||
| ;; MOD2-NEXT: ) | ||
| ;; MOD2-NEXT: ) | ||
| (func $B | ||
| (drop | ||
| (i32.const 42) | ||
| ) | ||
| ) | ||
|
|
||
| ;; PRIMARY: (func $C | ||
| ;; PRIMARY-NEXT: (drop | ||
| ;; PRIMARY-NEXT: (i32.const 1337) | ||
| ;; PRIMARY-NEXT: ) | ||
| ;; PRIMARY-NEXT: ) | ||
| (func $C | ||
| (drop | ||
| (i32.const 1337) | ||
| ) | ||
| ) | ||
|
|
||
| ;; MOD3: (type $0 (func)) | ||
|
|
||
| ;; MOD3: (func $D | ||
| ;; MOD3-NEXT: (drop | ||
| ;; MOD3-NEXT: (i32.const 999999) | ||
| ;; MOD3-NEXT: ) | ||
| ;; MOD3-NEXT: ) | ||
| (func $D | ||
| (drop | ||
| (i32.const 999999) | ||
| ) | ||
| ) | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 1: | ||
| A | ||
|
|
||
| 2: | ||
| B | ||
|
|
||
| 3: | ||
| C | ||
| D |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
|
|
||
| ;; RUN: wasm-split %s --split-funcs=start_func,other -o1 %t.1.wasm -o2 %t.2.wasm -g 2>&1 | ||
| ;; RUN: wasm-dis -all %t.1.wasm | filecheck %s --check-prefix PRIMARY | ||
| ;; RUN: wasm-dis -all %t.2.wasm | filecheck %s --check-prefix SECONDARY | ||
|
|
||
| ;; Do not error on trying to split out the start function. It cannot be | ||
| ;; split out, keep it in the primary module. | ||
|
|
||
| (module | ||
| ;; PRIMARY: (type $0 (func)) | ||
|
|
||
| ;; PRIMARY: (start $start_func) | ||
|
|
||
| ;; PRIMARY: (func $start_func (type $0) | ||
| ;; PRIMARY-NEXT: ) | ||
| (func $start_func) | ||
|
|
||
| (start $start_func) | ||
|
|
||
| ;; SECONDARY: (type $0 (func)) | ||
|
|
||
| ;; SECONDARY: (func $other (type $0) | ||
| ;; SECONDARY-NEXT: ) | ||
| (func $other) | ||
| ) | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the order change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I meant by this:
That is the table needs to be created at the right time. I think...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why that would be related to this change 🤔
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't either... Can you give an example?
That order change was the gist of #8688, so without breaking a lot of new assumptions, it is not easy to flip...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For an example, run the multi-split test in this PR. (That is, take all of this PR but the part in question. The test crashes because it doesn't find the table. Reordering makes the table exist - but I have no high-level understanding of the flow here 😄 so maybe it is the wrong fix)