Skip to content

Commit 3f15cfd

Browse files
authored
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
1 parent 48c897d commit 3f15cfd

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/library_autodebug.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ addToLibrary({
2929
dbg('get_f64 ' + [loc, index, value]);
3030
return value;
3131
},
32+
$get_funcref: (loc, index, value) => {
33+
dbg('get_funcref ' + [loc, index, value]);
34+
return value;
35+
},
36+
$get_externref: (loc, index, value) => {
37+
dbg('get_externref ' + [loc, index, value]);
38+
return value;
39+
},
3240
$get_anyref: (loc, index, value) => {
3341
dbg('get_anyref ' + [loc, index, value]);
3442
return value;
@@ -55,6 +63,14 @@ addToLibrary({
5563
dbg('set_f64 ' + [loc, index, value]);
5664
return value;
5765
},
66+
$set_funcref: (loc, index, value) => {
67+
dbg('set_afuncef ' + [loc, index, value]);
68+
return value;
69+
},
70+
$set_externref: (loc, index, value) => {
71+
dbg('set_externref ' + [loc, index, value]);
72+
return value;
73+
},
5874
$set_anyref: (loc, index, value) => {
5975
dbg('set_anyref ' + [loc, index, value]);
6076
return value;
@@ -115,12 +131,16 @@ extraLibraryFuncs.push(
115131
'$get_i64',
116132
'$get_f32',
117133
'$get_f64',
134+
'$get_funcref',
135+
'$get_externref',
118136
'$get_anyref',
119137
'$get_exnref',
120138
'$set_i32',
121139
'$set_i64',
122140
'$set_f32',
123141
'$set_f64',
142+
'$set_funcref',
143+
'$set_externref',
124144
'$set_anyref',
125145
'$set_exnref',
126146
'$load_ptr',

test/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6909,6 +6909,12 @@ def image_compare(output):
69096909
@no_asan('autodebug logging interferes with asan')
69106910
@with_env_modify({'EMCC_AUTODEBUG': '1'})
69116911
def test_autodebug_wasm(self):
6912+
# Even though the test itself doesn't directly use reference types,
6913+
# Binaryen's '--instrument-locals' will add their logging functions if
6914+
# reference-types is enabled. So make sure this test passes when
6915+
# reference-types feature is enabled as well.
6916+
self.emcc_args += ['-mreference-types']
6917+
self.node_args += shared.node_reference_types_flags(self.get_nodejs())
69126918
output = self.do_runf('core/test_autodebug.c', 'success')
69136919
# test that the program both works and also emits some of the logging
69146920
# (but without the specific output, as it is logging the actual locals

tools/emscripten.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,16 @@ def add_standard_wasm_imports(send_items_map):
779779
'get_i64',
780780
'get_f32',
781781
'get_f64',
782+
'get_funcref',
783+
'get_externref',
782784
'get_anyref',
783785
'get_exnref',
784786
'set_i32',
785787
'set_i64',
786788
'set_f32',
787789
'set_f64',
790+
'set_funcref',
791+
'set_externref',
788792
'set_anyref',
789793
'set_exnref',
790794
'load_ptr',

0 commit comments

Comments
 (0)