diff --git a/src/allocator.rs b/src/allocator.rs index 2ea4a1659f8..8dae5dcf385 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -13,7 +13,11 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; /// Returns whether an allocator shim was created -pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut Module) -> bool { +pub(crate) fn codegen( + tcx: TyCtxt<'_>, + module: &mut Module, + unwind_context: &mut UnwindContext<'_>, +) -> bool { let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { use rustc_middle::middle::dependency_format::Linkage; list.iter().any(|&linkage| linkage == Linkage::Dynamic) @@ -21,14 +25,18 @@ pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut Module, kind: AllocatorKind) { +fn codegen_inner( + module: &mut Module, + unwind_context: &mut UnwindContext<'_>, + kind: AllocatorKind, +) { let usize_ty = module.target_config().pointer_type(); for method in ALLOCATOR_METHODS { @@ -99,5 +107,6 @@ fn codegen_inner(module: &mut Module, kind: AllocatorKin &mut ctx, &mut cranelift_codegen::binemit::NullTrapSink {}, ).unwrap(); + unwind_context.add_function(func_id, &ctx, module.isa()); } } diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 6c5d5c48d86..27c76fbee1d 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -123,7 +123,7 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege let mut unwind_context = UnwindContext::new(tcx, &mut module); super::codegen_mono_items(tcx, &mut module, debug.as_mut(), &mut unwind_context, mono_items); - crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module); + crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context); emit_module( tcx, @@ -185,19 +185,21 @@ pub(super) fn run_aot( tcx.sess.abort_if_errors(); let mut allocator_module = new_module(tcx, "allocator_shim".to_string()); - let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module); + let mut allocator_unwind_context = UnwindContext::new(tcx, &mut allocator_module); + let created_alloc_shim = crate::allocator::codegen( + tcx, + &mut allocator_module, + &mut allocator_unwind_context, + ); let allocator_module = if created_alloc_shim { - // FIXME create .eh_frame for allocator shim - let unwind_context = UnwindContext::new(tcx, &mut allocator_module); - let ModuleCodegenResult(module, work_product) = emit_module( tcx, "allocator_shim".to_string(), ModuleKind::Allocator, allocator_module, None, - unwind_context, + allocator_unwind_context, ); if let Some((id, product)) = work_product { work_products.insert(id, product); diff --git a/src/driver/jit.rs b/src/driver/jit.rs index d4f17981845..fa88029ceb9 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -57,8 +57,8 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! { super::time(tcx, "codegen mono items", || { super::codegen_mono_items(tcx, &mut jit_module, None, &mut unwind_context, mono_items); }); - crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module); - crate::allocator::codegen(tcx, &mut jit_module); + crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, &mut unwind_context); + crate::allocator::codegen(tcx, &mut jit_module, &mut unwind_context); jit_module.finalize_definitions(); diff --git a/src/main_shim.rs b/src/main_shim.rs index c45b0eb8cd4..7366c6a9c0a 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -2,7 +2,11 @@ use crate::prelude::*; /// Create the `main` function which will initialize the rust runtime and call /// users main function. -pub(crate) fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module) { +pub(crate) fn maybe_create_entry_wrapper( + tcx: TyCtxt<'_>, + module: &mut Module, + unwind_context: &mut UnwindContext<'_>, +) { use rustc_hir::lang_items::StartFnLangItem; use rustc_session::config::EntryFnType; @@ -22,11 +26,12 @@ pub(crate) fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module, m: &mut Module, + unwind_context: &mut UnwindContext<'_>, rust_main_def_id: DefId, use_start_lang_item: bool, ) { @@ -109,5 +114,6 @@ pub(crate) fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module