summaryrefslogtreecommitdiff
path: root/src/ir/module-splitting.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2024-11-01 17:35:35 -0700
committerGitHub <noreply@github.com>2024-11-02 00:35:35 +0000
commit9f496abc5cf1ddbca8c8a4f4e740c412588708ef (patch)
treeb5d690a6228cec3a1a732f66a6bde743f55c5460 /src/ir/module-splitting.cpp
parent3b301784b86eada1ed2a9c52cbfd3a04564420fc (diff)
downloadbinaryen-9f496abc5cf1ddbca8c8a4f4e740c412588708ef.tar.gz
binaryen-9f496abc5cf1ddbca8c8a4f4e740c412588708ef.tar.bz2
binaryen-9f496abc5cf1ddbca8c8a4f4e740c412588708ef.zip
Module splitting: don't create new tables when splitting with Emscripten (#7050)
Emscripten's JS loader code for wasm-split isn't prepared for handling multiple tables that binaryen automatically creates when reference types are enabled (especially in conjunction with dynamic loading). For now, disable creation of multiple tables when using Emscripten's table ABI (distinguished by importing or exporting a table named "__indirect_function_table".
Diffstat (limited to 'src/ir/module-splitting.cpp')
-rw-r--r--src/ir/module-splitting.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp
index f299d7a35..a7ee96fa2 100644
--- a/src/ir/module-splitting.cpp
+++ b/src/ir/module-splitting.cpp
@@ -146,12 +146,24 @@ void TableSlotManager::addSlot(Name func, Slot slot) {
}
TableSlotManager::TableSlotManager(Module& module) : module(module) {
- if (module.features.hasReferenceTypes()) {
- // Just create a new table to manage all primary-to-secondary calls lazily.
- // Do not re-use slots for functions that will already be in existing
- // tables, since that is not correct in the face of table mutations.
- // TODO: Reduce overhead by creating a separate table for each function type
- // if WasmGC is enabled.
+ // If possible, just create a new table to manage all primary-to-secondary
+ // calls lazily. Do not re-use slots for functions that will already be in
+ // existing tables, since that is not correct in the face of table mutations.
+ // However, do not do this for emscripten; its loader code (and dynamic
+ // loading in particular) do not support this yet.
+ // TODO: Reduce overhead by creating a separate table for each function type
+ // if WasmGC is enabled.
+ Export* emscriptenTableExport =
+ module.getExportOrNull("__indirect_function_table");
+ Table* singletonTable =
+ module.tables.size() == 1 ? module.tables[0].get() : nullptr;
+ bool emscriptenTableImport =
+ singletonTable && singletonTable->imported() &&
+ singletonTable->module == "env" &&
+ singletonTable->base == "__indirect_function_table";
+
+ if (module.features.hasReferenceTypes() && !emscriptenTableExport &&
+ !emscriptenTableImport) {
return;
}