diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-06-14 15:46:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-14 15:46:30 -0700 |
commit | 6fdd9dd2137a563bc41a85cf45178cc734e499a2 (patch) | |
tree | a3aeb3cc570da5702e143602c22e0df775c5e4ff | |
parent | 8f524e8f926b6993878f02334e730fe5f65096f6 (diff) | |
download | binaryen-6fdd9dd2137a563bc41a85cf45178cc734e499a2.tar.gz binaryen-6fdd9dd2137a563bc41a85cf45178cc734e499a2.tar.bz2 binaryen-6fdd9dd2137a563bc41a85cf45178cc734e499a2.zip |
Do not create dyncall thunks for functions with i64 results or params (#586)
Dyncall thunks are meant to be used with emscripten on the web; however
on the web, functions with i64 results or params are not allowed to be
exported.
-rw-r--r-- | src/wasm-linker.cpp | 9 | ||||
-rw-r--r-- | test/dot_s/dyncall.c | 4 | ||||
-rw-r--r-- | test/dot_s/dyncall.s | 34 | ||||
-rw-r--r-- | test/dot_s/dyncall.wast | 43 | ||||
-rw-r--r-- | test/dot_s/indirect-import.wast | 17 |
5 files changed, 39 insertions, 68 deletions
diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 1ec2defc9..e6a0a0514 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -357,12 +357,21 @@ void Linker::emscriptenGlue(std::ostream& o) { o << " }\n"; } +bool hasI64ResultOrParam(FunctionType* ft) { + if (ft->result == i64) return true; + for (auto ty : ft->params) { + if (ty == i64) return true; + } + return false; +} + void Linker::makeDynCallThunks() { std::unordered_set<std::string> sigs; wasm::Builder wasmBuilder(out.wasm); for (const auto& indirectFunc : out.wasm.table.names) { std::string sig(getSig(out.wasm.getFunction(indirectFunc))); auto* funcType = ensureFunctionType(sig, &out.wasm); + if (hasI64ResultOrParam(funcType)) continue; // Can't export i64s on the web. if (!sigs.insert(sig).second) continue; // Sig is already in the set std::vector<NameType> params; params.emplace_back("fptr", i32); // function pointer param diff --git a/test/dot_s/dyncall.c b/test/dot_s/dyncall.c index 16c70b066..791c5d67a 100644 --- a/test/dot_s/dyncall.c +++ b/test/dot_s/dyncall.c @@ -5,7 +5,7 @@ uint32_t i() { return 0; } -uint64_t jf(float f) { +uint32_t i_f(float f) { return 0; } void vd(double d) { @@ -22,7 +22,7 @@ void vd2(double d) { int main() { asm(" i32.const $drop=, i@FUNCTION"); - asm(" i32.const $drop=, jf@FUNCTION"); + asm(" i32.const $drop=, i_f@FUNCTION"); asm(" i32.const $drop=, vd@FUNCTION"); asm(" i32.const $drop=, ffjjdi@FUNCTION"); asm(" i32.const $drop=, vd2@FUNCTION"); diff --git a/test/dot_s/dyncall.s b/test/dot_s/dyncall.s index 45d80e474..0d36f7463 100644 --- a/test/dot_s/dyncall.s +++ b/test/dot_s/dyncall.s @@ -1,5 +1,5 @@ .text - .file "src/work/binaryen/test/dot_s/dyncall.c" + .file "test/dot_s/dyncall.c" .section .text.i,"ax",@progbits .hidden i .globl i @@ -8,24 +8,24 @@ i: # @i .result i32 # BB#0: # %entry i32.const $push0=, 0 - return $pop0 + # fallthrough-return: $pop0 .endfunc .Lfunc_end0: .size i, .Lfunc_end0-i - .section .text.jf,"ax",@progbits - .hidden jf - .globl jf - .type jf,@function -jf: # @jf + .section .text.i_f,"ax",@progbits + .hidden i_f + .globl i_f + .type i_f,@function +i_f: # @i_f .param f32 - .result i64 + .result i32 # BB#0: # %entry - i64.const $push0=, 0 - return $pop0 + i32.const $push0=, 0 + # fallthrough-return: $pop0 .endfunc .Lfunc_end1: - .size jf, .Lfunc_end1-jf + .size i_f, .Lfunc_end1-i_f .section .text.vd,"ax",@progbits .hidden vd @@ -34,7 +34,7 @@ jf: # @jf vd: # @vd .param f64 # BB#0: # %entry - return + # fallthrough-return .endfunc .Lfunc_end2: .size vd, .Lfunc_end2-vd @@ -48,7 +48,7 @@ ffjjdi: # @ffjjdi .result f32 # BB#0: # %entry f32.const $push0=, 0x0p0 - return $pop0 + # fallthrough-return: $pop0 .endfunc .Lfunc_end3: .size ffjjdi, .Lfunc_end3-ffjjdi @@ -60,7 +60,7 @@ ffjjdi: # @ffjjdi vd2: # @vd2 .param f64 # BB#0: # %entry - return + # fallthrough-return .endfunc .Lfunc_end4: .size vd2, .Lfunc_end4-vd2 @@ -76,7 +76,7 @@ main: # @main i32.const $drop=, i@FUNCTION #NO_APP #APP - i32.const $drop=, jf@FUNCTION + i32.const $drop=, i_f@FUNCTION #NO_APP #APP i32.const $drop=, vd@FUNCTION @@ -88,10 +88,10 @@ main: # @main i32.const $drop=, vd2@FUNCTION #NO_APP i32.const $push0=, 0 - return $pop0 + # fallthrough-return: $pop0 .endfunc .Lfunc_end5: .size main, .Lfunc_end5-main - .ident "clang version 3.9.0 " + .ident "clang version 3.9.0 (trunk 272564) (llvm/trunk 272563)" diff --git a/test/dot_s/dyncall.wast b/test/dot_s/dyncall.wast index 52b503821..b0521de84 100644 --- a/test/dot_s/dyncall.wast +++ b/test/dot_s/dyncall.wast @@ -2,40 +2,31 @@ (memory 1) (export "memory" memory) (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$jf (func (param f32) (result i64))) + (type $FUNCSIG$if (func (param f32) (result i32))) (type $FUNCSIG$vd (func (param f64))) (type $FUNCSIG$ffjjdi (func (param f32 i64 i64 f64 i32) (result f32))) (export "i" $i) - (export "jf" $jf) + (export "i_f" $i_f) (export "vd" $vd) (export "ffjjdi" $ffjjdi) (export "vd2" $vd2) (export "main" $main) (export "dynCall_i" $dynCall_i) - (export "dynCall_jf" $dynCall_jf) + (export "dynCall_if" $dynCall_if) (export "dynCall_vd" $dynCall_vd) - (export "dynCall_ffjjdi" $dynCall_ffjjdi) - (table $i $jf $vd $ffjjdi $vd2) + (table $i $i_f $vd $ffjjdi $vd2) (func $i (type $FUNCSIG$i) (result i32) - (return - (i32.const 0) - ) + (i32.const 0) ) - (func $jf (type $FUNCSIG$jf) (param $0 f32) (result i64) - (return - (i64.const 0) - ) + (func $i_f (type $FUNCSIG$if) (param $0 f32) (result i32) + (i32.const 0) ) (func $vd (type $FUNCSIG$vd) (param $0 f64) - (return) ) (func $ffjjdi (type $FUNCSIG$ffjjdi) (param $0 f32) (param $1 i64) (param $2 i64) (param $3 f64) (param $4 i32) (result f32) - (return - (f32.const 0) - ) + (f32.const 0) ) (func $vd2 (type $FUNCSIG$vd) (param $0 f64) - (return) ) (func $main (result i32) (i32.const 0) @@ -43,17 +34,15 @@ (i32.const 2) (i32.const 3) (i32.const 4) - (return - (i32.const 0) - ) + (i32.const 0) ) (func $dynCall_i (param $fptr i32) (result i32) (call_indirect $FUNCSIG$i (get_local $fptr) ) ) - (func $dynCall_jf (param $fptr i32) (param $0 f32) (result i64) - (call_indirect $FUNCSIG$jf + (func $dynCall_if (param $fptr i32) (param $0 f32) (result i32) + (call_indirect $FUNCSIG$if (get_local $fptr) (get_local $0) ) @@ -64,15 +53,5 @@ (get_local $0) ) ) - (func $dynCall_ffjjdi (param $fptr i32) (param $0 f32) (param $1 i64) (param $2 i64) (param $3 f64) (param $4 i32) (result f32) - (call_indirect $FUNCSIG$ffjjdi - (get_local $fptr) - (get_local $0) - (get_local $1) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) ) ;; METADATA: { "asmConsts": {},"staticBump": 12, "initializers": [] } diff --git a/test/dot_s/indirect-import.wast b/test/dot_s/indirect-import.wast index b24b5cd59..21378eefa 100644 --- a/test/dot_s/indirect-import.wast +++ b/test/dot_s/indirect-import.wast @@ -15,9 +15,7 @@ (export "bar" $bar) (export "baz" $baz) (export "dynCall_fd" $dynCall_fd) - (export "dynCall_vj" $dynCall_vj) (export "dynCall_v" $dynCall_v) - (export "dynCall_ijidf" $dynCall_ijidf) (export "dynCall_vi" $dynCall_vi) (table $__importThunk_extern_fd $__importThunk_extern_vj $__importThunk_extern_v $__importThunk_extern_ijidf $__importThunk_extern_struct $__importThunk_extern_sret) (func $bar (result i32) @@ -121,26 +119,11 @@ (get_local $0) ) ) - (func $dynCall_vj (param $fptr i32) (param $0 i64) - (call_indirect $FUNCSIG$vj - (get_local $fptr) - (get_local $0) - ) - ) (func $dynCall_v (param $fptr i32) (call_indirect $FUNCSIG$v (get_local $fptr) ) ) - (func $dynCall_ijidf (param $fptr i32) (param $0 i64) (param $1 i32) (param $2 f64) (param $3 f32) (result i32) - (call_indirect $FUNCSIG$ijidf - (get_local $fptr) - (get_local $0) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) (func $dynCall_vi (param $fptr i32) (param $0 i32) (call_indirect $FUNCSIG$vi (get_local $fptr) |