-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Emit the emscripten entry point as __main_argc_argv
#158937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+67
−1
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //@ only-wasm32-unknown-emscripten | ||
|
|
||
| // On wasm the age-old C trick of a `main` that is either `int main(void)` or | ||
| // `int main(int, char**)` doesn't work, because wasm requires caller and callee | ||
| // signatures to match. The platform ABI (as used by Clang) therefore mangles | ||
| // the entry point by signature; the argc/argv form is emitted as | ||
| // `__main_argc_argv`. Rust's emscripten target uses the argc/argv form, so its | ||
| // entry point must be emitted under that name rather than as a raw `main`. | ||
| // | ||
| // This matters beyond cosmetics: emscripten's own crt references | ||
| // `__main_argc_argv` directly on some entry paths (notably `crt1_proxy_main.o`, | ||
| // used by `-sPROXY_TO_PTHREAD`), which fail to link against a raw `main`. | ||
| // | ||
| // The JS-visible name of the entry point stays `_main`; emscripten bridges that | ||
| // to the wasm `__main_argc_argv` export internally. | ||
|
|
||
| use run_make_support::{rfs, rustc, wasmparser}; | ||
| use wasmparser::ExternalKind; | ||
|
|
||
| fn main() { | ||
| rustc().input("main.rs").target("wasm32-unknown-emscripten").output("main.js").run(); | ||
|
|
||
| let file = rfs::read("main.wasm"); | ||
| let mut entry = None; | ||
| let mut has_plain_main = false; | ||
| for payload in wasmparser::Parser::new(0).parse_all(&file) { | ||
| if let wasmparser::Payload::ExportSection(s) = payload.unwrap() { | ||
| for export in s { | ||
| let export = export.unwrap(); | ||
| match export.name { | ||
| "__main_argc_argv" => entry = Some(export.kind), | ||
| "main" => has_plain_main = true, | ||
| _ => {} | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| assert_eq!( | ||
| entry, | ||
| Some(ExternalKind::Func), | ||
| "the emscripten entry point must be exported as the wasm C-ABI symbol `__main_argc_argv`", | ||
| ); | ||
| assert!(!has_plain_main, "a raw `main` symbol must not be exported on wasm"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.