From 3f15cfdcd1fb035c3266505bfe2812c775ab9457 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 17 Apr 2024 09:50:39 +0900 Subject: [PATCH] Add reference type logging support (#21762) We need these if we want to enable reference-types feature in Clang by default. `test_autodebug_wasm` fails without this if we enable reference-types in Clang. (Even though the test itself doesn't seem to actually use them, turning on `EMCC_AUTODEBUG` runs `wasm-opt` with `--instrument-locals`, which adds imports for `get_` and `set_` functions for the reference types if reference-types feature is enabled: https://github.com/WebAssembly/binaryen/blob/8c834e8257b03ea87b639ddac9adefec64fcad00/src/passes/InstrumentLocals.cpp#L179-L187 --- src/library_autodebug.js | 20 ++++++++++++++++++++ test/test_core.py | 6 ++++++ tools/emscripten.py | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/src/library_autodebug.js b/src/library_autodebug.js index 84fda73f927a..f5f4a79d0b4f 100644 --- a/src/library_autodebug.js +++ b/src/library_autodebug.js @@ -29,6 +29,14 @@ addToLibrary({ dbg('get_f64 ' + [loc, index, value]); return value; }, + $get_funcref: (loc, index, value) => { + dbg('get_funcref ' + [loc, index, value]); + return value; + }, + $get_externref: (loc, index, value) => { + dbg('get_externref ' + [loc, index, value]); + return value; + }, $get_anyref: (loc, index, value) => { dbg('get_anyref ' + [loc, index, value]); return value; @@ -55,6 +63,14 @@ addToLibrary({ dbg('set_f64 ' + [loc, index, value]); return value; }, + $set_funcref: (loc, index, value) => { + dbg('set_afuncef ' + [loc, index, value]); + return value; + }, + $set_externref: (loc, index, value) => { + dbg('set_externref ' + [loc, index, value]); + return value; + }, $set_anyref: (loc, index, value) => { dbg('set_anyref ' + [loc, index, value]); return value; @@ -115,12 +131,16 @@ extraLibraryFuncs.push( '$get_i64', '$get_f32', '$get_f64', + '$get_funcref', + '$get_externref', '$get_anyref', '$get_exnref', '$set_i32', '$set_i64', '$set_f32', '$set_f64', + '$set_funcref', + '$set_externref', '$set_anyref', '$set_exnref', '$load_ptr', diff --git a/test/test_core.py b/test/test_core.py index 37813bfa5b51..568ff6de25a9 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -6909,6 +6909,12 @@ def image_compare(output): @no_asan('autodebug logging interferes with asan') @with_env_modify({'EMCC_AUTODEBUG': '1'}) def test_autodebug_wasm(self): + # Even though the test itself doesn't directly use reference types, + # Binaryen's '--instrument-locals' will add their logging functions if + # reference-types is enabled. So make sure this test passes when + # reference-types feature is enabled as well. + self.emcc_args += ['-mreference-types'] + self.node_args += shared.node_reference_types_flags(self.get_nodejs()) output = self.do_runf('core/test_autodebug.c', 'success') # test that the program both works and also emits some of the logging # (but without the specific output, as it is logging the actual locals diff --git a/tools/emscripten.py b/tools/emscripten.py index 2af5b8029a9b..522f4492343b 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -779,12 +779,16 @@ def add_standard_wasm_imports(send_items_map): 'get_i64', 'get_f32', 'get_f64', + 'get_funcref', + 'get_externref', 'get_anyref', 'get_exnref', 'set_i32', 'set_i64', 'set_f32', 'set_f64', + 'set_funcref', + 'set_externref', 'set_anyref', 'set_exnref', 'load_ptr',