From 80dc7d63986781c11de3ba4adb30a38915c3912f Mon Sep 17 00:00:00 2001 From: Guanzhong Chen Date: Fri, 16 Aug 2019 13:37:32 -0700 Subject: [PATCH 1/4] Fix infinite loop in AsmConstWalker::visitCall --- src/wasm/wasm-emscripten.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index caea833027e..11b139766e0 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -718,6 +718,11 @@ void AsmConstWalker::visitCall(Call* curr) { if (set) { assert(set->index == get->index); arg = set->value; + } else { + Fatal() << "local.get of unknown in arg0 of call to " << import->base + << " in function " << getFunction()->name + << ".\nThis might be caused by aggressive compiler " + "transformations. Consider using EM_JS instead."; } } else if (auto* value = arg->dynCast()) { // In the dynamic linking case the address of the string constant @@ -729,7 +734,7 @@ void AsmConstWalker::visitCall(Call* curr) { } else { if (!value) { Fatal() << "Unexpected arg0 type (" << getExpressionName(arg) - << ") in call to to: " << import->base; + << ") in call to: " << import->base; } } } From 244bd5cf4db717499a2f6f2c3187680935b92f44 Mon Sep 17 00:00:00 2001 From: Guanzhong Chen Date: Fri, 16 Aug 2019 13:44:51 -0700 Subject: [PATCH 2/4] Add unit test --- test/unit/input/em_asm_mangled_string.wast | 11 +++++++++++ test/unit/test_lld.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/unit/input/em_asm_mangled_string.wast create mode 100644 test/unit/test_lld.py diff --git a/test/unit/input/em_asm_mangled_string.wast b/test/unit/input/em_asm_mangled_string.wast new file mode 100644 index 00000000000..aa856270d96 --- /dev/null +++ b/test/unit/input/em_asm_mangled_string.wast @@ -0,0 +1,11 @@ +(module + (import "env" "emscripten_asm_const_int" (func $emscripten_asm_const_int (param i32 i32 i32) (result i32))) + (global $global$0 (mut i32) (i32.const 66192)) + (global $global$1 i32 (i32.const 652)) + (export "__data_end" (global $global$1)) + (export "main" (func $main)) + (func $main (param $0 i32) (param $1 i32) (result i32) + (drop (call $emscripten_asm_const_int (local.get $0) (i32.const 0) (i32.const 0))) + (i32.const 0) + ) +) diff --git a/test/unit/test_lld.py b/test/unit/test_lld.py new file mode 100644 index 00000000000..229dae7c11f --- /dev/null +++ b/test/unit/test_lld.py @@ -0,0 +1,14 @@ +from scripts.test.shared import WASM_EMSCRIPTEN_FINALIZE, run_process +from .utils import BinaryenTestCase +import os + + +class EmscriptenFinalizeTest(BinaryenTestCase): + def test_em_asm_mangled_string(self): + input_dir = os.path.dirname(__file__) + p = run_process(WASM_EMSCRIPTEN_FINALIZE + [ + os.path.join(input_dir, 'input', 'em_asm_mangled_string.wast'), '-o', os.devnull, '--global-base=1024' + ], check=False, capture_output=True) + self.assertNotEqual(p.returncode, 0) + self.assertIn('Fatal: local.get of unknown in arg0 of call to $emscripten_asm_const_int in function $main.', p.stderr) + self.assertIn('This might be caused by aggressive compiler transformations. Consider using EM_JS instead.', p.stderr) From a09d37e0f839ecbd2a4d06983d83c76ae9ae69ca Mon Sep 17 00:00:00 2001 From: Guanzhong Chen Date: Fri, 16 Aug 2019 13:57:25 -0700 Subject: [PATCH 3/4] Explicitly mention EM_ASM* macros --- src/wasm/wasm-emscripten.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 11b139766e0..04aee52c6f4 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -719,10 +719,11 @@ void AsmConstWalker::visitCall(Call* curr) { assert(set->index == get->index); arg = set->value; } else { - Fatal() << "local.get of unknown in arg0 of call to " << import->base - << " in function " << getFunction()->name - << ".\nThis might be caused by aggressive compiler " - "transformations. Consider using EM_JS instead."; + Fatal() + << "local.get of unknown in arg0 of call to " << import->base + << " in function " << getFunction()->name + << " (used by EM_ASM* macros).\nThis might be caused by aggressive " + "compiler transformations. Consider using EM_JS instead."; } } else if (auto* value = arg->dynCast()) { // In the dynamic linking case the address of the string constant From fafd7a5b666ea88a9a0a4f46e601dbeb6038aede Mon Sep 17 00:00:00 2001 From: Guanzhong Chen Date: Fri, 16 Aug 2019 14:41:27 -0700 Subject: [PATCH 4/4] Rename test and fix error message --- src/wasm/wasm-emscripten.cpp | 10 +++++----- test/unit/{test_lld.py => test_finalize.py} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename test/unit/{test_lld.py => test_finalize.py} (88%) diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 04aee52c6f4..978afa296e9 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -719,11 +719,11 @@ void AsmConstWalker::visitCall(Call* curr) { assert(set->index == get->index); arg = set->value; } else { - Fatal() - << "local.get of unknown in arg0 of call to " << import->base - << " in function " << getFunction()->name - << " (used by EM_ASM* macros).\nThis might be caused by aggressive " - "compiler transformations. Consider using EM_JS instead."; + Fatal() << "local.get of unknown in arg0 of call to " << import->base + << " (used by EM_ASM* macros) in function " + << getFunction()->name + << ".\nThis might be caused by aggressive compiler " + "transformations. Consider using EM_JS instead."; } } else if (auto* value = arg->dynCast()) { // In the dynamic linking case the address of the string constant diff --git a/test/unit/test_lld.py b/test/unit/test_finalize.py similarity index 88% rename from test/unit/test_lld.py rename to test/unit/test_finalize.py index 229dae7c11f..cdcfe27e809 100644 --- a/test/unit/test_lld.py +++ b/test/unit/test_finalize.py @@ -10,5 +10,5 @@ def test_em_asm_mangled_string(self): os.path.join(input_dir, 'input', 'em_asm_mangled_string.wast'), '-o', os.devnull, '--global-base=1024' ], check=False, capture_output=True) self.assertNotEqual(p.returncode, 0) - self.assertIn('Fatal: local.get of unknown in arg0 of call to $emscripten_asm_const_int in function $main.', p.stderr) + self.assertIn('Fatal: local.get of unknown in arg0 of call to $emscripten_asm_const_int (used by EM_ASM* macros) in function $main.', p.stderr) self.assertIn('This might be caused by aggressive compiler transformations. Consider using EM_JS instead.', p.stderr)