Skip to content

Commit 49cd748

Browse files
authored
Rollup merge of rust-lang#39193 - pepyakin:emcc-strip-panic-rt, r=alexcrichton
Tell emscripten to remove exception handling code when panic=abort Fixes rust-lang#36900
2 parents 8163b4b + 24cb5b7 commit 49cd748

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/librustc_back/target/asmjs_unknown_emscripten.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn target() -> Result<Target, String> {
2222
linker_is_gnu: true,
2323
allow_asm: false,
2424
obj_is_bitcode: true,
25+
is_like_emscripten: true,
2526
max_atomic_width: Some(32),
2627
post_link_args: vec!["-s".to_string(), "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()],
2728
target_family: Some("unix".to_string()),

src/librustc_back/target/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ pub struct TargetOptions {
330330
/// Whether the target toolchain is like Android's. Only useful for compiling against Android.
331331
/// Defaults to false.
332332
pub is_like_android: bool,
333+
/// Whether the target toolchain is like Emscripten's. Only useful for compiling with
334+
/// Emscripten toolchain.
335+
/// Defaults to false.
336+
pub is_like_emscripten: bool,
333337
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
334338
pub linker_is_gnu: bool,
335339
/// The MinGW toolchain has a known issue that prevents it from correctly
@@ -428,6 +432,7 @@ impl Default for TargetOptions {
428432
is_like_solaris: false,
429433
is_like_windows: false,
430434
is_like_android: false,
435+
is_like_emscripten: false,
431436
is_like_msvc: false,
432437
linker_is_gnu: false,
433438
allows_weak_linkage: true,
@@ -603,6 +608,7 @@ impl Target {
603608
key!(is_like_solaris, bool);
604609
key!(is_like_windows, bool);
605610
key!(is_like_msvc, bool);
611+
key!(is_like_emscripten, bool);
606612
key!(is_like_android, bool);
607613
key!(linker_is_gnu, bool);
608614
key!(allows_weak_linkage, bool);
@@ -767,6 +773,7 @@ impl ToJson for Target {
767773
target_option_val!(is_like_solaris);
768774
target_option_val!(is_like_windows);
769775
target_option_val!(is_like_msvc);
776+
target_option_val!(is_like_emscripten);
770777
target_option_val!(is_like_android);
771778
target_option_val!(linker_is_gnu);
772779
target_option_val!(allows_weak_linkage);

src/librustc_back/target/wasm32_unknown_emscripten.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn target() -> Result<Target, String> {
2424
linker_is_gnu: true,
2525
allow_asm: false,
2626
obj_is_bitcode: true,
27+
is_like_emscripten: true,
2728
max_atomic_width: Some(32),
2829
post_link_args: vec!["-s".to_string(), "BINARYEN=1".to_string(),
2930
"-s".to_string(), "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()],

src/librustc_trans/back/link.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc::dep_graph::DepNode;
2929
use rustc::hir::def_id::CrateNum;
3030
use rustc::hir::svh::Svh;
3131
use rustc_back::tempdir::TempDir;
32+
use rustc_back::PanicStrategy;
3233
use rustc_incremental::IncrementalHashesMap;
3334

3435
use std::ascii;
@@ -714,6 +715,11 @@ fn link_natively(sess: &Session,
714715
cmd.arg(root.join(obj));
715716
}
716717

718+
if sess.target.target.options.is_like_emscripten &&
719+
sess.panic_strategy() == PanicStrategy::Abort {
720+
cmd.args(&["-s", "DISABLE_EXCEPTION_CATCHING=1"]);
721+
}
722+
717723
{
718724
let mut linker = trans.linker_info.to_linker(&mut cmd, &sess);
719725
link_args(&mut *linker, sess, crate_type, tmpdir,

0 commit comments

Comments
 (0)