Skip to content

Commit aec8bbd

Browse files
Strip out broken Emscripten unwinding code
1 parent 4f322db commit aec8bbd

File tree

23 files changed

+42
-335
lines changed

23 files changed

+42
-335
lines changed

compiler/rustc_codegen_llvm/src/context.rs

-21
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub struct CodegenCx<'ll, 'tcx> {
9999
pub dbg_cx: Option<debuginfo::CodegenUnitDebugContext<'ll, 'tcx>>,
100100

101101
eh_personality: Cell<Option<&'ll Value>>,
102-
eh_catch_typeinfo: Cell<Option<&'ll Value>>,
103102
pub rust_try_fn: Cell<Option<(&'ll Type, &'ll Value)>>,
104103

105104
intrinsics: RefCell<FxHashMap<&'static str, (&'ll Type, &'ll Value)>>,
@@ -439,7 +438,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
439438
coverage_cx,
440439
dbg_cx,
441440
eh_personality: Cell::new(None),
442-
eh_catch_typeinfo: Cell::new(None),
443441
rust_try_fn: Cell::new(None),
444442
intrinsics: Default::default(),
445443
local_gen_sym_counter: Cell::new(0),
@@ -889,25 +887,6 @@ impl<'ll> CodegenCx<'ll, '_> {
889887
}
890888
None
891889
}
892-
893-
pub(crate) fn eh_catch_typeinfo(&self) -> &'ll Value {
894-
if let Some(eh_catch_typeinfo) = self.eh_catch_typeinfo.get() {
895-
return eh_catch_typeinfo;
896-
}
897-
let tcx = self.tcx;
898-
assert!(self.sess().target.is_like_emscripten);
899-
let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
900-
Some(def_id) => self.get_static(def_id),
901-
_ => {
902-
let ty = self
903-
.type_struct(&[self.type_ptr_to(self.type_isize()), self.type_i8p()], false);
904-
self.declare_global("rust_eh_catch_typeinfo", ty)
905-
}
906-
};
907-
let eh_catch_typeinfo = self.const_bitcast(eh_catch_typeinfo, self.type_i8p());
908-
self.eh_catch_typeinfo.set(Some(eh_catch_typeinfo));
909-
eh_catch_typeinfo
910-
}
911890
}
912891

913892
impl CodegenCx<'_, '_> {

compiler/rustc_codegen_llvm/src/intrinsic.rs

-87
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ fn try_intrinsic<'ll>(
431431
bx.store(bx.const_i32(0), dest, ret_align);
432432
} else if wants_msvc_seh(bx.sess()) {
433433
codegen_msvc_try(bx, try_func, data, catch_func, dest);
434-
} else if bx.sess().target.is_like_emscripten {
435-
codegen_emcc_try(bx, try_func, data, catch_func, dest);
436434
} else {
437435
codegen_gnu_try(bx, try_func, data, catch_func, dest);
438436
}
@@ -656,91 +654,6 @@ fn codegen_gnu_try<'ll>(
656654
bx.store(ret, dest, i32_align);
657655
}
658656

