Skip to content

Commit 98ae83d

Browse files
committed
Mangle "main" as "__main_void" on wasm32-wasi
On wasm, the age-old C trick of having a main function which can either have no arguments or argc+argv doesn't work, because wasm requires caller and callee signatures to match. WASI's current strategy is to have compilers mangle main's name to indicate which signature they're using. Rust uses the no-argument form, which should be mangled as `__main_void`. This is needed on wasm32-wasi as of #105395.
1 parent 7632db0 commit 98ae83d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compiler/rustc_target/src/spec/wasm32_wasi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ pub fn target() -> Target {
104104
// `args::args()` makes the WASI API calls itself.
105105
options.main_needs_argc_argv = false;
106106

107+
// And, WASI mangles the name of "main" to distinguish between different
108+
// signatures.
109+
options.entry_name = "__main_void".into();
110+
107111
Target {
108112
llvm_target: "wasm32-wasi".into(),
109113
pointer_width: 32,

0 commit comments

Comments
 (0)