diff options
author | Alon Zakai <azakai@google.com> | 2024-01-11 11:11:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-11 11:11:15 -0800 |
commit | e5948a939eb6610f1cb7742df8c54f6d17389b83 (patch) | |
tree | be3db7721599df7f53aa747c0e4581109a188f22 /src/tools/wasm-merge.cpp | |
parent | 141f7cad3aa516db3828e619b31fe681e46a151b (diff) | |
download | binaryen-e5948a939eb6610f1cb7742df8c54f6d17389b83.tar.gz binaryen-e5948a939eb6610f1cb7742df8c54f6d17389b83.tar.bz2 binaryen-e5948a939eb6610f1cb7742df8c54f6d17389b83.zip |
wasm-merge: Sort globals to ensure proper validation (#6221)
If the first module has a global that reads from a global that appears in a later
module, then we need to reorder the globals, because if we just append the
globals from the later module we'd end up with a global reading from another
that is not before it.
Changes to the existing renamings test are just due to the global sorting
pass that now runs (it not only fixes up validation errors but also tries to sort
in a more optimal order for size).
Fixes #6220
Diffstat (limited to 'src/tools/wasm-merge.cpp')
-rw-r--r-- | src/tools/wasm-merge.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 088317eec..0884350cb 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -586,13 +586,17 @@ Note that filenames and modules names are interleaved (which is hopefully less c // module. fuseImportsAndExports(); - // Remove unused things. This is obviously a useful optimization, but it also - // makes using the output easier: if an import was resolved by an export - // during the merge, then that import will have no more uses and it will be - // optimized out (while if we didn't optimize it out then instantiating the - // module would still be forced to provide something for that import). { PassRunner passRunner(&merged); + // We might have made some globals read from others that now appear after + // them (if the one they read was appended from a later module). Sort them + // to fix that. TODO: we could do this only if we actually append globals + passRunner.add("reorder-globals-always"); + // Remove unused things. This is obviously a useful optimization but it also + // makes using the output easier: if an import was resolved by an export + // during the merge, then that import will have no more uses and it will be + // optimized out (while if we didn't optimize it out then instantiating the + // module would still be forced to provide something for that import). passRunner.add("remove-unused-module-elements"); passRunner.run(); } |