Skip to content

Don't require eh_personality lang item on targets that have a personality #143893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/rustc_passes/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
Expand Down
13 changes: 3 additions & 10 deletions library/std/src/sys/personality/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
Loading