Skip to content

Commit 4109348

Browse files
authored
Stop doing extra optimization work in standalone mode (#14338)
Before this PR we would try to remove unneeded imports, as they might cause a wasm not to run in a WASI VM if it were nonstandard. However, I think that was only an issue when bringing up standalone mode (as we converted nonstandard things to WASI). Today, I verified that building hello world (even with C++ iostreams) in -O0 will run in both wasmtime and wasmer without issue. While there may be cases in which there are nonstandard imports, it is best to let the user explicitly run the optimizer to work around that, as otherwise it adds complexity (in particular, as sbc100 noticed, if we automatically run the optimizer even in unoptimized builds, it means that ERROR_ON_WASM_CHANGES_AFTER_LINK will always error in standalone mode).
1 parent 23d7d65 commit 4109348

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ See docs/process.md for more on how version tagging works.
3333
- Reinstated the warning on linker-only `-s` settings passed when not linking
3434
(i.e. when compiling with `-c`). As before this can disabled with
3535
`-Wno-unused-command-line-argument` (#14182).
36+
- Standalone wasm mode no longer does extra binaryen work during link. It used
37+
to remove unneeded imports, in hopes of avoiding nonstandard imports that
38+
could prevent running in WASI VMs, but that has not been needed any more. A
39+
minor side effect you might see from this is a larger wasm size in standalone
40+
mode when not optimizing (but optimized builds are unaffected). (#14338)
3641

3742
2.0.23
3843
------

emcc.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,6 @@ def get_binaryen_passes():
521521
passes += ['--no-exit-runtime']
522522
if run_binaryen_optimizer:
523523
passes += [building.opt_level_to_str(settings.OPT_LEVEL, settings.SHRINK_LEVEL)]
524-
elif settings.STANDALONE_WASM:
525-
# even if not optimizing, make an effort to remove all unused imports and
526-
# exports, to make the wasm as standalone as possible
527-
passes += ['--remove-unused-module-elements']
528524
# when optimizing, use the fact that low memory is never used (1024 is a
529525
# hardcoded value in the binaryen pass)
530526
if run_binaryen_optimizer and settings.GLOBAL_BASE >= 1024:

tests/test_other.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9683,6 +9683,8 @@ def ok(args, filename='hello_world.cpp', expected='hello, world!'):
96839683
ok(required_flags + ['-O1'])
96849684
# Exception support shouldn't require changes after linking
96859685
ok(required_flags + ['-fexceptions'])
9686+
# Standalone mode should not do anything special to the wasm.
9687+
ok(required_flags + ['-sSTANDALONE_WASM'])
96869688

96879689
# other builds fail with a standard message + extra details
96889690
def fail(args, details):

0 commit comments

Comments
 (0)