Skip to content

Commit 664afac

Browse files
authored
Honor ALLOW_MEMORY_GROWTH and WASM_MEM_MAX in wasm backed (#6878)
1 parent 3c4bc8e commit 664afac

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

tools/shared.py

+27-12
Original file line numberDiff line numberDiff line change
@@ -1333,16 +1333,23 @@ def __getitem__(self, key):
13331333

13341334

13351335
def verify_settings():
1336-
if Settings.WASM_BACKEND and not Settings.WASM:
1337-
# TODO(sbc): Make this into a hard error. We still have a few places that
1338-
# pass WASM=0 before we can do this (at least Platform/Emscripten.cmake and
1339-
# generate_struct_info).
1340-
logging.debug('emcc: WASM_BACKEND is not compatible with asmjs (WASM=0), forcing WASM=1')
1341-
Settings.WASM = 1
1336+
if Settings.WASM_BACKEND:
1337+
if not Settings.WASM:
1338+
# TODO(sbc): Make this into a hard error. We still have a few places that
1339+
# pass WASM=0 before we can do this (at least Platform/Emscripten.cmake and
1340+
# generate_struct_info).
1341+
logging.debug('emcc: WASM_BACKEND is not compatible with asmjs (WASM=0), forcing WASM=1')
1342+
Settings.WASM = 1
1343+
1344+
if not BINARYEN_ROOT:
1345+
exit_with_error('emcc: BINARYEN_ROOT must be set in the .emscripten config'
1346+
' when using the LLVM wasm backend')
1347+
1348+
if Settings.CYBERDWARF:
1349+
exit_with_error('emcc: CYBERDWARF is not supported by the LLVM wasm backend')
13421350

1343-
if Settings.WASM_BACKEND and not BINARYEN_ROOT:
1344-
exit_with_error('emcc: BINARYEN_ROOT must be set in the .emscripten config'
1345-
' when using the LLVM wasm backend')
1351+
if Settings.EMTERPRETIFY:
1352+
exit_with_error('emcc: EMTERPRETIFY is not is not supported by the LLVM wasm backend')
13461353

13471354

13481355
Settings = SettingsManager()
@@ -1921,7 +1928,7 @@ def wrapped():
19211928
'-z',
19221929
'stack-size=%s' % Settings.TOTAL_STACK,
19231930
'--global-base=%s' % Settings.GLOBAL_BASE,
1924-
'--initial-memory=%s' % Settings.TOTAL_MEMORY,
1931+
'--initial-memory=%d' % Settings.TOTAL_MEMORY,
19251932
'-o',
19261933
target,
19271934
'--no-entry',
@@ -1932,6 +1939,11 @@ def wrapped():
19321939
'--lto-O%d' % lto_level,
19331940
] + files + [libc_rt_lib, compiler_rt_lib]
19341941

1942+
if Settings.WASM_MEM_MAX != -1:
1943+
cmd.append('--max-memory=%d' % Settings.WASM_MEM_MAX)
1944+
elif not Settings.ALLOW_MEMORY_GROWTH:
1945+
cmd.append('--max-memory=%d' % Settings.TOTAL_MEMORY)
1946+
19351947
for a in Building.llvm_backend_args():
19361948
cmd += ['-mllvm', a]
19371949

@@ -2292,9 +2304,12 @@ def can_inline():
22922304

22932305
@staticmethod
22942306
def is_wasm_only():
2307+
# not even wasm, much less wasm-only
22952308
if not Settings.WASM:
2296-
return False # not even wasm, much less wasm-only
2297-
# if the asm.js code will not run, and won't be run through the js optimizer, then
2309+
return False
2310+
# llvm backend can only ever produce wasm
2311+
if Settings.WASM_BACKEND:
2312+
return True
22982313
# fastcomp can emit wasm-only code.
22992314
# also disable this mode if it depends on special optimizations that are not yet
23002315
# compatible with it.

0 commit comments

Comments
 (0)