659-
// Variant of codegen_gnu_try used for emscripten where Rust panics are
660-
// implemented using C++ exceptions. Here we use exceptions of a specific type
661-
// (`struct rust_panic`) to represent Rust panics.
662-
fn codegen_emcc_try<'ll>(
663-
bx: &mut Builder<'_, 'll, '_>,
664-
try_func: &'ll Value,
665-
data: &'ll Value,
666-
catch_func: &'ll Value,
667-
dest: &'ll Value,
668-
) {
669-
let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| {
670-
// Codegens the shims described above:
671-
//
672-
// bx:
673-
// invoke %try_func(%data) normal %normal unwind %catch
674-
//
675-
// normal:
676-
// ret 0
677-
//
678-
// catch:
679-
// (%ptr, %selector) = landingpad
680-
// %rust_typeid = @llvm.eh.typeid.for(@_ZTI10rust_panic)
681-
// %is_rust_panic = %selector == %rust_typeid
682-
// %catch_data = alloca { i8*, i8 }
683-
// %catch_data[0] = %ptr
684-
// %catch_data[1] = %is_rust_panic
685-
// call %catch_func(%data, %catch_data)
686-
// ret 1
687-
let then = bx.append_sibling_block("then");
688-
let catch = bx.append_sibling_block("catch");
689-
690-
let try_func = llvm::get_param(bx.llfn(), 0);
691-
let data = llvm::get_param(bx.llfn(), 1);
692-
let catch_func = llvm::get_param(bx.llfn(), 2);
693-
let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void());
694-
bx.invoke(try_func_ty, try_func, &[data], then, catch, None);
695-
696-
bx.switch_to_block(then);
697-
bx.ret(bx.const_i32(0));
698-
699-
// Type indicator for the exception being thrown.
700-
//
701-
// The first value in this tuple is a pointer to the exception object
702-
// being thrown. The second value is a "selector" indicating which of
703-
// the landing pad clauses the exception's type had been matched to.
704-
bx.switch_to_block(catch);
705-
let tydesc = bx.eh_catch_typeinfo();
706-
let lpad_ty = bx.type_struct(&[bx.type_i8p(), bx.type_i32()], false);
707-
let vals = bx.landing_pad(lpad_ty, bx.eh_personality(), 2);
708-
bx.add_clause(vals, tydesc);
709-
bx.add_clause(vals, bx.const_null(bx.type_i8p()));
710-
let ptr = bx.extract_value(vals, 0);
711-
let selector = bx.extract_value(vals, 1);
712-
713-
// Check if the typeid we got is the one for a Rust panic.
714-
let rust_typeid = bx.call_intrinsic("llvm.eh.typeid.for", &[tydesc]);
715-
let is_rust_panic = bx.icmp(IntPredicate::IntEQ, selector, rust_typeid);
716-
let is_rust_panic = bx.zext(is_rust_panic, bx.type_bool());
717-
718-
// We need to pass two values to catch_func (ptr and is_rust_panic), so
719-
// create an alloca and pass a pointer to that.
720-
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
721-
let i8_align = bx.tcx().data_layout.i8_align.abi;
722-
let catch_data_type = bx.type_struct(&[bx.type_i8p(), bx.type_bool()], false);
723-
let catch_data = bx.alloca(catch_data_type, ptr_align);
724-
let catch_data_0 =
725-
bx.inbounds_gep(catch_data_type, catch_data, &[bx.const_usize(0), bx.const_usize(0)]);
726-
bx.store(ptr, catch_data_0, ptr_align);
727-
let catch_data_1 =
728-
bx.inbounds_gep(catch_data_type, catch_data, &[bx.const_usize(0), bx.const_usize(1)]);
729-
bx.store(is_rust_panic, catch_data_1, i8_align);
730-
let catch_data = bx.bitcast(catch_data, bx.type_i8p());
731-
732-
let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void());
733-
bx.call(catch_ty, catch_func, &[data, catch_data], None);
734-
bx.ret(bx.const_i32(1));
735-
});
736-
737-
// Note that no invoke is used here because by definition this function
738-
// can't panic (that's what it's catching).
739-
let ret = bx.call(llty, llfn, &[try_func, data, catch_func], None);
740-
let i32_align = bx.tcx().data_layout.i32_align.abi;
741-
bx.store(ret, dest, i32_align);
742-
}
743-
744657
// Helper function to give a Block to a closure to codegen a shim function.
745658
// This is currently primarily used for the `try` intrinsic functions above.
746659
fn gen_fn<'ll, 'tcx>(

compiler/rustc_codegen_ssa/src/back/link.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_span::symbol::Symbol;
2121
use rustc_span::DebuggerVisualizerFile;
2222
use rustc_target::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
2323
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor, SplitDebuginfo};
24-
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel, SanitizerSet, Target};
24+
use rustc_target::spec::{RelocModel, RelroLevel, SanitizerSet, Target};
2525

2626
use super::archive::{find_library, ArchiveBuilder};
2727
use super::command::Command;
@@ -2047,15 +2047,6 @@ fn add_order_independent_options(
20472047
cmd.no_crt_objects();
20482048
}
20492049

