summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-10-06 11:30:27 -0700
committerGitHub <noreply@github.com>2022-10-06 18:30:27 +0000
commite8884de3c880a7de4bb1f8eae3df5f00f4164b4d (patch)
treefc5ab515e8e969c20b64dc9b4df54645fd4a7e4d
parente6be381b6f5adbd07af080a4e1f74ba04c8eda82 (diff)
downloadbinaryen-e8884de3c880a7de4bb1f8eae3df5f00f4164b4d.tar.gz
binaryen-e8884de3c880a7de4bb1f8eae3df5f00f4164b4d.tar.bz2
binaryen-e8884de3c880a7de4bb1f8eae3df5f00f4164b4d.zip
Warn on too many parameters for Web VMs (#5119)
Fixes emscripten-core/emscripten#17988
-rw-r--r--src/wasm-binary.h3
-rw-r--r--src/wasm/wasm-binary.cpp5
-rw-r--r--test/unit/test_web_limitations.py22
3 files changed, 29 insertions, 1 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index b308abade..e9ad665c4 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -48,7 +48,8 @@ enum {
enum WebLimitations : uint32_t {
MaxDataSegments = 100 * 1000,
MaxFunctionBodySize = 128 * 1024,
- MaxFunctionLocals = 50 * 1000
+ MaxFunctionLocals = 50 * 1000,
+ MaxFunctionParams = 1000
};
template<typename T, typename MiniT> struct LEB {
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 4e5db69b1..55dafadd4 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -453,6 +453,11 @@ void WasmBinaryWriter::writeFunctions() {
tableOfContents.functionBodies.emplace_back(
func->name, sizePos + sizeFieldSize, size);
binaryLocationTrackedExpressionsForFunc.clear();
+
+ if (func->getParams().size() > WebLimitations::MaxFunctionParams) {
+ std::cerr << "Some VMs may not accept this binary because it has a large "
+ << "number of parameters in function " << func->name << ".\n";
+ }
});
finishSection(sectionStart);
}
diff --git a/test/unit/test_web_limitations.py b/test/unit/test_web_limitations.py
new file mode 100644
index 000000000..6359390f9
--- /dev/null
+++ b/test/unit/test_web_limitations.py
@@ -0,0 +1,22 @@
+import os
+
+from scripts.test import shared
+from . import utils
+
+
+class WebLimitations(utils.BinaryenTestCase):
+ def test_many_params(self):
+ """Test that we warn on large numbers of parameters, which Web VMs
+ disallow."""
+
+ params = '(param i32) ' * 1001
+ module = '''
+ (module
+ (func $foo %s
+ )
+ )
+ ''' % params
+ p = shared.run_process(shared.WASM_OPT + ['-o', os.devnull],
+ input=module, capture_output=True)
+ self.assertIn('Some VMs may not accept this binary because it has a large number of parameters in function foo.',
+ p.stderr)