Skip to content

Commit dd4fbbe

Browse files
authored
Enable optimize_syscalls when MAIN_MODULE=2. NFC (#19370)
With `MAIN_MODULE=1` we cannot disable `SYSCALLS_REQUIRE_FILESYSTEM` since the side modules might depend on these syscalls. However we `MAIN_MODULE=2` we have a complete view of the side module imports so we can.
1 parent 5634cfb commit dd4fbbe

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

emscripten.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ def write_output_file(outfile, module):
6060
outfile.write(module[i])
6161

6262

63-
def optimize_syscalls(declares):
63+
def maybe_disable_filesystem(imports):
6464
"""Disables filesystem if only a limited subset of syscalls is used.
6565
6666
Our syscalls are static, and so if we see a very limited set of them - in particular,
6767
no open() syscall and just simple writing - then we don't need full filesystem support.
6868
If FORCE_FILESYSTEM is set, we can't do this. We also don't do it if INCLUDE_FULL_LIBRARY, since
6969
not including the filesystem would mean not including the full JS libraries, and the same for
70-
MAIN_MODULE since a side module might need the filesystem.
70+
MAIN_MODULE=1 since a side module might need the filesystem.
7171
"""
72-
relevant_settings = ['FORCE_FILESYSTEM', 'INCLUDE_FULL_LIBRARY', 'MAIN_MODULE']
73-
if any(settings[s] for s in relevant_settings):
72+
if any(settings[s] for s in ['FORCE_FILESYSTEM', 'INCLUDE_FULL_LIBRARY']):
73+
return
74+
if settings.MAIN_MODULE == 1:
7475
return
7576

7677
if settings.FILESYSTEM == 0:
@@ -79,7 +80,9 @@ def optimize_syscalls(declares):
7980
else:
8081
# TODO(sbc): Find a better way to identify wasi syscalls
8182
syscall_prefixes = ('__syscall_', 'fd_')
82-
syscalls = {d for d in declares if d.startswith(syscall_prefixes) or d in ['path_open']}
83+
side_module_imports = [shared.demangle_c_symbol_name(s) for s in settings.SIDE_MODULE_IMPORTS]
84+
all_imports = set(imports).union(side_module_imports)
85+
syscalls = {d for d in all_imports if d.startswith(syscall_prefixes) or d in ['path_open']}
8386
# check if the only filesystem syscalls are in: close, ioctl, llseek, write
8487
# (without open, etc.. nothing substantial can be done, so we can disable
8588
# extra filesystem support in that case)
@@ -116,7 +119,7 @@ def get_weak_imports(main_wasm):
116119

117120

118121
def update_settings_glue(wasm_file, metadata):
119-
optimize_syscalls(metadata.imports)
122+
maybe_disable_filesystem(metadata.imports)
120123

121124
# Integrate info from backend
122125
if settings.SIDE_MODULE:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
28024
1+
15091

0 commit comments

Comments
 (0)