Skip to content

Commit b5b9ebd

Browse files
authored
[wasm-split] Sync secondary tables' initial/max (#8714)
When an existing table is used as the active table, after we increate the size of the table by placing placeholders, we should sync it to the secondary modules' imports of the table. Fixes emscripten-core/emscripten#26959.
1 parent e7987f6 commit b5b9ebd

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/ir/module-splitting.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,11 @@ void ModuleSplitter::setupTablePatching() {
11071107
// so we should export and import the active table here.
11081108
auto secondaryTable =
11091109
secondary.getTableOrNull(tableManager.activeTable->name);
1110-
if (!secondaryTable) {
1110+
if (secondaryTable) {
1111+
// In case it's already in the secondary module, sync the initial/max
1112+
secondaryTable->initial = tableManager.activeTable->initial;
1113+
secondaryTable->max = tableManager.activeTable->max;
1114+
} else {
11111115
secondaryTable =
11121116
ModuleUtils::copyTable(tableManager.activeTable, secondary);
11131117
makeImportExport(*tableManager.activeTable,

test/lit/wasm-split/active-table-base-global-used-elsewhere.wast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
;; PRIMARY: (import "placeholder.deferred" "1" (func $placeholder_1))
2020

21-
;; PRIMARY: (table $table 2 funcref)
22-
(table $table 1 funcref)
21+
;; PRIMARY: (table $table 2 2 funcref)
22+
(table $table 1 1 funcref)
2323
(elem (global.get $base) $keep)
2424
;; PRIMARY: (elem $0 (global.get $base) $keep $placeholder_1)
2525

@@ -40,7 +40,7 @@
4040
(func $keep
4141
(call $split)
4242
)
43-
;; SECONDARY: (import "primary" "table" (table $table 1 funcref))
43+
;; SECONDARY: (import "primary" "table" (table $table 2 2 funcref))
4444

4545
;; SECONDARY: (import "primary" "global" (global $base i32))
4646

0 commit comments

Comments
 (0)