Skip to content

Commit

Permalink
Don't send the memory and table to standalone wasms, which do not imp…
Browse files Browse the repository at this point in the history
…ort them. (#9639)
  • Loading branch information
kripken committed Oct 14, 2019
1 parent a26e51b commit 169e572
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
21 changes: 12 additions & 9 deletions emscripten.py
Expand Up @@ -2436,15 +2436,18 @@ def create_em_js(forwarded_json, metadata):


def add_standard_wasm_imports(send_items_map):
# memory was already allocated (so that js could use the buffer); import it
memory_import = 'wasmMemory'
if shared.Settings.MODULARIZE and shared.Settings.USE_PTHREADS:
# Pthreads assign wasmMemory in their worker startup. In MODULARIZE mode, they cannot assign inside the
# Module scope, so lookup via Module as well.
memory_import += " || Module['wasmMemory']"
send_items_map['memory'] = memory_import

send_items_map['table'] = 'wasmTable'
# Normally we import these into the wasm (so that JS could use them even
# before the wasm loads), while in standalone mode we do not depend
# on JS to create them, but create them in the wasm and export them.
if not shared.Settings.STANDALONE_WASM:
memory_import = 'wasmMemory'
if shared.Settings.MODULARIZE and shared.Settings.USE_PTHREADS:
# Pthreads assign wasmMemory in their worker startup. In MODULARIZE mode, they cannot assign inside the
# Module scope, so lookup via Module as well.
memory_import += " || Module['wasmMemory']"
send_items_map['memory'] = memory_import

send_items_map['table'] = 'wasmTable'

# With the wasm backend __memory_base and __table_base and only needed for
# relocatable output.
Expand Down
@@ -1,6 +1,4 @@
args_get
args_sizes_get
emscripten_notify_memory_growth
memory
proc_exit
table
2 changes: 0 additions & 2 deletions tests/other/metadce/mem_O3_STANDALONE_WASM.sent
@@ -1,5 +1,3 @@
args_get
args_sizes_get
memory
proc_exit
table
4 changes: 2 additions & 2 deletions tests/test_other.py
Expand Up @@ -8119,13 +8119,13 @@ def test_metadce_hello_fastcomp(self, *args):
3, [], [], 6100, 2, 3, 5), # noqa
# argc/argv support code etc. is in the wasm
'O3_standalone': (['-O3', '-s', 'STANDALONE_WASM'],
5, [], [], 6423, 3, 4, 5), # noqa
3, [], [], 6423, 3, 4, 5), # noqa
# Growth support code is in JS, no significant change in the wasm
'O3_grow': (['-O3', '-s', 'ALLOW_MEMORY_GROWTH'],
3, [], [], 6098, 2, 3, 5), # noqa
# Growth support code is in the wasm
'O3_grow_standalone': (['-O3', '-s', 'ALLOW_MEMORY_GROWTH', '-s', 'STANDALONE_WASM'],
6, [], [], 6563, 4, 4, 6), # noqa
4, [], [], 6563, 4, 4, 6), # noqa
})
@no_fastcomp()
def test_metadce_mem(self, *args):
Expand Down

0 comments on commit 169e572

Please sign in to comment.