Auto merge of #109507 - Amanieu:panic-oom-payload, r=davidtwco
Report allocation errors as panics OOM is now reported as a panic but with a custom payload type (`AllocErrorPanicPayload`) which holds the layout that was passed to `handle_alloc_error`. This should be review one commit at a time: - The first commit adds `AllocErrorPanicPayload` and changes allocation errors to always be reported as panics. - The second commit removes `#[alloc_error_handler]` and the `alloc_error_hook` API. ACP: https://github.com/rust-lang/libs-team/issues/192 Closes #51540 Closes #51245
This commit is contained in:
commit
321337b0a5
@ -1,4 +1,4 @@
|
|||||||
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
|
#![feature(start, core_intrinsics, lang_items)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@ -21,11 +21,6 @@ fn panic_handler(_: &core::panic::PanicInfo) -> ! {
|
|||||||
core::intrinsics::abort();
|
core::intrinsics::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[alloc_error_handler]
|
|
||||||
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
|
|
||||||
core::intrinsics::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[lang = "eh_personality"]
|
#[lang = "eh_personality"]
|
||||||
fn eh_personality() -> ! {
|
fn eh_personality() -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
|
@ -5,11 +5,10 @@
|
|||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::config::OomStrategy;
|
use rustc_session::config::OomStrategy;
|
||||||
use rustc_span::symbol::sym;
|
|
||||||
|
|
||||||
use crate::GccContext;
|
use crate::GccContext;
|
||||||
|
|
||||||
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) {
|
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind) {
|
||||||
let context = &mods.context;
|
let context = &mods.context;
|
||||||
let usize =
|
let usize =
|
||||||
match tcx.sess.target.pointer_width {
|
match tcx.sess.target.pointer_width {
|
||||||
@ -87,37 +86,6 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
|
|||||||
// as described in https://github.com/rust-lang/rust/commit/77a96ed5646f7c3ee8897693decc4626fe380643
|
// as described in https://github.com/rust-lang/rust/commit/77a96ed5646f7c3ee8897693decc4626fe380643
|
||||||
}
|
}
|
||||||
|
|
||||||
let types = [usize, usize];
|
|
||||||
let name = "__rust_alloc_error_handler".to_string();
|
|
||||||
let args: Vec<_> = types.iter().enumerate()
|
|
||||||
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
|
|
||||||
.collect();
|
|
||||||
let func = context.new_function(None, FunctionType::Exported, void, &args, name, false);
|
|
||||||
|
|
||||||
if tcx.sess.target.default_hidden_visibility {
|
|
||||||
#[cfg(feature="master")]
|
|
||||||
func.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
|
|
||||||
}
|
|
||||||
|
|
||||||
let callee = alloc_error_handler_kind.fn_name(sym::oom);
|
|
||||||
let args: Vec<_> = types.iter().enumerate()
|
|
||||||
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
|
|
||||||
.collect();
|
|
||||||
let callee = context.new_function(None, FunctionType::Extern, void, &args, callee, false);
|
|
||||||
#[cfg(feature="master")]
|
|
||||||
callee.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
|
|
||||||
|
|
||||||
let block = func.new_block("entry");
|
|
||||||
|
|
||||||
let args = args
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, _)| func.get_param(i as i32).to_rvalue())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let _ret = context.new_call(None, callee, &args);
|
|
||||||
//llvm::LLVMSetTailCall(ret, True);
|
|
||||||
block.end_with_void_return(None);
|
|
||||||
|
|
||||||
let name = OomStrategy::SYMBOL.to_string();
|
let name = OomStrategy::SYMBOL.to_string();
|
||||||
let global = context.new_global(None, GlobalKind::Exported, i8, name);
|
let global = context.new_global(None, GlobalKind::Exported, i8, name);
|
||||||
let value = tcx.sess.opts.unstable_opts.oom.should_panic();
|
let value = tcx.sess.opts.unstable_opts.oom.should_panic();
|
||||||
|
@ -163,11 +163,11 @@ fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ExtraBackendMethods for GccCodegenBackend {
|
impl ExtraBackendMethods for GccCodegenBackend {
|
||||||
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) -> Self::Module {
|
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind) -> Self::Module {
|
||||||
let mut mods = GccContext {
|
let mut mods = GccContext {
|
||||||
context: Context::default(),
|
context: Context::default(),
|
||||||
};
|
};
|
||||||
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); }
|
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind); }
|
||||||
mods
|
mods
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user