about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/src/allocator.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src/allocator.rs')
-rw-r--r--compiler/rustc_codegen_cranelift/src/allocator.rs79
1 files changed, 45 insertions, 34 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/allocator.rs b/compiler/rustc_codegen_cranelift/src/allocator.rs
index 2c246ceb37d..d4b1ae2b613 100644
--- a/compiler/rustc_codegen_cranelift/src/allocator.rs
+++ b/compiler/rustc_codegen_cranelift/src/allocator.rs
@@ -3,10 +3,12 @@
 
 use crate::prelude::*;
 
-use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
+use rustc_ast::expand::allocator::{
+    alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy,
+    ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE,
+};
 use rustc_codegen_ssa::base::allocator_kind_for_codegen;
 use rustc_session::config::OomStrategy;
-use rustc_span::symbol::sym;
 
 /// Returns whether an allocator shim was created
 pub(crate) fn codegen(
@@ -34,41 +36,43 @@ fn codegen_inner(
 ) {
     let usize_ty = module.target_config().pointer_type();
 
-    for method in ALLOCATOR_METHODS {
-        let mut arg_tys = Vec::with_capacity(method.inputs.len());
-        for ty in method.inputs.iter() {
-            match *ty {
-                AllocatorTy::Layout => {
-                    arg_tys.push(usize_ty); // size
-                    arg_tys.push(usize_ty); // align
-                }
-                AllocatorTy::Ptr => arg_tys.push(usize_ty),
-                AllocatorTy::Usize => arg_tys.push(usize_ty),
+    if kind == AllocatorKind::Default {
+        for method in ALLOCATOR_METHODS {
+            let mut arg_tys = Vec::with_capacity(method.inputs.len());
+            for ty in method.inputs.iter() {
+                match *ty {
+                    AllocatorTy::Layout => {
+                        arg_tys.push(usize_ty); // size
+                        arg_tys.push(usize_ty); // align
+                    }
+                    AllocatorTy::Ptr => arg_tys.push(usize_ty),
+                    AllocatorTy::Usize => arg_tys.push(usize_ty),
 
-                AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
+                    AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
+                }
             }
-        }
-        let output = match method.output {
-            AllocatorTy::ResultPtr => Some(usize_ty),
-            AllocatorTy::Unit => None,
+            let output = match method.output {
+                AllocatorTy::ResultPtr => Some(usize_ty),
+                AllocatorTy::Unit => None,
 
-            AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
-                panic!("invalid allocator output")
-            }
-        };
+                AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
+                    panic!("invalid allocator output")
+                }
+            };
 
-        let sig = Signature {
-            call_conv: module.target_config().default_call_conv,
-            params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
-            returns: output.into_iter().map(AbiParam::new).collect(),
-        };
-        crate::common::create_wrapper_function(
-            module,
-            unwind_context,
-            sig,
-            &format!("__rust_{}", method.name),
-            &kind.fn_name(method.name),
-        );
+            let sig = Signature {
+                call_conv: module.target_config().default_call_conv,
+                params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
+                returns: output.into_iter().map(AbiParam::new).collect(),
+            };
+            crate::common::create_wrapper_function(
+                module,
+                unwind_context,
+                sig,
+                &global_fn_name(method.name),
+                &default_fn_name(method.name),
+            );
+        }
     }
 
     let sig = Signature {
@@ -81,7 +85,7 @@ fn codegen_inner(
         unwind_context,
         sig,
         "__rust_alloc_error_handler",
-        &alloc_error_handler_kind.fn_name(sym::oom),
+        &alloc_error_handler_name(alloc_error_handler_kind),
     );
 
     let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
@@ -90,4 +94,11 @@ fn codegen_inner(
     let val = oom_strategy.should_panic();
     data_ctx.define(Box::new([val]));
     module.define_data(data_id, &data_ctx).unwrap();
+
+    let data_id =
+        module.declare_data(NO_ALLOC_SHIM_IS_UNSTABLE, Linkage::Export, false, false).unwrap();
+    let mut data_ctx = DataContext::new();
+    data_ctx.set_align(1);
+    data_ctx.define(Box::new([0]));
+    module.define_data(data_id, &data_ctx).unwrap();
 }