Skip to content

Commit dca1101

Browse files
authored
Unify handling of --memory-init-file (#18869)
This option cannot be used with `-sWASM` so error out in this case.
1 parent f641d74 commit dca1101

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

emcc.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def minify_whitespace():
391391

392392
def embed_memfile():
393393
return (settings.SINGLE_FILE or
394-
(settings.MEM_INIT_METHOD == 0 and
394+
(settings.WASM2JS and settings.MEM_INIT_METHOD == 0 and
395395
(not settings.MAIN_MODULE and
396396
not settings.SIDE_MODULE and
397397
not settings.GENERATE_SOURCE_MAP)))
@@ -1808,9 +1808,6 @@ def phase_linker_setup(options, state, newargs):
18081808
options.extern_pre_js = read_js_files(options.extern_pre_js)
18091809
options.extern_post_js = read_js_files(options.extern_post_js)
18101810

1811-
if options.memory_init_file is None:
1812-
options.memory_init_file = settings.OPT_LEVEL >= 2
1813-
18141811
# TODO: support source maps with js_transform
18151812
if options.js_transform and settings.GENERATE_SOURCE_MAP:
18161813
logger.warning('disabling source maps because a js transform is being done')
@@ -2079,10 +2076,6 @@ def phase_linker_setup(options, state, newargs):
20792076
if settings.MAIN_MODULE == 1:
20802077
settings.INCLUDE_FULL_LIBRARY = 1
20812078
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$preloadDylibs']
2082-
elif settings.SIDE_MODULE:
2083-
assert not settings.MAIN_MODULE
2084-
# memory init file is not supported with side modules, must be executable synchronously (for dlopen)
2085-
options.memory_init_file = False
20862079

20872080
# If we are including the entire JS library then we know for sure we will, by definition,
20882081
# require all the reverse dependencies.
@@ -2580,6 +2573,10 @@ def check_memory_setting(setting):
25802573
exit_with_error('MEM_INIT_METHOD is not supported in wasm. Memory will be embedded in the wasm binary if threads are not used, and included in a separate file if threads are used.')
25812574

25822575
if settings.WASM2JS:
2576+
if options.memory_init_file is None:
2577+
options.memory_init_file = settings.OPT_LEVEL >= 2
2578+
if options.memory_init_file:
2579+
settings.MEM_INIT_METHOD = 1
25832580
settings.MAYBE_WASM2JS = 1
25842581
# when using wasm2js, if the memory segments are in the wasm then they
25852582
# end up converted by wasm2js into base64 encoded JS. alternatively, we
@@ -2592,7 +2589,7 @@ def check_memory_setting(setting):
25922589
else:
25932590
# wasm includes the mem init in the wasm binary. The exception is
25942591
# wasm2js, which behaves more like js.
2595-
options.memory_init_file = True
2592+
# TODO(sbc): Error out here in --memory-init-file used.
25962593
settings.MEM_INIT_IN_WASM = True
25972594

25982595
if (
@@ -3118,7 +3115,7 @@ def phase_post_link(options, state, in_wasm, wasm_target, target):
31183115
else:
31193116
memfile = shared.replace_or_append_suffix(target, '.mem')
31203117

3121-
phase_emscript(options, in_wasm, wasm_target, memfile)
3118+
phase_emscript(in_wasm, wasm_target, memfile)
31223119

31233120
if options.js_transform:
31243121
phase_source_transforms(options)
@@ -3136,13 +3133,9 @@ def phase_post_link(options, state, in_wasm, wasm_target, target):
31363133

31373134

31383135
@ToolchainProfiler.profile_block('emscript')
3139-
def phase_emscript(options, in_wasm, wasm_target, memfile):
3136+
def phase_emscript(in_wasm, wasm_target, memfile):
31403137
# Emscripten
31413138
logger.debug('emscript')
3142-
if options.memory_init_file:
3143-
settings.MEM_INIT_METHOD = 1
3144-
else:
3145-
assert settings.MEM_INIT_METHOD != 1
31463139

31473140
if embed_memfile():
31483141
settings.SUPPORT_BASE64_EMBEDDING = 1

src/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var EXIT_RUNTIME = false;
9797

9898
// use the --memory-init-file command line switch to select this method
9999
// [link]
100-
var MEM_INIT_METHOD = false;
100+
var MEM_INIT_METHOD = 0;
101101

102102
// The total stack size. There is no way to enlarge the stack, so this
103103
// value must be large enough for the program's requirements. If

0 commit comments

Comments
 (0)