Skip to content

Commit

Permalink
Add reference type logging support (emscripten-core#21762)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aheejin authored Apr 17, 2024
1 parent 48c897d commit 3f15cfd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/library_autodebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3f15cfd

Please sign in to comment.