]> git.lizzy.rs Git - rust.git/commitdiff
Put allocator shim in a different object file
authorbjorn3 <bjorn3@users.noreply.github.com>
Thu, 13 Dec 2018 14:16:46 +0000 (15:16 +0100)
committerbjorn3 <bjorn3@users.noreply.github.com>
Thu, 13 Dec 2018 14:24:14 +0000 (15:24 +0100)
src/allocator.rs
src/lib.rs

index 9c444d8cfc51cc61ca0a14b7480c356240f494ff..1cc45a7d93bbd8131583ef662a0c4b2d594f665a 100644 (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
     }
 }
 
index c7b328b5d8812feb66f0c63e2ab9f194bcb97ce9..a1628b8b08db4ec074f807d3a023f6b19db1c3a6 100644 (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,