Blame SOURCES/0001-Mangle-main-as-__main_void-on-wasm32-wasi.patch

235ca3
From 98ae83daae67e9e7663b8345eced1de8c667271f Mon Sep 17 00:00:00 2001
235ca3
From: Dan Gohman <dev@sunfishcode.online>
235ca3
Date: Thu, 8 Dec 2022 10:35:46 -0800
235ca3
Subject: [PATCH] Mangle "main" as "__main_void" on wasm32-wasi
235ca3
235ca3
On wasm, the age-old C trick of having a main function which can either have
235ca3
no arguments or argc+argv doesn't work, because wasm requires caller and
235ca3
callee signatures to match. WASI's current strategy is to have compilers
235ca3
mangle main's name to indicate which signature they're using. Rust uses the
235ca3
no-argument form, which should be mangled as `__main_void`.
235ca3
235ca3
This is needed on wasm32-wasi as of #105395.
235ca3
---
235ca3
 compiler/rustc_target/src/spec/wasm32_wasi.rs | 4 ++++
235ca3
 1 file changed, 4 insertions(+)
235ca3
235ca3
diff --git a/compiler/rustc_target/src/spec/wasm32_wasi.rs b/compiler/rustc_target/src/spec/wasm32_wasi.rs
235ca3
index 6f0bbf0672d4..a0476d542e64 100644
235ca3
--- a/compiler/rustc_target/src/spec/wasm32_wasi.rs
235ca3
+++ b/compiler/rustc_target/src/spec/wasm32_wasi.rs
235ca3
@@ -104,6 +104,10 @@ pub fn target() -> Target {
235ca3
     // `args::args()` makes the WASI API calls itself.
235ca3
     options.main_needs_argc_argv = false;
235ca3
 
235ca3
+    // And, WASI mangles the name of "main" to distinguish between different
235ca3
+    // signatures.
235ca3
+    options.entry_name = "__main_void".into();
235ca3
+
235ca3
     Target {
235ca3
         llvm_target: "wasm32-wasi".into(),
235ca3
         pointer_width: 32,
235ca3
-- 
235ca3
2.38.1
235ca3