diff options
| author | bors <bors@rust-lang.org> | 2022-03-18 03:01:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-18 03:01:46 +0000 |
| commit | d6f3a4ecb48ead838638e902f2fa4e5f3059779b (patch) | |
| tree | a0ced664fbcf095dac8d3b0a498b9ce8b335cb53 /compiler/rustc_codegen_cranelift | |
| parent | cd119057160cedea245aa2679add56723f3dc784 (diff) | |
| parent | 0254e318b820d79bb448d4d22d93e345e67b25eb (diff) | |
| download | rust-d6f3a4ecb48ead838638e902f2fa4e5f3059779b.tar.gz rust-d6f3a4ecb48ead838638e902f2fa4e5f3059779b.zip | |
Auto merge of #88098 - Amanieu:oom_panic, r=nagisa
Implement -Z oom=panic This PR removes the `#[rustc_allocator_nounwind]` attribute on `alloc_error_handler` which allows it to unwind with a panic instead of always aborting. This is then used to implement `-Z oom=panic` as per RFC 2116 (tracking issue #43596). Perf and binary size tests show negligible impact.
Diffstat (limited to 'compiler/rustc_codegen_cranelift')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/allocator.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/allocator.rs b/compiler/rustc_codegen_cranelift/src/allocator.rs index 82247b47888..c3b99b64263 100644 --- a/compiler/rustc_codegen_cranelift/src/allocator.rs +++ b/compiler/rustc_codegen_cranelift/src/allocator.rs @@ -4,6 +4,7 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; +use rustc_session::config::OomStrategy; /// Returns whether an allocator shim was created pub(crate) fn codegen( @@ -18,7 +19,13 @@ pub(crate) fn codegen( if any_dynamic_crate { false } else if let Some(kind) = tcx.allocator_kind(()) { - codegen_inner(module, unwind_context, kind, tcx.lang_items().oom().is_some()); + codegen_inner( + module, + unwind_context, + kind, + tcx.lang_items().oom().is_some(), + tcx.sess.opts.debugging_opts.oom, + ); true } else { false @@ -30,6 +37,7 @@ fn codegen_inner( unwind_context: &mut UnwindContext, kind: AllocatorKind, has_alloc_error_handler: bool, + oom_strategy: OomStrategy, ) { let usize_ty = module.target_config().pointer_type(); @@ -129,4 +137,11 @@ fn codegen_inner( } module.define_function(func_id, &mut ctx).unwrap(); unwind_context.add_function(func_id, &ctx, module.isa()); + + let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap(); + let mut data_ctx = DataContext::new(); + data_ctx.set_align(1); + let val = oom_strategy.should_panic(); + data_ctx.define(Box::new([val])); + module.define_data(data_id, &data_ctx).unwrap(); } |
