Skip to content

Commit bb977cf

Browse files
committed
Implement set_output_kind for emscripten linker
1 parent 8aab472 commit bb977cf

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,32 @@ impl<'a> Linker for EmLinker<'a> {
10411041
&mut self.cmd
10421042
}
10431043

1044-
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
1044+
fn set_output_kind(&mut self, output_kind: LinkOutputKind, _out_filename: &Path) {
1045+
match output_kind {
1046+
LinkOutputKind::DynamicNoPicExe | LinkOutputKind::DynamicPicExe => {
1047+
// "-sMAIN_MODULE=1" breaks
1048+
// https://github.com/rust-lang/rust/issues/92738
1049+
self.cmd.arg("-sMAIN_MODULE=2");
1050+
}
1051+
LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
1052+
// -sSIDE_MODULE=1 breaks
1053+
// https://github.com/rust-lang/rust/issues/92738
1054+
// In any case, -sSIDE_MODULE=2 is better because Rust is good at
1055+
// calculating exports.
1056+
self.cmd.arg("-sSIDE_MODULE=2");
1057+
// Without -sWASM_BIGINT there are issues with dynamic Rust libraries. There
1058+
// are no plans to fix this in Emscripten AFAIK. See
1059+
// https://github.com/emscripten-core/emscripten/pull/16693 This could also
1060+
// be fixed with panic=abort.
1061+
self.cmd.arg("-sWASM_BIGINT");
1062+
}
1063+
// -fno-pie is the default on Emscripten.
1064+
LinkOutputKind::StaticNoPicExe | LinkOutputKind::StaticPicExe => {}
1065+
LinkOutputKind::WasiReactorExe => {
1066+
unreachable!();
1067+
}
1068+
}
1069+
}
10451070

10461071
fn include_path(&mut self, path: &Path) {
10471072
self.cmd.arg("-L").arg(path);

0 commit comments

Comments
 (0)