Rollup merge of #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.
This commit is contained in:
commit
4e4a93c2dd
21 changed files with 131 additions and 10 deletions
|
@ -109,7 +109,10 @@ unsafe fn configure_llvm(sess: &Session) {
|
|||
add("-wasm-enable-eh", false);
|
||||
}
|
||||
|
||||
if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
|
||||
if sess.target.os == "emscripten"
|
||||
&& !sess.opts.unstable_opts.emscripten_wasm_eh
|
||||
&& sess.panic_strategy() == PanicStrategy::Unwind
|
||||
{
|
||||
add("-enable-emscripten-cxx-exceptions", false);
|
||||
}
|
||||
|
||||
|
|
|
@ -2451,10 +2451,12 @@ fn add_order_independent_options(
|
|||
}
|
||||
|
||||
if sess.target.os == "emscripten" {
|
||||
cmd.cc_arg("-s").cc_arg(if sess.panic_strategy() == PanicStrategy::Abort {
|
||||
"DISABLE_EXCEPTION_CATCHING=1"
|
||||
cmd.cc_arg(if sess.panic_strategy() == PanicStrategy::Abort {
|
||||
"-sDISABLE_EXCEPTION_CATCHING=1"
|
||||
} else if sess.opts.unstable_opts.emscripten_wasm_eh {
|
||||
"-fwasm-exceptions"
|
||||
} else {
|
||||
"DISABLE_EXCEPTION_CATCHING=0"
|
||||
"-sDISABLE_EXCEPTION_CATCHING=0"
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -388,7 +388,8 @@ pub(crate) fn build_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
// exceptions. This means that the VM does the unwinding for
|
||||
// us
|
||||
pub fn wants_wasm_eh(sess: &Session) -> bool {
|
||||
sess.target.is_like_wasm && sess.target.os != "emscripten"
|
||||
sess.target.is_like_wasm
|
||||
&& (sess.target.os != "emscripten" || sess.opts.unstable_opts.emscripten_wasm_eh)
|
||||
}
|
||||
|
||||
/// Returns `true` if this session's target will use SEH-based unwinding.
|
||||
|
|
|
@ -37,6 +37,7 @@ const GATED_CFGS: &[GatedCfg] = &[
|
|||
(sym::sanitizer_cfi_normalize_integers, sym::cfg_sanitizer_cfi, Features::cfg_sanitizer_cfi),
|
||||
// this is consistent with naming of the compiler flag it's for
|
||||
(sym::fmt_debug, sym::fmt_debug, Features::fmt_debug),
|
||||
(sym::emscripten_wasm_eh, sym::cfg_emscripten_wasm_eh, Features::cfg_emscripten_wasm_eh),
|
||||
];
|
||||
|
||||
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
|
||||
|
|
|
@ -202,6 +202,8 @@ declare_features! (
|
|||
(internal, allow_internal_unstable, "1.0.0", None),
|
||||
/// Allows using anonymous lifetimes in argument-position impl-trait.
|
||||
(unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None),
|
||||
/// Allows access to the emscripten_wasm_eh config, used by panic_unwind and unwind
|
||||
(internal, cfg_emscripten_wasm_eh, "CURRENT_RUSTC_VERSION", None),
|
||||
/// Allows identifying the `compiler_builtins` crate.
|
||||
(internal, compiler_builtins, "1.13.0", None),
|
||||
/// Allows writing custom MIR
|
||||
|
|
|
@ -782,6 +782,7 @@ fn test_unstable_options_tracking_hash() {
|
|||
tracked!(dwarf_version, Some(5));
|
||||
tracked!(embed_source, true);
|
||||
tracked!(emit_thin_lto, false);
|
||||
tracked!(emscripten_wasm_eh, true);
|
||||
tracked!(export_executable_symbols, true);
|
||||
tracked!(fewer_names, Some(true));
|
||||
tracked!(fixed_x18, true);
|
||||
|
|
|
@ -26,7 +26,10 @@ pub(crate) fn check_crate(
|
|||
if items.eh_personality().is_none() {
|
||||
items.missing.push(LangItem::EhPersonality);
|
||||
}
|
||||
if tcx.sess.target.os == "emscripten" && items.eh_catch_typeinfo().is_none() {
|
||||
if tcx.sess.target.os == "emscripten"
|
||||
&& items.eh_catch_typeinfo().is_none()
|
||||
&& !tcx.sess.opts.unstable_opts.emscripten_wasm_eh
|
||||
{
|
||||
items.missing.push(LangItem::EhCatchTypeinfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -143,6 +143,7 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
|
|||
| (sym::target_has_atomic_load_store, Some(_))
|
||||
| (sym::target_thread_local, None) => disallow(cfg, "--target"),
|
||||
(sym::fmt_debug, None | Some(_)) => disallow(cfg, "-Z fmt-debug"),
|
||||
(sym::emscripten_wasm_eh, None | Some(_)) => disallow(cfg, "-Z emscripten_wasm_eh"),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -295,6 +296,10 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
|
|||
ins_none!(sym::ub_checks);
|
||||
}
|
||||
|
||||
// Nightly-only implementation detail for the `panic_unwind` and `unwind` crates.
|
||||
if sess.is_nightly_build() && sess.opts.unstable_opts.emscripten_wasm_eh {
|
||||
ins_none!(sym::emscripten_wasm_eh);
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
|
|
|
@ -1771,6 +1771,8 @@ options! {
|
|||
"emit a section containing stack size metadata (default: no)"),
|
||||
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
|
||||
"emit the bc module with thin LTO info (default: yes)"),
|
||||
emscripten_wasm_eh: bool = (false, parse_bool, [TRACKED],
|
||||
"Use WebAssembly error handling for wasm32-unknown-emscripten"),
|
||||
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
|
||||
"enforce the type length limit when monomorphizing instances in codegen"),
|
||||
export_executable_symbols: bool = (false, parse_bool, [TRACKED],
|
||||
|
|
|
@ -570,6 +570,7 @@ symbols! {
|
|||
cfg_autodiff_fallback,
|
||||
cfg_boolean_literals,
|
||||
cfg_doctest,
|
||||
cfg_emscripten_wasm_eh,
|
||||
cfg_eval,
|
||||
cfg_fmt_debug,
|
||||
cfg_hide,
|
||||
|
@ -823,6 +824,7 @@ symbols! {
|
|||
emit_enum_variant_arg,
|
||||
emit_struct,
|
||||
emit_struct_field,
|
||||
emscripten_wasm_eh,
|
||||
enable,
|
||||
encode,
|
||||
end,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue