-
-
Notifications
You must be signed in to change notification settings - Fork 708
Mangle C main on Wasm
#23303
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
Merged
Mangle C main on Wasm
#23303
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| `extern(C) main` now mangled correctly on WebAssembly | ||
|
|
||
| D now matches the mangling behavior of Clang for C `main` on Wasm targets. | ||
|
|
||
| `main` is mangled as either `__main_void` or `__main_argc_argv` as appropriate (unless overriden by `pragma(mangle)`) | ||
|
|
||
| This change is useful for both WASI and Emscripten targets, which both expect this. |
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 |
|---|---|---|
|
|
@@ -727,6 +727,23 @@ public: | |
| buf.writestring(fd.ident.toString()); | ||
| return; | ||
| } | ||
|
|
||
| version (IN_LLVM) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @ibuclaw for whatever the GCC logic should be |
||
| { | ||
| import gen.llvmhelpers : isTargetWasm; | ||
| bool isWasm = isTargetWasm(); | ||
| } | ||
| else bool isWasm = false; | ||
|
|
||
| if (fd.isCMain() && isWasm) | ||
| { | ||
| if (fd.parameters) | ||
| buf.writestring("__main_argc_argv"); | ||
| else | ||
| buf.writestring("__main_void"); | ||
| return; | ||
| } | ||
|
|
||
| visit(cast(Declaration)fd); | ||
| } | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DMD has no WASM target, so this changelog entry shouldn't be here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So even though the change was upstreamed, it shouldn't be logged?
What about #23293 and #23294?
Either way, this particular one has already been merged. Do you need me to open a PR to delete it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be logged in LDC's release notes, but the changelog in this repo gets published with dmd releases so users are aware of what changed when upgrading dmd.
Newly reserved version WASI identifiers affect dmd because
version = WASIp1is something dmd now rejects. core.stdc updates for WASM could be relevant if anyone used dmd's bundled druntime sources with LDC, but that sounds very niche so I don't think it's worth mentioning. New mangling of WASM main is irrelevant/confusing for dmd users because it is incapable of generating any WASM code. I would delete it indeed.