Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6a7bc3f

Browse files
authored
Unrolled build for rust-lang#131830
Rollup merge of rust-lang#131830 - hoodmane:emscripten-wasm-eh, r=workingjubilee Add support for wasm exception handling to Emscripten target This is a draft because we need some additional setting for the Emscripten target to select between the old exception handling and the new exception handling. I don't know how to add a setting like that, would appreciate advice from Rust folks. We could maybe choose to use the new exception handling if `Ctarget-feature=+exception-handling` is passed? I tried this but I get errors from llvm so I'm not doing it right.
2 parents 0f1e965 + 49c7423 commit 6a7bc3f

File tree

21 files changed

+131
-10
lines changed

21 files changed

+131
-10
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ unsafe fn configure_llvm(sess: &Session) {
109109
add("-wasm-enable-eh", false);
110110
}
111111

112-
if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
112+
if sess.target.os == "emscripten"
113+
&& !sess.opts.unstable_opts.emscripten_wasm_eh
114+
&& sess.panic_strategy() == PanicStrategy::Unwind
115+
{
113116
add("-enable-emscripten-cxx-exceptions", false);
114117
}
115118

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,10 +2451,12 @@ fn add_order_independent_options(
24512451
}
24522452

24532453
if sess.target.os == "emscripten" {
2454-
cmd.cc_arg("-s").cc_arg(if sess.panic_strategy() == PanicStrategy::Abort {
2455-
"DISABLE_EXCEPTION_CATCHING=1"
2454+
cmd.cc_arg(if sess.panic_strategy() == PanicStrategy::Abort {
2455+
"-sDISABLE_EXCEPTION_CATCHING=1"
2456+
} else if sess.opts.unstable_opts.emscripten_wasm_eh {
2457+
"-fwasm-exceptions"
24562458
} else {
2457-
"DISABLE_EXCEPTION_CATCHING=0"
2459+
"-sDISABLE_EXCEPTION_CATCHING=0"
24582460
});
24592461
}
24602462

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ pub(crate) fn build_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
388388
// exceptions. This means that the VM does the unwinding for
389389
// us
390390
pub fn wants_wasm_eh(sess: &Session) -> bool {
391-
sess.target.is_like_wasm && sess.target.os != "emscripten"
391+
sess.target.is_like_wasm
392+
&& (sess.target.os != "emscripten" || sess.opts.unstable_opts.emscripten_wasm_eh)
392393
}
393394

394395
/// Returns `true` if this session's target will use SEH-based unwinding.

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const GATED_CFGS: &[GatedCfg] = &[
3737
(sym::sanitizer_cfi_normalize_integers, sym::cfg_sanitizer_cfi, Features::cfg_sanitizer_cfi),
3838
// this is consistent with naming of the compiler flag it's for
3939
(sym::fmt_debug, sym::fmt_debug, Features::fmt_debug),
40+
(sym::emscripten_wasm_eh, sym::cfg_emscripten_wasm_eh, Features::cfg_emscripten_wasm_eh),
4041
];
4142

4243
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ declare_features! (
202202
(internal, allow_internal_unstable, "1.0.0", None),
203203
/// Allows using anonymous lifetimes in argument-position impl-trait.
204204
(unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None),
205+
/// Allows access to the emscripten_wasm_eh config, used by panic_unwind and unwind
206+
(internal, cfg_emscripten_wasm_eh, "CURRENT_RUSTC_VERSION", None),
205207
/// Allows identifying the `compiler_builtins` crate.
206208
(internal, compiler_builtins, "1.13.0", None),
207209
/// Allows writing custom MIR

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ fn test_unstable_options_tracking_hash() {
782782
tracked!(dwarf_version, Some(5));
783783
tracked!(embed_source, true);
784784
tracked!(emit_thin_lto, false);
785+
tracked!(emscripten_wasm_eh, true);
785786
tracked!(export_executable_symbols, true);
786787
tracked!(fewer_names, Some(true));
787788
tracked!(fixed_x18, true);

compiler/rustc_passes/src/weak_lang_items.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ pub(crate) fn check_crate(
2626
if items.eh_personality().is_none() {
2727
items.missing.push(LangItem::EhPersonality);
2828
}
29-
if tcx.sess.target.os == "emscripten" && items.eh_catch_typeinfo().is_none() {
29+
if tcx.sess.target.os == "emscripten"
30+
&& items.eh_catch_typeinfo().is_none()
31+
&& !tcx.sess.opts.unstable_opts.emscripten_wasm_eh
32+
{
3033
items.missing.push(LangItem::EhCatchTypeinfo);
3134
}
3235

compiler/rustc_session/src/config/cfg.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
143143
| (sym::target_has_atomic_load_store, Some(_))
144144
| (sym::target_thread_local, None) => disallow(cfg, "--target"),
145145
(sym::fmt_debug, None | Some(_)) => disallow(cfg, "-Z fmt-debug"),
146+
(sym::emscripten_wasm_eh, None | Some(_)) => disallow(cfg, "-Z emscripten_wasm_eh"),
146147
_ => {}
147148
}
148149
}
@@ -295,6 +296,10 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
295296
ins_none!(sym::ub_checks);
296297
}
297298

299+
// Nightly-only implementation detail for the `panic_unwind` and `unwind` crates.
300+
if sess.is_nightly_build() && sess.opts.unstable_opts.emscripten_wasm_eh {
301+
ins_none!(sym::emscripten_wasm_eh);
302+
}
298303
ret
299304
}
300305

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,8 @@ options! {
17711771
"emit a section containing stack size metadata (default: no)"),
17721772
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
17731773
"emit the bc module with thin LTO info (default: yes)"),
1774+
emscripten_wasm_eh: bool = (false, parse_bool, [TRACKED],
1775+
"Use WebAssembly error handling for wasm32-unknown-emscripten"),
17741776
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
17751777
"enforce the type length limit when monomorphizing instances in codegen"),
17761778
export_executable_symbols: bool = (false, parse_bool, [TRACKED],

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ symbols! {
570570
cfg_autodiff_fallback,
571571
cfg_boolean_literals,
572572
cfg_doctest,
573+
cfg_emscripten_wasm_eh,
573574
cfg_eval,
574575
cfg_fmt_debug,
575576
cfg_hide,
@@ -823,6 +824,7 @@ symbols! {
823824
emit_enum_variant_arg,
824825
emit_struct,
825826
emit_struct_field,
827+
emscripten_wasm_eh,
826828
enable,
827829
encode,
828830
end,

0 commit comments

Comments
 (0)