Pass --no-entry to emcc when linking emscripten cdylib/dylib#157985
Closed
guybedford wants to merge 1 commit into
Closed
Pass --no-entry to emcc when linking emscripten cdylib/dylib#157985guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
A cdylib/dylib has no `main`, but rustc invokes emcc in its default executable mode, which links in emscripten's standalone-wasm entry shim and then fails with `undefined symbol: main`. Mirror the WasmLd linker: emit `--no-entry` for `DynamicDylib`/ `StaticDylib` output kinds in EmLinker::set_output_kind, conditioned on LinkOutputKind so executables keep their entry. Extend the emscripten cdylib run-make test to also link a bin crate with `main`, guarding against regressing the executable entry path.
Collaborator
|
r? @camelid rustbot has assigned @camelid. Use Why was this reviewer chosen?The reviewer was selected based on:
|
bjorn3
reviewed
Jun 17, 2026
|
|
||
| // An executable has a `main`, so `--no-entry` must NOT be applied: it must | ||
| // still link with its entry preserved. | ||
| bare_rustc().input("main.rs").target("wasm32-unknown-emscripten").crate_type("bin").run(); |
Member
There was a problem hiding this comment.
If --no-entry is passed here, the test would still pass. I think --no-entry not being passed would already be covered by all run-pass tests that run on emscripten anyway.
bjorn3
reviewed
Jun 17, 2026
|
|
||
| fn main() { | ||
| // A cdylib must link without `--no-entry` being supplied by the user. | ||
| bare_rustc().input("foo.rs").target("wasm32-unknown-emscripten").crate_type("cdylib").run(); |
Member
There was a problem hiding this comment.
Why did this work before?
Edit: I think -sSIDE_MODULE=2 already implies --no-entry.
Contributor
|
This doesn't look right to me. As @bjorn3 says, |
Member
|
@guybedford do you have an example of a situation in which you get this linker error? |
Contributor
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A cdylib/dylib has no
main, but rustc invokes emcc in its default executable mode, which links in emscripten's standalone-wasm entry shim and then fails withundefined symbol: main.Mirror the WasmLd linker: emit
--no-entryforDynamicDylib/StaticDyliboutput kinds in EmLinker::set_output_kind, conditioned on LinkOutputKind so executables keep their entry.Extends the emscripten cdylib run-make test to also link a bin crate with
main, guarding against regressing the executable entry path.