Skip to content

Commit

Permalink
Rollup merge of #105468 - sunfishcode:sunfishcode/main-void-wasi, r=e…
Browse files Browse the repository at this point in the history
…stebank

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.
  • Loading branch information
matthiaskrgr authored Dec 9, 2022
2 parents 5156fbd + 98ae83d commit 320d018
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_target/src/spec/wasm32_wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ pub fn target() -> Target {
// `args::args()` makes the WASI API calls itself.
options.main_needs_argc_argv = false;

// And, WASI mangles the name of "main" to distinguish between different
// signatures.
options.entry_name = "__main_void".into();

Target {
llvm_target: "wasm32-wasi".into(),
pointer_width: 32,
Expand Down

0 comments on commit 320d018

Please sign in to comment.