Skip to content

Commit 9da4fea

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

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,38 @@ 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+
warn!(
1051+
"Building dynamic executable with -sMAIN_MODULE=2. \
1052+
Dead code elimination may break things. \
1053+
See https://emscripten.org/docs/compiling/Dynamic-Linking.html?highlight=main_module#code-size \
1054+
"
1055+
);
1056+
}
1057+
LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
1058+
// -sSIDE_MODULE=1 breaks
1059+
// https://github.com/rust-lang/rust/issues/92738
1060+
// In any case, -sSIDE_MODULE=2 is better because Rust is good at
1061+
// calculating exports.
1062+
self.cmd.arg("-sSIDE_MODULE=2");
1063+
// Without -sWASM_BIGINT there are issues with dynamic Rust libraries. There
1064+
// are no plans to fix this in Emscripten AFAIK. See
1065+
// https://github.com/emscripten-core/emscripten/pull/16693 This could also
1066+
// be fixed with panic=abort.
1067+
self.cmd.arg("-sWASM_BIGINT");
1068+
}
1069+
// -fno-pie is the default on Emscripten.
1070+
LinkOutputKind::StaticNoPicExe | LinkOutputKind::StaticPicExe => {}
1071+
LinkOutputKind::WasiReactorExe => {
1072+
unreachable!();
1073+
}
1074+
}
1075+
}
10451076

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

0 commit comments

Comments
 (0)