Skip to content

Commit ed9d1a1

Browse files
authored
Use correct table name in GenerateDynCalls (#3560)
GenerateDynCalls was hardcoding the table name to use in the call_indirects in the dyncall thunks. The hardcoded name was different from the default name for imported tables, so the call_indirects referred to a nonexistent table when dynamic linking was enabled. This PR instead uses the name of table 0 when creating call_indirects for the dyncall thunks.
1 parent e130b58 commit ed9d1a1

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/passes/GenerateDynCalls.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ void GenerateDynCalls::generateDynCallThunk(Signature sig) {
129129
}
130130
// FIXME: Should the existence of a table be ensured here? i.e. create one if
131131
// there is none?
132-
Expression* call =
133-
builder.makeCallIndirect(Name::fromInt(0), fptr, args, sig);
134-
f->body = call;
132+
assert(wasm->tables.size() > 0);
133+
f->body = builder.makeCallIndirect(wasm->tables[0]->name, fptr, args, sig);
135134

136135
wasm->addFunction(std::move(f));
137136
exportFunction(*wasm, name, true);

test/passes/generate-dyncalls.txt renamed to test/passes/generate-dyncalls_all-features.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,44 @@
1818
(i64.const 42)
1919
)
2020
(func $dynCall_i (param $fptr i32) (result i32)
21-
(call_indirect (type $none_=>_i32)
21+
(call_indirect $0 (type $none_=>_i32)
2222
(local.get $fptr)
2323
)
2424
)
2525
(func $dynCall_ji (param $fptr i32) (param $0 i32) (result i64)
26-
(call_indirect (type $i32_=>_i64)
26+
(call_indirect $0 (type $i32_=>_i64)
2727
(local.get $0)
2828
(local.get $fptr)
2929
)
3030
)
3131
(func $dynCall_vii (param $fptr i32) (param $0 i32) (param $1 i32)
32-
(call_indirect (type $i32_i32_=>_none)
32+
(call_indirect $0 (type $i32_i32_=>_none)
33+
(local.get $0)
34+
(local.get $1)
35+
(local.get $fptr)
36+
)
37+
)
38+
)
39+
(module
40+
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
41+
(type $none_=>_i32 (func (result i32)))
42+
(type $i32_i32_=>_none (func (param i32 i32)))
43+
(type $i32_=>_i32 (func (param i32) (result i32)))
44+
(import "env" "table" (table $timport$0 1 1 funcref))
45+
(elem (i32.const 0) $f)
46+
(import "env" "invoke_vii" (func $invoke_vii (param i32 i32 i32)))
47+
(export "dynCall_i" (func $dynCall_i))
48+
(export "dynCall_vii" (func $dynCall_vii))
49+
(func $f (result i32)
50+
(i32.const 42)
51+
)
52+
(func $dynCall_i (param $fptr i32) (result i32)
53+
(call_indirect $timport$0 (type $none_=>_i32)
54+
(local.get $fptr)
55+
)
56+
)
57+
(func $dynCall_vii (param $fptr i32) (param $0 i32) (param $1 i32)
58+
(call_indirect $timport$0 (type $i32_i32_=>_none)
3359
(local.get $0)
3460
(local.get $1)
3561
(local.get $fptr)

test/passes/generate-dyncalls.wast renamed to test/passes/generate-dyncalls_all-features.wast

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@
99
(table 2 2 funcref)
1010
(elem (i32.const 0) $f1 $f2)
1111
)
12+
(module
13+
(import "env" "invoke_vii" (func $invoke_vii (param i32 i32 i32)))
14+
(import "env" "table" (table 1 1 funcref))
15+
(elem (i32.const 0) $f)
16+
(func $f (result i32)
17+
(i32.const 42)
18+
)
19+
)

0 commit comments

Comments
 (0)