Skip to content

Commit 3bba195

Browse files
authored
Only create _start if it doesn't already exist (#2363)
1 parent 6459eff commit 3bba195

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/wasm/wasm-emscripten.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,9 @@ void EmscriptenGlueGenerator::exportWasiStart() {
12181218
return;
12191219
}
12201220
Name _start = "_start";
1221+
if (wasm.getExportOrNull(_start)) {
1222+
return;
1223+
}
12211224
Builder builder(wasm);
12221225
auto* body = builder.makeDrop(builder.makeCall(
12231226
main,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(module
2+
(memory $0 2)
3+
(table $0 1 1 funcref)
4+
(elem (i32.const 0) $foo)
5+
(global $global$0 (mut i32) (i32.const 66112))
6+
(global $global$1 i32 (i32.const 66112))
7+
(global $global$2 i32 (i32.const 576))
8+
(export "memory" (memory $0))
9+
(export "_start" (func $_start))
10+
(export "__heap_base" (global $global$1))
11+
(export "__data_end" (global $global$2))
12+
(func $_start (result i32)
13+
(nop)
14+
)
15+
(func $foo (result i32))
16+
)
17+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
(module
2+
(type $FUNCSIG$i (func (result i32)))
3+
(memory $0 2)
4+
(table $0 1 1 funcref)
5+
(elem (i32.const 0) $foo)
6+
(global $global$0 (mut i32) (i32.const 66112))
7+
(global $global$1 i32 (i32.const 66112))
8+
(global $global$2 i32 (i32.const 576))
9+
(export "memory" (memory $0))
10+
(export "_start" (func $_start))
11+
(export "__heap_base" (global $global$1))
12+
(export "__data_end" (global $global$2))
13+
(export "stackSave" (func $stackSave))
14+
(export "stackAlloc" (func $stackAlloc))
15+
(export "stackRestore" (func $stackRestore))
16+
(export "__growWasmMemory" (func $__growWasmMemory))
17+
(func $_start (; 0 ;) (type $FUNCSIG$i) (result i32)
18+
(nop)
19+
)
20+
(func $foo (; 1 ;) (type $FUNCSIG$i) (result i32)
21+
(nop)
22+
)
23+
(func $stackSave (; 2 ;) (result i32)
24+
(global.get $global$0)
25+
)
26+
(func $stackAlloc (; 3 ;) (param $0 i32) (result i32)
27+
(local $1 i32)
28+
(global.set $global$0
29+
(local.tee $1
30+
(i32.and
31+
(i32.sub
32+
(global.get $global$0)
33+
(local.get $0)
34+
)
35+
(i32.const -16)
36+
)
37+
)
38+
)
39+
(local.get $1)
40+
)
41+
(func $stackRestore (; 4 ;) (param $0 i32)
42+
(global.set $global$0
43+
(local.get $0)
44+
)
45+
)
46+
(func $__growWasmMemory (; 5 ;) (param $newSize i32) (result i32)
47+
(memory.grow
48+
(local.get $newSize)
49+
)
50+
)
51+
)
52+
(;
53+
--BEGIN METADATA --
54+
{
55+
"staticBump": 8,
56+
"tableSize": 1,
57+
"declares": [
58+
],
59+
"externs": [
60+
],
61+
"implementedFunctions": [
62+
"__start",
63+
"_stackSave",
64+
"_stackAlloc",
65+
"_stackRestore",
66+
"___growWasmMemory"
67+
],
68+
"exports": [
69+
"_start",
70+
"stackSave",
71+
"stackAlloc",
72+
"stackRestore",
73+
"__growWasmMemory"
74+
],
75+
"namedGlobals": {
76+
"__heap_base" : "66112",
77+
"__data_end" : "576"
78+
},
79+
"invokeFuncs": [
80+
],
81+
"features": [
82+
],
83+
"mainReadsParams": 0
84+
}
85+
-- END METADATA --
86+
;)

0 commit comments

Comments
 (0)