diff options
author | Alon Zakai <alonzakai@gmail.com> | 2019-02-06 16:10:06 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-06 16:10:06 -0800 |
commit | ab35a43ed3f3e5173b511e7e00239c50172fbddf (patch) | |
tree | 4ebdc98611b9b8c95a42bd0df65d00788fb22546 | |
parent | e2e0c2751f3fe4b3cc7493d2ea3274d821e62b8b (diff) | |
download | binaryen-ab35a43ed3f3e5173b511e7e00239c50172fbddf.tar.gz binaryen-ab35a43ed3f3e5173b511e7e00239c50172fbddf.tar.bz2 binaryen-ab35a43ed3f3e5173b511e7e00239c50172fbddf.zip |
wasm-emscripten-finalize: separateDataSegments() fix (#1897)
We should emit a file with only the data segments, starting from the global base, and not starting from zero (the data before is unneeded, and the emscripten loading code assumes it isn't there).
Also fix the auto updater to work properly on .mem test updating.
-rwxr-xr-x | auto_update_tests.py | 2 | ||||
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 5 | ||||
-rw-r--r-- | src/wasm-emscripten.h | 5 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 3 | ||||
-rw-r--r-- | test/lld/em_asm.wast.mem.mem | bin | 652 -> 84 bytes | |||
-rw-r--r-- | test/lld/hello_world.wast.mem.mem | bin | 581 -> 13 bytes |
6 files changed, 11 insertions, 4 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index bef6a8908..f37019f3f 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -80,7 +80,7 @@ def update_lld_tests(): extension_arg_map = { '.out': [], '.jscall.out': ['--emscripten-reserved-function-pointers=3'], - '.mem.out': ['--separate-data-segments', mem_file], + '.mem.out': ['--separate-data-segments', mem_file + '.mem'], } for ext, ext_args in extension_arg_map.items(): out_path = wast_path + ext diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index f2c74221d..42fc1e4db 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -224,7 +224,10 @@ int main(int argc, const char *argv[]) { // for metadata). if (!dataSegmentFile.empty()) { Output memInitFile(dataSegmentFile, Flags::Binary, Flags::Release); - generator.separateDataSegments(&memInitFile); + if (globalBase == INVALID_BASE) { + Fatal() << "globalBase must be set"; + } + generator.separateDataSegments(&memInitFile, globalBase); } if (options.debug) { diff --git a/src/wasm-emscripten.h b/src/wasm-emscripten.h index d078cafbf..275c809fd 100644 --- a/src/wasm-emscripten.h +++ b/src/wasm-emscripten.h @@ -57,7 +57,10 @@ public: void fixInvokeFunctionNames(); - void separateDataSegments(Output* outfile); + // Emits the data segments to a file. The file contains data from address base + // onwards (we must pass in base, as we can't tell it from the wasm - the first + // segment may start after a run of zeros, but we need those zeros in the file). + void separateDataSegments(Output* outfile, Address base); private: Module& wasm; diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index e09ad98d2..a383a812a 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -919,10 +919,11 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( return meta.str(); } -void EmscriptenGlueGenerator::separateDataSegments(Output* outfile) { +void EmscriptenGlueGenerator::separateDataSegments(Output* outfile, Address base) { size_t lastEnd = 0; for (Memory::Segment& seg : wasm.memory.segments) { size_t offset = seg.offset->cast<Const>()->value.geti32(); + offset -= base; size_t fill = offset - lastEnd; if (fill > 0) { std::vector<char> buf(fill); diff --git a/test/lld/em_asm.wast.mem.mem b/test/lld/em_asm.wast.mem.mem Binary files differindex 1e5476727..9249eb195 100644 --- a/test/lld/em_asm.wast.mem.mem +++ b/test/lld/em_asm.wast.mem.mem diff --git a/test/lld/hello_world.wast.mem.mem b/test/lld/hello_world.wast.mem.mem Binary files differindex 674c410a9..2bc1f1ee6 100644 --- a/test/lld/hello_world.wast.mem.mem +++ b/test/lld/hello_world.wast.mem.mem |