2050-
if sess.target.is_like_emscripten {
2051-
cmd.arg("-s");
2052-
cmd.arg(if sess.panic_strategy() == PanicStrategy::Abort {
2053-
"DISABLE_EXCEPTION_CATCHING=1"
2054-
} else {
2055-
"DISABLE_EXCEPTION_CATCHING=0"
2056-
});
2057-
}
2058-
20592050
if flavor == LinkerFlavor::PtxLinker {
20602051
// Provide the linker with fallback to internal `target-cpu`.
20612052
cmd.arg("--fallback-arch");

compiler/rustc_hir/src/lang_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ language_item_table! {
270270
Start, sym::start, start_fn, Target::Fn, GenericRequirement::Exact(1);
271271

272272
EhPersonality, sym::eh_personality, eh_personality, Target::Fn, GenericRequirement::None;
273-
EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None;
274273

275274
OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);
276275

compiler/rustc_hir/src/weak_lang_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ impl LanguageItems {
4242
weak_lang_items! {
4343
panic_impl, PanicImpl, rust_begin_unwind;
4444
eh_personality, EhPersonality, rust_eh_personality;
45-
eh_catch_typeinfo, EhCatchTypeinfo, rust_eh_catch_typeinfo;
4645
oom, Oom, rust_oom;
4746
}

compiler/rustc_middle/src/middle/lang_items.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ pub fn required(tcx: TyCtxt<'_>, lang_item: LangItem) -> bool {
5353
// symbols. Other panic runtimes ensure that the relevant symbols are
5454
// available to link things together, but they're never exercised.
5555
match tcx.sess.panic_strategy() {
56-
PanicStrategy::Abort => {
57-
lang_item != LangItem::EhPersonality && lang_item != LangItem::EhCatchTypeinfo
58-
}
56+
PanicStrategy::Abort => lang_item != LangItem::EhPersonality,
5957
PanicStrategy::Unwind => true,
6058
}
6159
}

compiler/rustc_passes/src/weak_lang_items.rs

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem
1717
if items.eh_personality().is_none() {
1818
items.missing.push(LangItem::EhPersonality);
1919
}
20-
if tcx.sess.target.is_like_emscripten && items.eh_catch_typeinfo().is_none() {
21-
items.missing.push(LangItem::EhCatchTypeinfo);
22-
}
2320

2421
let crate_items = tcx.hir_crate_items(());
2522
for id in crate_items.foreign_items() {

compiler/rustc_span/src/symbol.rs

-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ symbols! {
619619
e,
620620
edition_macro_pats,
621621
edition_panic,
622-
eh_catch_typeinfo,
623622
eh_personality,
624623
emit_enum,
625624
emit_enum_variant,
@@ -1164,7 +1163,6 @@ symbols! {
11641163
rust_2024_preview,
11651164
rust_begin_unwind,
11661165
rust_cold_cc,
1167-
rust_eh_catch_typeinfo,
11681166
rust_eh_personality,
11691167
rust_eh_register_frames,
11701168
rust_eh_unregister_frames,

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ pub fn target() -> Target {
1616
let mut post_link_args = LinkArgs::new();
1717
post_link_args.insert(
1818
LinkerFlavor::Em,
19-
vec![
20-
"-s".into(),
21-
"ABORTING_MALLOC=0".into(),
22-
"-Wl,--fatal-warnings".into(),
23-
],
19+
vec!["-s".into(), "ABORTING_MALLOC=0".into(), "-Wl,--fatal-warnings".into()],
2420
);
2521

2622
let opts = TargetOptions {

library/panic_abort/src/lib.rs

-11
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,6 @@ pub mod personalities {
134134
1 // `ExceptionContinueSearch`
135135
}
136136

137-
// Similar to above, this corresponds to the `eh_catch_typeinfo` lang item
138-
// that's only used on Emscripten currently.
139-
//
140-
// Since panics don't generate exceptions and foreign exceptions are
141-
// currently UB with -C panic=abort (although this may be subject to
142-
// change), any catch_unwind calls will never use this typeinfo.
143-
#[rustc_std_internal_symbol]
144-
#[allow(non_upper_case_globals)]
145-
#[cfg(target_os = "emscripten")]
146-
static rust_eh_catch_typeinfo: [usize; 2] = [0; 2];
147-
148137
// These two are called by our startup objects on i686-pc-windows-gnu, but
149138
// they don't need to do anything so the bodies are nops.
150139
#[rustc_std_internal_symbol]

library/panic_unwind/src/emcc.rs

-132
This file was deleted.

0 commit comments

Comments
 (0)