diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-02-09 16:28:46 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-10 00:28:46 +0000 |
commit | ed9d1a190383cd4705cf5725dcaef59b122c9770 (patch) | |
tree | 5d102fcfe6fa819999dce98a749d998622f1864a | |
parent | e130b58895b64a0fe3a088e25f4043a12f3634ca (diff) | |
download | binaryen-ed9d1a190383cd4705cf5725dcaef59b122c9770.tar.gz binaryen-ed9d1a190383cd4705cf5725dcaef59b122c9770.tar.bz2 binaryen-ed9d1a190383cd4705cf5725dcaef59b122c9770.zip |
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.
-rw-r--r-- | src/passes/GenerateDynCalls.cpp | 5 | ||||
-rw-r--r-- | test/passes/generate-dyncalls_all-features.txt (renamed from test/passes/generate-dyncalls.txt) | 32 | ||||
-rw-r--r-- | test/passes/generate-dyncalls_all-features.wast (renamed from test/passes/generate-dyncalls.wast) | 8 |
3 files changed, 39 insertions, 6 deletions
diff --git a/src/passes/GenerateDynCalls.cpp b/src/passes/GenerateDynCalls.cpp index a53f1d0de..9669dcdb8 100644 --- a/src/passes/GenerateDynCalls.cpp +++ b/src/passes/GenerateDynCalls.cpp @@ -129,9 +129,8 @@ void GenerateDynCalls::generateDynCallThunk(Signature sig) { } // FIXME: Should the existence of a table be ensured here? i.e. create one if // there is none? - Expression* call = - builder.makeCallIndirect(Name::fromInt(0), fptr, args, sig); - f->body = call; + assert(wasm->tables.size() > 0); + f->body = builder.makeCallIndirect(wasm->tables[0]->name, fptr, args, sig); wasm->addFunction(std::move(f)); exportFunction(*wasm, name, true); diff --git a/test/passes/generate-dyncalls.txt b/test/passes/generate-dyncalls_all-features.txt index 64a04de86..efee27acf 100644 --- a/test/passes/generate-dyncalls.txt +++ b/test/passes/generate-dyncalls_all-features.txt @@ -18,18 +18,44 @@ (i64.const 42) ) (func $dynCall_i (param $fptr i32) (result i32) - (call_indirect (type $none_=>_i32) + (call_indirect $0 (type $none_=>_i32) (local.get $fptr) ) ) (func $dynCall_ji (param $fptr i32) (param $0 i32) (result i64) - (call_indirect (type $i32_=>_i64) + (call_indirect $0 (type $i32_=>_i64) (local.get $0) (local.get $fptr) ) ) (func $dynCall_vii (param $fptr i32) (param $0 i32) (param $1 i32) - (call_indirect (type $i32_i32_=>_none) + (call_indirect $0 (type $i32_i32_=>_none) + (local.get $0) + (local.get $1) + (local.get $fptr) + ) + ) +) +(module + (type $i32_i32_i32_=>_none (func (param i32 i32 i32))) + (type $none_=>_i32 (func (result i32))) + (type $i32_i32_=>_none (func (param i32 i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (import "env" "table" (table $timport$0 1 1 funcref)) + (elem (i32.const 0) $f) + (import "env" "invoke_vii" (func $invoke_vii (param i32 i32 i32))) + (export "dynCall_i" (func $dynCall_i)) + (export "dynCall_vii" (func $dynCall_vii)) + (func $f (result i32) + (i32.const 42) + ) + (func $dynCall_i (param $fptr i32) (result i32) + (call_indirect $timport$0 (type $none_=>_i32) + (local.get $fptr) + ) + ) + (func $dynCall_vii (param $fptr i32) (param $0 i32) (param $1 i32) + (call_indirect $timport$0 (type $i32_i32_=>_none) (local.get $0) (local.get $1) (local.get $fptr) diff --git a/test/passes/generate-dyncalls.wast b/test/passes/generate-dyncalls_all-features.wast index 551d52a21..c73a6b6a5 100644 --- a/test/passes/generate-dyncalls.wast +++ b/test/passes/generate-dyncalls_all-features.wast @@ -9,3 +9,11 @@ (table 2 2 funcref) (elem (i32.const 0) $f1 $f2) ) +(module + (import "env" "invoke_vii" (func $invoke_vii (param i32 i32 i32))) + (import "env" "table" (table 1 1 funcref)) + (elem (i32.const 0) $f) + (func $f (result i32) + (i32.const 42) + ) +) |