Put allocator shim in a different object file

This commit is contained in:
bjorn3
2018-12-13 15:16:46 +01:00
parent 77e3612581
commit c8d435aade
2 changed files with 15 additions and 3 deletions
+6 -1
View File
@@ -13,7 +13,8 @@
use rustc::middle::allocator::AllocatorKind;
use rustc_allocator::{AllocatorTy, ALLOCATOR_METHODS};
pub fn codegen(sess: &Session, module: &mut Module<impl Backend + 'static>) {
/// Returns whether an allocator shim was created
pub fn codegen(sess: &Session, module: &mut Module<impl Backend + 'static>) -> bool {
let any_dynamic_crate = sess
.dependency_formats
.borrow()
@@ -23,8 +24,12 @@ pub fn codegen(sess: &Session, module: &mut Module<impl Backend + 'static>) {
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
}
}
+9 -2
View File
@@ -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,