Skip to content

Commit 62d6214

Browse files
authored
Rollup merge of #143893 - ChrisDenton:eh_personality_optional, r=compiler-errors
Don't require `eh_personality` lang item on targets that have a personality MSVC and wasm have personalities of their own so Rust's personality function is never called. The removed library comment has some more details.
2 parents 145d0cc + 98eadb3 commit 62d6214

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

compiler/rustc_passes/src/weak_lang_items.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ use crate::errors::{
1313
MissingLangItem, MissingPanicHandler, PanicUnwindWithoutStd, UnknownExternLangItem,
1414
};
1515

16+
fn has_personality(tcx: TyCtxt<'_>) -> bool {
17+
// MSVC and wasm targets (except emscripten) have their own personalities
18+
tcx.sess.target.is_like_msvc
19+
|| (tcx.sess.target.is_like_wasm
20+
&& (tcx.sess.target.os != "emscripten"
21+
|| tcx.sess.opts.unstable_opts.emscripten_wasm_eh))
22+
}
23+
1624
/// Checks the crate for usage of weak lang items, returning a vector of all the
1725
/// lang items required by this crate, but not defined yet.
1826
pub(crate) fn check_crate(
@@ -23,7 +31,7 @@ pub(crate) fn check_crate(
2331
// These are never called by user code, they're generated by the compiler.
2432
// They will never implicitly be added to the `missing` array unless we do
2533
// so here.
26-
if items.eh_personality().is_none() {
34+
if items.eh_personality().is_none() && !has_personality(tcx) {
2735
items.missing.push(LangItem::EhPersonality);
2836
}
2937
if tcx.sess.target.os == "emscripten"

library/std/src/sys/personality/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ mod dwarf;
1616
cfg_if::cfg_if! {
1717
if #[cfg(target_os = "emscripten")] {
1818
mod emcc;
19-
} else if #[cfg(any(target_env = "msvc", target_family = "wasm"))] {
20-
// This is required by the compiler to exist (e.g., it's a lang item),
21-
// but it's never actually called by the compiler because
22-
// __CxxFrameHandler3 (msvc) / __gxx_wasm_personality_v0 (wasm) is the
23-
// personality function that is always used. Hence this is just an
24-
// aborting stub.
25-
#[lang = "eh_personality"]
26-
fn rust_eh_personality() {
27-
core::intrinsics::abort()
28-
}
2919
} else if #[cfg(any(
3020
all(target_family = "windows", target_env = "gnu"),
3121
target_os = "psp",
@@ -36,6 +26,9 @@ cfg_if::cfg_if! {
3626
))] {
3727
mod gcc;
3828
} else {
29+
// Targets that have a pre-defined personality:
30+
// - msvc
31+
// - wasm (except for emscripten)
3932
// Targets that don't support unwinding.
4033
// - os=none ("bare metal" targets)
4134
// - os=uefi

0 commit comments

Comments
 (0)