summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-01-06 15:04:42 -0800
committerGitHub <noreply@github.com>2022-01-06 15:04:42 -0800
commit8c0f53d236f664086405870321e5887aaed39f3f (patch)
treee2d8153967535df252db9c98af584841cf7c5a38 /test
parent5049f077ae2d21166dc8ee4c3057bdc48cb3d94c (diff)
downloadbinaryen-8c0f53d236f664086405870321e5887aaed39f3f.tar.gz
binaryen-8c0f53d236f664086405870321e5887aaed39f3f.tar.bz2
binaryen-8c0f53d236f664086405870321e5887aaed39f3f.zip
[ctor-eval] Add --ignore-external-input option (#4428)
This is meant to address one of the main limitations of wasm-ctor-eval in emscripten atm, that libc++ global ctors will read env vars, which means they call an import, which stops us from evalling, emscripten-core/emscripten#15403 (comment) To handle that, this adds an option to ignore external input. When set, we can assume that no env vars will be read, no reading from stdin, no arguments to main(), etc. Perhaps these could each be separate options, but I think keeping it simple for now might be good enough.
Diffstat (limited to 'test')
-rw-r--r--test/ctor-eval/ignore-external-input.wast63
-rw-r--r--test/ctor-eval/ignore-external-input.wast.ctors1
-rw-r--r--test/ctor-eval/ignore-external-input.wast.out17
-rw-r--r--test/lit/help/wasm-ctor-eval.test3
4 files changed, 84 insertions, 0 deletions
diff --git a/test/ctor-eval/ignore-external-input.wast b/test/ctor-eval/ignore-external-input.wast
new file mode 100644
index 000000000..0849c67ab
--- /dev/null
+++ b/test/ctor-eval/ignore-external-input.wast
@@ -0,0 +1,63 @@
+(module
+ (import "wasi_snapshot_preview1" "environ_sizes_get" (func $wasi_environ_sizes_get (param i32 i32) (result i32)))
+ (import "wasi_snapshot_preview1" "environ_get" (func $wasi_environ_get (param i32 i32) (result i32)))
+
+ (import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi_args_sizes_get (param i32 i32) (result i32)))
+ (import "wasi_snapshot_preview1" "args_get" (func $wasi_args_get (param i32 i32) (result i32)))
+
+ (import "wasi_snapshot_preview1" "something_else" (func $wasi_something_else (result i32)))
+
+ (memory 256 256)
+ (data (i32.const 0) "aaaaaaaaaaaaaaaaaaaaaaaaaaaa") ;; the final 4 'a's will remain
+
+ (func "test1"
+ ;; This is ok to call: when ignoring external input we assume there is no
+ ;; environment to read.
+ (i32.store
+ (i32.const 0) ;; the result (0) will be written to address 0
+ (call $wasi_environ_sizes_get
+ (i32.const 4) ;; count (0) will be written to address 4
+ (i32.const 0)
+ )
+ )
+ (i32.store
+ (i32.const 8) ;; the result (0) will be written to address 8
+ (call $wasi_environ_get
+ (i32.const 0)
+ (i32.const 0)
+ )
+ )
+ )
+
+ (func "test2"
+ ;; This is also ok to call: when ignoring external input we assume there are
+ ;; not args passed to main.
+ (i32.store
+ (i32.const 12) ;; the result (0) will be written to address 12
+ (call $wasi_args_sizes_get
+ (i32.const 16) ;; argc (0) will be written to address 16
+ (i32.const 0)
+ )
+ )
+ (i32.store
+ (i32.const 20) ;; the result (0) will be written to address 20
+ (call $wasi_args_get
+ (i32.const 0)
+ (i32.const 0)
+ )
+ )
+ )
+
+ (func "test3"
+ ;; This is *not* ok to call, and we will *not* reach the final store after
+ ;; this call. This function will not be evalled and will remain in the
+ ;; output.
+ (drop
+ (call $wasi_something_else)
+ )
+ (i32.store
+ (i32.const 24)
+ (i32.const 100)
+ )
+ )
+)
diff --git a/test/ctor-eval/ignore-external-input.wast.ctors b/test/ctor-eval/ignore-external-input.wast.ctors
new file mode 100644
index 000000000..c7060ede5
--- /dev/null
+++ b/test/ctor-eval/ignore-external-input.wast.ctors
@@ -0,0 +1 @@
+test1,test2,test3
diff --git a/test/ctor-eval/ignore-external-input.wast.out b/test/ctor-eval/ignore-external-input.wast.out
new file mode 100644
index 000000000..f728afd0e
--- /dev/null
+++ b/test/ctor-eval/ignore-external-input.wast.out
@@ -0,0 +1,17 @@
+(module
+ (type $none_=>_i32 (func (result i32)))
+ (type $none_=>_none (func))
+ (import "wasi_snapshot_preview1" "something_else" (func $wasi_something_else (result i32)))
+ (memory $0 256 256)
+ (data (i32.const 24) "aaaa")
+ (export "test3" (func $2))
+ (func $2
+ (drop
+ (call $wasi_something_else)
+ )
+ (i32.store
+ (i32.const 24)
+ (i32.const 100)
+ )
+ )
+)
diff --git a/test/lit/help/wasm-ctor-eval.test b/test/lit/help/wasm-ctor-eval.test
index cf0671c81..364ac5d4c 100644
--- a/test/lit/help/wasm-ctor-eval.test
+++ b/test/lit/help/wasm-ctor-eval.test
@@ -19,6 +19,9 @@
;; CHECK-NEXT: --ctors,-c Comma-separated list of global
;; CHECK-NEXT: constructor functions to evaluate
;; CHECK-NEXT:
+;; CHECK-NEXT: --ignore-external-input,-ipi Assumes no env vars are to be read, stdin
+;; CHECK-NEXT: is empty, etc.
+;; CHECK-NEXT:
;; CHECK-NEXT:
;; CHECK-NEXT: Tool options:
;; CHECK-NEXT: -------------