diff options
author | Sam Clegg <sbc@chromium.org> | 2021-02-11 16:53:51 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-12 00:53:51 +0000 |
commit | 8369064c09964ab77eae2af6f0d8cce58e412e11 (patch) | |
tree | 2f12e2dd1e4ca21332d5f9e89a8c29382826204e /test | |
parent | e283300dbb8bf573584a811bdc973b3731b67486 (diff) | |
download | binaryen-8369064c09964ab77eae2af6f0d8cce58e412e11.tar.gz binaryen-8369064c09964ab77eae2af6f0d8cce58e412e11.tar.bz2 binaryen-8369064c09964ab77eae2af6f0d8cce58e412e11.zip |
finalize: strip segments that contain only EM_ASM/EM_JS data (#3557)
If we find a data segment whose entire contents is EM_JS or EM_ASM
strings then strip it from the binary.
See: https://github.com/emscripten-core/emscripten/pull/13443
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/wasm-emscripten-finalize/em_asm.wat | 29 | ||||
-rw-r--r-- | test/lit/wasm-emscripten-finalize/em_asm_partial.wat | 24 | ||||
-rw-r--r-- | test/lit/wasm-emscripten-finalize/em_js.wat | 25 |
3 files changed, 73 insertions, 5 deletions
diff --git a/test/lit/wasm-emscripten-finalize/em_asm.wat b/test/lit/wasm-emscripten-finalize/em_asm.wat new file mode 100644 index 000000000..43dbfb9ae --- /dev/null +++ b/test/lit/wasm-emscripten-finalize/em_asm.wat @@ -0,0 +1,29 @@ +;; Test that em_asm string are extracted correctly when the __start_em_asm +;; and __stop_em_asm globals are exported. + +;; RUN: wasm-emscripten-finalize %s -S | filecheck %s + +;; Check that the data segment that contains only EM_ASM strings resized to +;; zero, and that the string are extracted into the metadata. + +;; CHECK: (data (i32.const 100) "normal data") +;; CHECK-NEXT: (data (i32.const 512) "") +;; CHECK-NEXT: (data (i32.const 1024) "more data") + +;; CHECK: "asmConsts": { +;; CHECK-NEXT: "512": "{ console.log('JS hello'); }", +;; CHECK-NEXT: "541": "{ console.log('hello again'); }" +;; CHECK-NEXT: }, + +;; Check that the exports are removed +;; CHECK-NOT: export + +(module + (memory 1 1) + (global (export "__start_em_asm") i32 (i32.const 512)) + (global (export "__stop_em_asm") i32 (i32.const 573)) + + (data (i32.const 100) "normal data") + (data (i32.const 512) "{ console.log('JS hello'); }\00{ console.log('hello again'); }\00") + (data (i32.const 1024) "more data") +) diff --git a/test/lit/wasm-emscripten-finalize/em_asm_partial.wat b/test/lit/wasm-emscripten-finalize/em_asm_partial.wat new file mode 100644 index 000000000..6432f1689 --- /dev/null +++ b/test/lit/wasm-emscripten-finalize/em_asm_partial.wat @@ -0,0 +1,24 @@ +;; Test that em_asm string are extraced correctly when the __start_em_asm +;; and __stop_em_asm globals are exported. + +;; RUN: wasm-emscripten-finalize %s -S | filecheck %s + +;; Check for the case when __start_em_asm and __stop_em_asm don't define an +;; entire segment. In this case we preserve the segment but zero the data. + +;; CHECK: (data (i32.const 512) "xx\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00yy") + +;; CHECK: "asmConsts": { +;; CHECK-NEXT: "514": "{ console.log('JS hello'); }", +;; CHECK-NEXT: "543": "{ console.log('hello again'); }" +;; CHECK-NEXT: }, + +;; Check that the exports are removed +;; CHECK-NOT: export + +(module + (memory 1 1) + (global (export "__start_em_asm") i32 (i32.const 514)) + (global (export "__stop_em_asm") i32 (i32.const 575)) + (data (i32.const 512) "xx{ console.log('JS hello'); }\00{ console.log('hello again'); }\00yy") +) diff --git a/test/lit/wasm-emscripten-finalize/em_js.wat b/test/lit/wasm-emscripten-finalize/em_js.wat index c2dd4c17d..0cce1e3b5 100644 --- a/test/lit/wasm-emscripten-finalize/em_js.wat +++ b/test/lit/wasm-emscripten-finalize/em_js.wat @@ -3,20 +3,32 @@ ;; RUN: wasm-emscripten-finalize %s -S | filecheck %s -;; Both functions should be stripped from the binary +;; All functions should be stripped from the binary, regardless +;; of internal name ;; 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 +;; CHECK: (data (i32.const 1024) "some JS string data\00xxx") +;; CHECK: (data (i32.const 2048) "more JS string data\00yyy") + ;; CHECK: "emJsFuncs": { -;; CHECK-NEXT: "bar": "more JS string dara", -;; CHECK-NEXT: "foo": "some JS string" +;; CHECK-NEXT: "bar": "more JS string data", +;; CHECK-NEXT: "baz": "Only em_js strings here +;; CHECK-NEXT: "foo": "some JS string data" ;; CHECK-NEXT: }, (module (memory 1 1) - (data (i32.const 1024) "some JS string\00") - (data (i32.const 2048) "more JS string dara\00") + (data (i32.const 512) "Only em_js strings here\00") + (data (i32.const 1024) "some JS string data\00xxx") + (data (i32.const 2048) "more JS string data\00yyy") (export "__em_js__foo" (func $__em_js__foo)) (export "__em_js__bar" (func $bar)) + (export "__em_js__baz" (func $baz)) ;; Name matches export name (func $__em_js__foo (result i32) (i32.const 1024) @@ -25,4 +37,7 @@ (func $bar (result i32) (i32.const 2048) ) + (func $baz (result i32) + (i32.const 512) + ) ) |