diff options
| author | Daniel Paoliello <danpao@microsoft.com> | 2025-07-03 09:17:48 -0700 |
|---|---|---|
| committer | Daniel Paoliello <danpao@microsoft.com> | 2025-07-03 10:52:21 -0700 |
| commit | 2b22d0f0d2b9d0d71025065db93058e34f846600 (patch) | |
| tree | 7896a68c2fe3f42137bd4bce543c24aa2017f8df /compiler/rustc_codegen_cranelift/src | |
| parent | b94bd12401d26ccf1c3b04ceb4e950b0ff7c8d29 (diff) | |
| download | rust-2b22d0f0d2b9d0d71025065db93058e34f846600.tar.gz rust-2b22d0f0d2b9d0d71025065db93058e34f846600.zip | |
Make __rust_alloc_error_handler_should_panic a function
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/allocator.rs | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/allocator.rs b/compiler/rustc_codegen_cranelift/src/allocator.rs index ffb932a3c38..04f1129d87c 100644 --- a/compiler/rustc_codegen_cranelift/src/allocator.rs +++ b/compiler/rustc_codegen_cranelift/src/allocator.rs @@ -84,19 +84,34 @@ fn codegen_inner( &mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)), ); - let data_id = module - .declare_data( - &mangle_internal_symbol(tcx, OomStrategy::SYMBOL), - Linkage::Export, - false, - false, - ) - .unwrap(); - let mut data = DataDescription::new(); - data.set_align(1); - let val = oom_strategy.should_panic(); - data.define(Box::new([val])); - module.define_data(data_id, &data).unwrap(); + { + let sig = Signature { + call_conv: module.target_config().default_call_conv, + params: vec![], + returns: vec![AbiParam::new(types::I8)], + }; + let func_id = module + .declare_function( + &mangle_internal_symbol(tcx, OomStrategy::SYMBOL), + Linkage::Export, + &sig, + ) + .unwrap(); + let mut ctx = Context::new(); + ctx.func.signature = sig; + { + let mut func_ctx = FunctionBuilderContext::new(); + let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx); + + let block = bcx.create_block(); + bcx.switch_to_block(block); + let value = bcx.ins().iconst(types::I8, oom_strategy.should_panic() as i64); + bcx.ins().return_(&[value]); + bcx.seal_all_blocks(); + bcx.finalize(); + } + module.define_function(func_id, &mut ctx).unwrap(); + } { let sig = Signature { |
