summaryrefslogtreecommitdiff
path: root/test/spec-wasm2c-prefix.c
diff options
context:
space:
mode:
authorKeith Winstein <keithw@cs.stanford.edu>2023-01-25 10:28:11 -0800
committerGitHub <noreply@github.com>2023-01-25 10:28:11 -0800
commit777e651edbe2a1931bd0d9746da5eaae8cc61ca9 (patch)
tree21ec1ac065b1ef7a6ef98ce36f3f26bec40b7813 /test/spec-wasm2c-prefix.c
parent165d5d62485bf09ddac404ab908a7c0ebf6b9851 (diff)
downloadwabt-777e651edbe2a1931bd0d9746da5eaae8cc61ca9.tar.gz
wabt-777e651edbe2a1931bd0d9746da5eaae8cc61ca9.tar.bz2
wabt-777e651edbe2a1931bd0d9746da5eaae8cc61ca9.zip
wasm2c: serialize types at wasm2c-time (#2120)
This makes wasm2c serialize each function type, rather than registering function types at module-initialization time. The serialized function type is the SHA-256 of the mangled param and result types (with a space between params and results). At runtime in call_indirect, a known (immediate) function type is compared against the function type stored in a funcref structure. For call_indirects to functions local to the module, or for any call_indirect when the toolchain merges string constants across compilation units (generally, GCC and clang), this can be done by comparing the pointers to each function type. Otherwise, the actual 32-byte values are compared. The function type IDs can be looked up at runtime with `Z_[modname]_get_func_type`, which matches the API from `wasm_rt_register_func_type`. A new `callback` example demos this. wasm2c does the SHA-256 either by linking against libcrypto or, if not available or if requested via `cmake -DUSE_INTERNAL_SHA256=ON`, by using a vendored (header-only) PicoSHA2. There is no runtime dependency on SHA-256 in the wasm2c runtime or generated modules. This eliminates the last of the per-module state, so this commit also removes the [modname]_init_module() function and the s_module_initialized bool.
Diffstat (limited to 'test/spec-wasm2c-prefix.c')
-rw-r--r--test/spec-wasm2c-prefix.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/test/spec-wasm2c-prefix.c b/test/spec-wasm2c-prefix.c
index b9ba0934..c3c6e500 100644
--- a/test/spec-wasm2c-prefix.c
+++ b/test/spec-wasm2c-prefix.c
@@ -194,10 +194,15 @@ static bool is_equal_wasm_rt_externref_t(wasm_rt_externref_t x,
return x == y;
}
+static inline bool is_equal_wasm_rt_func_type_t(const wasm_rt_func_type_t a,
+ const wasm_rt_func_type_t b) {
+ return (a == b) || (a && b && !memcmp(a, b, 32));
+}
+
static bool is_equal_wasm_rt_funcref_t(wasm_rt_funcref_t x,
wasm_rt_funcref_t y) {
- return (x.func_type == y.func_type) && (x.func == y.func) &&
- (x.module_instance == y.module_instance);
+ return is_equal_wasm_rt_func_type_t(x.func_type, y.func_type) &&
+ (x.func == y.func) && (x.module_instance == y.module_instance);
}
wasm_rt_externref_t spectest_make_externref(uintptr_t x) {