Skip to content

Commit 7ee1440

Browse files
authored
wasm-emscripten-finalize: remove exportWasiStart (WebAssembly#2986)
This should not be needed since in emscripten standalone mode we always include a crt1.o that includes _start.
1 parent 109f9fe commit 7ee1440

6 files changed

Lines changed: 4 additions & 66 deletions

File tree

src/tools/wasm-emscripten-finalize.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,7 @@ int main(int argc, const char* argv[]) {
277277
}
278278
}
279279

280-
if (standaloneWasm) {
281-
// Export a standard wasi "_start" method.
282-
generator.exportWasiStart();
283-
} else {
280+
if (!standaloneWasm) {
284281
// If not standalone wasm then JS is relevant and we need dynCalls.
285282
generator.generateDynCallThunks();
286283
// This is also not needed in standalone mode since standalone mode uses

src/wasm-emscripten.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class EmscriptenGlueGenerator {
6262
// as expected by emscripten.
6363
void renameMainArgcArgv();
6464

65-
void exportWasiStart();
66-
6765
// Emits the data segments to a file. The file contains data from address base
6866
// onwards (we must pass in base, as we can't tell it from the wasm - the
6967
// first segment may start after a run of zeros, but we need those zeros in

src/wasm/wasm-emscripten.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,29 +1059,4 @@ void EmscriptenGlueGenerator::renameMainArgcArgv() {
10591059
ModuleUtils::renameFunction(wasm, "__main_argc_argv", "main");
10601060
}
10611061

1062-
void EmscriptenGlueGenerator::exportWasiStart() {
1063-
// If main exists, export a function to call it per the wasi standard.
1064-
Name main = "main";
1065-
if (!wasm.getFunctionOrNull(main)) {
1066-
BYN_TRACE("exportWasiStart: main not found\n");
1067-
return;
1068-
}
1069-
Name _start = "_start";
1070-
if (wasm.getExportOrNull(_start)) {
1071-
BYN_TRACE("exportWasiStart: _start already present\n");
1072-
return;
1073-
}
1074-
BYN_TRACE("exportWasiStart\n");
1075-
Builder builder(wasm);
1076-
auto* body =
1077-
builder.makeDrop(builder.makeCall(main,
1078-
{LiteralUtils::makeZero(Type::i32, wasm),
1079-
LiteralUtils::makeZero(Type::i32, wasm)},
1080-
Type::i32));
1081-
auto* func =
1082-
builder.makeFunction(_start, Signature(Type::none, Type::none), {}, body);
1083-
wasm.addFunction(func);
1084-
wasm.addExport(builder.makeExport(_start, _start, ExternalKind::Function));
1085-
}
1086-
10871062
} // namespace wasm

test/lld/safe_stack_standalone-wasm.wat.out

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
(export "main" (func $main))
2020
(export "__set_stack_limit" (func $__set_stack_limit))
2121
(export "__growWasmMemory" (func $__growWasmMemory))
22-
(export "_start" (func $_start))
2322
(func $__wasm_call_ctors
2423
(nop)
2524
)
@@ -150,14 +149,6 @@
150149
(local.get $newSize)
151150
)
152151
)
153-
(func $_start
154-
(drop
155-
(call $main
156-
(i32.const 0)
157-
(i32.const 0)
158-
)
159-
)
160-
)
161152
)
162153
(;
163154
--BEGIN METADATA --
@@ -176,8 +167,7 @@
176167
"__wasm_call_ctors",
177168
"main",
178169
"__set_stack_limit",
179-
"__growWasmMemory",
180-
"_start"
170+
"__growWasmMemory"
181171
],
182172
"namedGlobals": {
183173
"__heap_base" : "66128",

test/lld/standalone-wasm.wat.out

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(module
22
(type $none_=>_i32 (func (result i32)))
3-
(type $none_=>_none (func))
43
(type $i32_=>_i32 (func (param i32) (result i32)))
54
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
65
(memory $0 2)
@@ -14,7 +13,6 @@
1413
(export "__heap_base" (global $global$1))
1514
(export "__data_end" (global $global$2))
1615
(export "__growWasmMemory" (func $__growWasmMemory))
17-
(export "_start" (func $_start))
1816
(func $__original_main (result i32)
1917
(nop)
2018
)
@@ -29,14 +27,6 @@
2927
(local.get $newSize)
3028
)
3129
)
32-
(func $_start
33-
(drop
34-
(call $main
35-
(i32.const 0)
36-
(i32.const 0)
37-
)
38-
)
39-
)
4030
)
4131
(;
4232
--BEGIN METADATA --
@@ -49,8 +39,7 @@
4939
],
5040
"exports": [
5141
"main",
52-
"__growWasmMemory",
53-
"_start"
42+
"__growWasmMemory"
5443
],
5544
"namedGlobals": {
5645
"__heap_base" : "66112",

test/lld/standalone-wasm2.wat.out

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(module
22
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
3-
(type $none_=>_none (func))
43
(type $i32_=>_i32 (func (param i32) (result i32)))
54
(memory $0 2)
65
(global $global$0 (mut i32) (i32.const 66112))
@@ -11,7 +10,6 @@
1110
(export "__heap_base" (global $global$1))
1211
(export "__data_end" (global $global$2))
1312
(export "__growWasmMemory" (func $__growWasmMemory))
14-
(export "_start" (func $_start))
1513
(func $__original_main (param $0 i32) (param $1 i32) (result i32)
1614
(nop)
1715
)
@@ -26,14 +24,6 @@
2624
(local.get $newSize)
2725
)
2826
)
29-
(func $_start
30-
(drop
31-
(call $main
32-
(i32.const 0)
33-
(i32.const 0)
34-
)
35-
)
36-
)
3727
)
3828
(;
3929
--BEGIN METADATA --
@@ -46,8 +36,7 @@
4636
],
4737
"exports": [
4838
"main",
49-
"__growWasmMemory",
50-
"_start"
39+
"__growWasmMemory"
5140
],
5241
"namedGlobals": {
5342
"__heap_base" : "66112",

0 commit comments

Comments
 (0)