Skip to content
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

Implement set_output_kind for Emscripten linker #98358

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,32 @@ impl<'a> Linker for EmLinker<'a> {
&mut self.cmd
}

fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
fn set_output_kind(&mut self, output_kind: LinkOutputKind, _out_filename: &Path) {
match output_kind {
LinkOutputKind::DynamicNoPicExe | LinkOutputKind::DynamicPicExe => {
// "-sMAIN_MODULE=1" breaks
// https://github.com/rust-lang/rust/issues/92738
self.cmd.arg("-sMAIN_MODULE=2");
}
LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
// -sSIDE_MODULE=1 breaks
// https://github.com/rust-lang/rust/issues/92738
// In any case, -sSIDE_MODULE=2 is better because Rust is good at
// calculating exports.
self.cmd.arg("-sSIDE_MODULE=2");
// Without -sWASM_BIGINT there are issues with dynamic Rust libraries. There
// are no plans to fix this in Emscripten AFAIK. See
// https://github.com/emscripten-core/emscripten/pull/16693 This could also
// be fixed with panic=abort.
self.cmd.arg("-sWASM_BIGINT");
Comment on lines +1057 to +1061
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This problem is fixed now:
emscripten-core/emscripten#17328
so I should remove it.

}
// -fno-pie is the default on Emscripten.
LinkOutputKind::StaticNoPicExe | LinkOutputKind::StaticPicExe => {}
LinkOutputKind::WasiReactorExe => {
unreachable!();
}
}
}

fn include_path(&mut self, path: &Path) {
self.cmd.arg("-L").arg(path);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub fn target() -> Target {
exe_suffix: ".js".into(),
linker: None,
relocation_model: RelocModel::Pic,
crt_static_respected: true,
crt_static_default: true,
panic_strategy: PanicStrategy::Unwind,
no_default_libraries: false,
post_link_args,
Expand Down