Skip to content

Pass --no-entry to emcc when linking emscripten cdylib/dylib#157985

Closed
guybedford wants to merge 1 commit into
rust-lang:mainfrom
guybedford:emscripten-cdylib-no-entry
Closed

Pass --no-entry to emcc when linking emscripten cdylib/dylib#157985
guybedford wants to merge 1 commit into
rust-lang:mainfrom
guybedford:emscripten-cdylib-no-entry

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

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.

Extends the emscripten cdylib run-make test to also link a bin crate with main, guarding against regressing the executable entry path.

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.
@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

r? @camelid

rustbot has assigned @camelid.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 21 candidates


// 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();

@bjorn3 bjorn3 Jun 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review


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();

@bjorn3 bjorn3 Jun 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this work before?
Edit: I think -sSIDE_MODULE=2 already implies --no-entry.

View changes since the review

@hoodmane

Copy link
Copy Markdown
Contributor

This doesn't look right to me. As @bjorn3 says, -sSIDE_MODULE=2 implies --no-entry.

@camelid

camelid commented Jun 17, 2026

Copy link
Copy Markdown
Member

@guybedford do you have an example of a situation in which you get this linker error?

@guybedford

Copy link
Copy Markdown
Contributor Author

Ahh, I see the root cause here was actually fixed in 1.95.0 by @hoodmane in #151704 and I'm just stuck on an old toolchain.

Closing as already resolved.

@guybedford guybedford closed this Jun 17, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2026
@guybedford guybedford deleted the emscripten-cdylib-no-entry branch June 17, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants