From c8d435aade4db3e51eb2414293a8e0d7934bd17a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 13 Dec 2018 15:16:46 +0100 Subject: [PATCH] Put allocator shim in a different object file --- src/allocator.rs | 7 ++++++- src/lib.rs | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 9c444d8cfc51..1cc45a7d93bb 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -13,7 +13,8 @@ use rustc::middle::allocator::AllocatorKind; use rustc_allocator::{AllocatorTy, ALLOCATOR_METHODS}; -pub fn codegen(sess: &Session, module: &mut Module) { +/// Returns whether an allocator shim was created +pub fn codegen(sess: &Session, module: &mut Module) -> bool { let any_dynamic_crate = sess .dependency_formats .borrow() @@ -23,8 +24,12 @@ pub fn codegen(sess: &Session, module: &mut Module) { list.iter().any(|&linkage| linkage == Linkage::Dynamic) }); if any_dynamic_crate { + false } else if let Some(kind) = *sess.allocator_kind.get() { codegen_inner(module, kind); + true + } else { + false } } diff --git a/src/lib.rs b/src/lib.rs index c7b328b5d881..a1628b8b08db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,14 +258,21 @@ fn codegen_crate<'a, 'tcx>( let mut faerie_module = new_module("some_file".to_string()); codegen_cgus(tcx, &mut faerie_module, &mut log); - crate::allocator::codegen(tcx.sess, &mut faerie_module); tcx.sess.abort_if_errors(); + let mut allocator_module = new_module("allocator_shim.o".to_string()); + let created_alloc_shim = + crate::allocator::codegen(tcx.sess, &mut allocator_module); + return Box::new(CodegenResults { crate_name: tcx.crate_name(LOCAL_CRATE), modules: vec![emit_module("dummy_name", ModuleKind::Regular, faerie_module)], - allocator_module: None, + allocator_module: if created_alloc_shim { + Some(emit_module("allocator_shim", ModuleKind::Allocator, allocator_module)) + } else { + None + }, metadata_module: CompiledModule { name: "dummy_metadata".to_string(), kind: ModuleKind::Metadata,