Skip to content

Commit 424a8c3

Browse files
committed
Implement "default_alloc_error_handler" feature
Fixes #1182
1 parent 1f70802 commit 424a8c3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/allocator.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::prelude::*;
55

66
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
77
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
8-
use rustc_span::symbol::sym;
98

109
/// Returns whether an allocator shim was created
1110
pub(crate) fn codegen(
@@ -20,7 +19,7 @@ pub(crate) fn codegen(
2019
if any_dynamic_crate {
2120
false
2221
} else if let Some(kind) = tcx.allocator_kind(()) {
23-
codegen_inner(module, unwind_context, kind);
22+
codegen_inner(module, unwind_context, kind, tcx.lang_items().oom().is_some());
2423
true
2524
} else {
2625
false
@@ -31,6 +30,7 @@ fn codegen_inner(
3130
module: &mut impl Module,
3231
unwind_context: &mut UnwindContext,
3332
kind: AllocatorKind,
33+
has_alloc_error_handler: bool,
3434
) {
3535
let usize_ty = module.target_config().pointer_type();
3636

@@ -65,7 +65,6 @@ fn codegen_inner(
6565

6666
let caller_name = format!("__rust_{}", method.name);
6767
let callee_name = kind.fn_name(method.name);
68-
//eprintln!("Codegen allocator shim {} -> {} ({:?} -> {:?})", caller_name, callee_name, sig.params, sig.returns);
6968

7069
let func_id = module.declare_function(&caller_name, Linkage::Export, &sig).unwrap();
7170

@@ -104,13 +103,12 @@ fn codegen_inner(
104103
returns: vec![],
105104
};
106105

107-
let callee_name = kind.fn_name(sym::oom);
108-
//eprintln!("Codegen allocator shim {} -> {} ({:?} -> {:?})", caller_name, callee_name, sig.params, sig.returns);
106+
let callee_name = if has_alloc_error_handler { "__rg_oom" } else { "__rdl_oom" };
109107

110108
let func_id =
111109
module.declare_function("__rust_alloc_error_handler", Linkage::Export, &sig).unwrap();
112110

113-
let callee_func_id = module.declare_function(&callee_name, Linkage::Import, &sig).unwrap();
111+
let callee_func_id = module.declare_function(callee_name, Linkage::Import, &sig).unwrap();
114112

115113
let mut ctx = Context::new();
116114
ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig);

0 commit comments

Comments
 (0)