diff options
author | Sam Clegg <sbc@chromium.org> | 2020-06-11 11:52:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-11 11:52:28 -0700 |
commit | 353c73a09393d42d30ab046f3f3373a272113d26 (patch) | |
tree | 06b80d1e9bde6020c18aa0740f4ccdae2eaf762d | |
parent | b9feef2861b6f7286c6a8bf1a89c1699b2fcae01 (diff) | |
download | binaryen-353c73a09393d42d30ab046f3f3373a272113d26.tar.gz binaryen-353c73a09393d42d30ab046f3f3373a272113d26.tar.bz2 binaryen-353c73a09393d42d30ab046f3f3373a272113d26.zip |
Default mainReadsParams to true in standalone mode (#2906)
The process of DCE'ing the argument handling is already handled in
a different way in standalone more. In standalone mode the entry
point is `_start` which takes no args, and argv code is included
on-demand via the presence or absence the wasi syscalls for argument
processing (__wasi_args_get/__wasi_args_sizes_get).
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 36 | ||||
-rw-r--r-- | test/lld/safe_stack_standalone-wasm.wat.out | 1 | ||||
-rw-r--r-- | test/lld/standalone-wasm-with-start.wat.out | 1 | ||||
-rw-r--r-- | test/lld/standalone-wasm.wat.out | 1 | ||||
-rw-r--r-- | test/lld/standalone-wasm2.wat.out | 1 | ||||
-rw-r--r-- | test/lld/standalone-wasm3.wat.out | 1 |
6 files changed, 21 insertions, 20 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index c2cace488..a57573254 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -1224,25 +1224,31 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( }); meta << "\n ],\n"; - auto mainReadsParams = false; - auto* exp = wasm.getExportOrNull("main"); - if (!exp) { - exp = wasm.getExportOrNull("__main_argc_argv"); - } - if (exp) { - if (exp->kind == ExternalKind::Function) { - auto* main = wasm.getFunction(exp->value); - mainReadsParams = true; - // If main does not read its parameters, it will just be a stub that - // calls __original_main (which has no parameters). - if (auto* call = main->body->dynCast<Call>()) { - if (call->operands.empty()) { - mainReadsParams = false; + // In normal mode we attempt to determine if main takes argumnts or not + // In standalone mode we export _start instead and rely on the presence + // of the __wasi_args_get and __wasi_args_sizes_get syscalls allow us to + // DCE to the argument handling JS code instead. + if (!standalone) { + auto mainReadsParams = false; + auto* exp = wasm.getExportOrNull("main"); + if (!exp) { + exp = wasm.getExportOrNull("__main_argc_argv"); + } + if (exp) { + if (exp->kind == ExternalKind::Function) { + auto* main = wasm.getFunction(exp->value); + mainReadsParams = true; + // If main does not read its parameters, it will just be a stub that + // calls __original_main (which has no parameters). + if (auto* call = main->body->dynCast<Call>()) { + if (call->operands.empty()) { + mainReadsParams = false; + } } } } + meta << " \"mainReadsParams\": " << int(mainReadsParams) << '\n'; } - meta << " \"mainReadsParams\": " << int(mainReadsParams) << '\n'; meta << "}\n"; diff --git a/test/lld/safe_stack_standalone-wasm.wat.out b/test/lld/safe_stack_standalone-wasm.wat.out index e39b076ff..81f62a0dd 100644 --- a/test/lld/safe_stack_standalone-wasm.wat.out +++ b/test/lld/safe_stack_standalone-wasm.wat.out @@ -187,7 +187,6 @@ ], "features": [ ], - "mainReadsParams": 0 } -- END METADATA -- ;) diff --git a/test/lld/standalone-wasm-with-start.wat.out b/test/lld/standalone-wasm-with-start.wat.out index 4e2d8cbc4..367a26168 100644 --- a/test/lld/standalone-wasm-with-start.wat.out +++ b/test/lld/standalone-wasm-with-start.wat.out @@ -45,7 +45,6 @@ ], "features": [ ], - "mainReadsParams": 0 } -- END METADATA -- ;) diff --git a/test/lld/standalone-wasm.wat.out b/test/lld/standalone-wasm.wat.out index 179878979..3a483bdf7 100644 --- a/test/lld/standalone-wasm.wat.out +++ b/test/lld/standalone-wasm.wat.out @@ -60,7 +60,6 @@ ], "features": [ ], - "mainReadsParams": 0 } -- END METADATA -- ;) diff --git a/test/lld/standalone-wasm2.wat.out b/test/lld/standalone-wasm2.wat.out index 5d2198d8d..d6a0c5505 100644 --- a/test/lld/standalone-wasm2.wat.out +++ b/test/lld/standalone-wasm2.wat.out @@ -57,7 +57,6 @@ ], "features": [ ], - "mainReadsParams": 1 } -- END METADATA -- ;) diff --git a/test/lld/standalone-wasm3.wat.out b/test/lld/standalone-wasm3.wat.out index 3634ca46e..65557a790 100644 --- a/test/lld/standalone-wasm3.wat.out +++ b/test/lld/standalone-wasm3.wat.out @@ -38,7 +38,6 @@ ], "features": [ ], - "mainReadsParams": 0 } -- END METADATA -- ;) |