From 097b70ce2f53e9cc110c1b5f9cac359a0129994f Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 16 Feb 2021 07:12:23 -0800 Subject: Fix removal of em_js strings (#3570) --- src/wasm/wasm-emscripten.cpp | 2 +- test/lit/wasm-emscripten-finalize/em_js.wat | 12 +++++------- 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)) -- cgit v1.2.3