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

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