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()
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
}
}
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,