diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 93d164e7d01f8..3b2b2b3e948d8 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -13,6 +13,14 @@ use crate::errors::{ MissingLangItem, MissingPanicHandler, PanicUnwindWithoutStd, UnknownExternLangItem, }; +fn has_personality(tcx: TyCtxt<'_>) -> bool { + // MSVC and wasm targets (except emscripten) have their own personalities + tcx.sess.target.is_like_msvc + || (tcx.sess.target.is_like_wasm + && (tcx.sess.target.os != "emscripten" + || tcx.sess.opts.unstable_opts.emscripten_wasm_eh)) +} + /// Checks the crate for usage of weak lang items, returning a vector of all the /// lang items required by this crate, but not defined yet. pub(crate) fn check_crate( @@ -23,7 +31,7 @@ pub(crate) fn check_crate( // These are never called by user code, they're generated by the compiler. // They will never implicitly be added to the `missing` array unless we do // so here. - if items.eh_personality().is_none() { + if items.eh_personality().is_none() && !has_personality(tcx) { items.missing.push(LangItem::EhPersonality); } if tcx.sess.target.os == "emscripten" diff --git a/library/std/src/sys/personality/mod.rs b/library/std/src/sys/personality/mod.rs index 2e1d2e53a2979..2623a0b8e5f32 100644 --- a/library/std/src/sys/personality/mod.rs +++ b/library/std/src/sys/personality/mod.rs @@ -16,16 +16,6 @@ mod dwarf; cfg_if::cfg_if! { if #[cfg(target_os = "emscripten")] { mod emcc; - } else if #[cfg(any(target_env = "msvc", target_family = "wasm"))] { - // This is required by the compiler to exist (e.g., it's a lang item), - // but it's never actually called by the compiler because - // __CxxFrameHandler3 (msvc) / __gxx_wasm_personality_v0 (wasm) is the - // personality function that is always used. Hence this is just an - // aborting stub. - #[lang = "eh_personality"] - fn rust_eh_personality() { - core::intrinsics::abort() - } } else if #[cfg(any( all(target_family = "windows", target_env = "gnu"), target_os = "psp", @@ -36,6 +26,9 @@ cfg_if::cfg_if! { ))] { mod gcc; } else { + // Targets that have a pre-defined personality: + // - msvc + // - wasm (except for emscripten) // Targets that don't support unwinding. // - os=none ("bare metal" targets) // - os=uefi