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