summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2021-02-16 07:12:23 -0800
committerGitHub <noreply@github.com>2021-02-16 07:12:23 -0800
commit097b70ce2f53e9cc110c1b5f9cac359a0129994f (patch)
tree4d36c5c919b6a30f5bdf90d868b8774b8bc04307
parentc12cc3f50c0ef798b218739fc3de06237ea2c5d5 (diff)
downloadbinaryen-097b70ce2f53e9cc110c1b5f9cac359a0129994f.tar.gz
binaryen-097b70ce2f53e9cc110c1b5f9cac359a0129994f.tar.bz2
binaryen-097b70ce2f53e9cc110c1b5f9cac359a0129994f.zip
Fix removal of em_js strings (#3570)
-rw-r--r--src/wasm/wasm-emscripten.cpp2
-rw-r--r--test/lit/wasm-emscripten-finalize/em_js.wat12
2 files changed, 6 insertions, 8 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 7a593f599..99c3216b6 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -447,7 +447,7 @@ EmJsWalker findEmJsFuncsAndReturnWalker(Module& wasm) {
// We can detect this by checking for segments that contain only JS strings.
// When we find such segements we remove them from the final binary.
for (Index i = 0; i < wasm.memory.segments.size(); i++) {
- Address start = walker.stringTracker.segmentOffsets[0];
+ Address start = walker.stringTracker.segmentOffsets[i];
Address cur = start;
while (cur < start + wasm.memory.segments[i].data.size()) {
diff --git a/test/lit/wasm-emscripten-finalize/em_js.wat b/test/lit/wasm-emscripten-finalize/em_js.wat
index 0cce1e3b5..85b3ece89 100644
--- a/test/lit/wasm-emscripten-finalize/em_js.wat
+++ b/test/lit/wasm-emscripten-finalize/em_js.wat
@@ -5,26 +5,24 @@
;; All functions should be stripped from the binary, regardless
;; of internal name
-;; CHECK-NOT: (func
+;; CHECK-NOT: (func
;; The data section that contains only em_js strings should
-;; be stripped.
-;; CHECK-NOT: (i32.const 512) "Only em_js strings here\00")
-
-;; Data sections that also contain other stuff should not be stripped
+;; be stripped (shrunk to zero size):
;; CHECK: (data (i32.const 1024) "some JS string data\00xxx")
+;; CHECK: (data (i32.const 512) "")
;; CHECK: (data (i32.const 2048) "more JS string data\00yyy")
;; CHECK: "emJsFuncs": {
;; CHECK-NEXT: "bar": "more JS string data",
-;; CHECK-NEXT: "baz": "Only em_js strings here
+;; CHECK-NEXT: "baz": "Only em_js strings here",
;; CHECK-NEXT: "foo": "some JS string data"
;; CHECK-NEXT: },
(module
(memory 1 1)
- (data (i32.const 512) "Only em_js strings here\00")
(data (i32.const 1024) "some JS string data\00xxx")
+ (data (i32.const 512) "Only em_js strings here\00")
(data (i32.const 2048) "more JS string data\00yyy")
(export "__em_js__foo" (func $__em_js__foo))
(export "__em_js__bar" (func $bar))