@@ -1041,7 +1041,38 @@ impl<'a> Linker for EmLinker<'a> {
1041
1041
& mut self . cmd
1042
1042
}
1043
1043
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
+ }
1045
1076
1046
1077
fn include_path ( & mut self , path : & Path ) {
1047
1078
self . cmd . arg ( "-L" ) . arg ( path) ;
0 commit comments