summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-09-27 14:27:27 -0700
committerGitHub <noreply@github.com>2019-09-27 14:27:27 -0700
commit3bba1955745ce0aae8e76c5e88dd46ab5b6612d6 (patch)
tree956e262d42c0a2e4540cbd56a0b0ef4b69b60f9e
parent6459efffec8282b53b135edcbaeb2da8964a822b (diff)
downloadbinaryen-3bba1955745ce0aae8e76c5e88dd46ab5b6612d6.tar.gz
binaryen-3bba1955745ce0aae8e76c5e88dd46ab5b6612d6.tar.bz2
binaryen-3bba1955745ce0aae8e76c5e88dd46ab5b6612d6.zip
Only create `_start` if it doesn't already exist (#2363)
-rw-r--r--src/wasm/wasm-emscripten.cpp3
-rw-r--r--test/lld/standalone-wasm-with-start.wast17
-rw-r--r--test/lld/standalone-wasm-with-start.wast.out86
3 files changed, 106 insertions, 0 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 3aa6f5647..9b579fa25 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -1218,6 +1218,9 @@ void EmscriptenGlueGenerator::exportWasiStart() {
return;
}
Name _start = "_start";
+ if (wasm.getExportOrNull(_start)) {
+ return;
+ }
Builder builder(wasm);
auto* body = builder.makeDrop(builder.makeCall(
main,
diff --git a/test/lld/standalone-wasm-with-start.wast b/test/lld/standalone-wasm-with-start.wast
new file mode 100644
index 000000000..8767c8efb
--- /dev/null
+++ b/test/lld/standalone-wasm-with-start.wast
@@ -0,0 +1,17 @@
+(module
+ (memory $0 2)
+ (table $0 1 1 funcref)
+ (elem (i32.const 0) $foo)
+ (global $global$0 (mut i32) (i32.const 66112))
+ (global $global$1 i32 (i32.const 66112))
+ (global $global$2 i32 (i32.const 576))
+ (export "memory" (memory $0))
+ (export "_start" (func $_start))
+ (export "__heap_base" (global $global$1))
+ (export "__data_end" (global $global$2))
+ (func $_start (result i32)
+ (nop)
+ )
+ (func $foo (result i32))
+)
+
diff --git a/test/lld/standalone-wasm-with-start.wast.out b/test/lld/standalone-wasm-with-start.wast.out
new file mode 100644
index 000000000..424d2f85e
--- /dev/null
+++ b/test/lld/standalone-wasm-with-start.wast.out
@@ -0,0 +1,86 @@
+(module
+ (type $FUNCSIG$i (func (result i32)))
+ (memory $0 2)
+ (table $0 1 1 funcref)
+ (elem (i32.const 0) $foo)
+ (global $global$0 (mut i32) (i32.const 66112))
+ (global $global$1 i32 (i32.const 66112))
+ (global $global$2 i32 (i32.const 576))
+ (export "memory" (memory $0))
+ (export "_start" (func $_start))
+ (export "__heap_base" (global $global$1))
+ (export "__data_end" (global $global$2))
+ (export "stackSave" (func $stackSave))
+ (export "stackAlloc" (func $stackAlloc))
+ (export "stackRestore" (func $stackRestore))
+ (export "__growWasmMemory" (func $__growWasmMemory))
+ (func $_start (; 0 ;) (type $FUNCSIG$i) (result i32)
+ (nop)
+ )
+ (func $foo (; 1 ;) (type $FUNCSIG$i) (result i32)
+ (nop)
+ )
+ (func $stackSave (; 2 ;) (result i32)
+ (global.get $global$0)
+ )
+ (func $stackAlloc (; 3 ;) (param $0 i32) (result i32)
+ (local $1 i32)
+ (global.set $global$0
+ (local.tee $1
+ (i32.and
+ (i32.sub
+ (global.get $global$0)
+ (local.get $0)
+ )
+ (i32.const -16)
+ )
+ )
+ )
+ (local.get $1)
+ )
+ (func $stackRestore (; 4 ;) (param $0 i32)
+ (global.set $global$0
+ (local.get $0)
+ )
+ )
+ (func $__growWasmMemory (; 5 ;) (param $newSize i32) (result i32)
+ (memory.grow
+ (local.get $newSize)
+ )
+ )
+)
+(;
+--BEGIN METADATA --
+{
+ "staticBump": 8,
+ "tableSize": 1,
+ "declares": [
+ ],
+ "externs": [
+ ],
+ "implementedFunctions": [
+ "__start",
+ "_stackSave",
+ "_stackAlloc",
+ "_stackRestore",
+ "___growWasmMemory"
+ ],
+ "exports": [
+ "_start",
+ "stackSave",
+ "stackAlloc",
+ "stackRestore",
+ "__growWasmMemory"
+ ],
+ "namedGlobals": {
+ "__heap_base" : "66112",
+ "__data_end" : "576"
+ },
+ "invokeFuncs": [
+ ],
+ "features": [
+ ],
+ "mainReadsParams": 0
+}
+-- END METADATA --
+;)