about summary refs log tree commit diff
path: root/src/allocator.rs
diff options
context:
space:
mode:
authorCollin Baker <collinbaker@chromium.org>2023-02-13 18:48:06 -0500
committerCollin Baker <collinbaker@chromium.org>2023-03-09 19:21:44 -0500
commitf2c81bb1c0316e59d73280712e839f8decddaa1a (patch)
tree4f8cf0437b56b95572e3d6e92ca0b0568b7978fe /src/allocator.rs
parent2ad8e1fb51bb998d353bbf500c3a6c3544b9110a (diff)
downloadrust-f2c81bb1c0316e59d73280712e839f8decddaa1a.tar.gz
rust-f2c81bb1c0316e59d73280712e839f8decddaa1a.zip
Don't export of __rust_* alloc symbols if not codegened
Diffstat (limited to 'src/allocator.rs')
-rw-r--r--src/allocator.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/allocator.rs b/src/allocator.rs
index 1c73957ca57..2c246ceb37d 100644
--- a/src/allocator.rs
+++ b/src/allocator.rs
@@ -4,6 +4,7 @@
 use crate::prelude::*;
 
 use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
+use rustc_codegen_ssa::base::allocator_kind_for_codegen;
 use rustc_session::config::OomStrategy;
 use rustc_span::symbol::sym;
 
@@ -13,24 +14,15 @@ pub(crate) fn codegen(
     module: &mut impl Module,
     unwind_context: &mut UnwindContext,
 ) -> bool {
-    let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
-        use rustc_middle::middle::dependency_format::Linkage;
-        list.iter().any(|&linkage| linkage == Linkage::Dynamic)
-    });
-    if any_dynamic_crate {
-        false
-    } else if let Some(kind) = tcx.allocator_kind(()) {
-        codegen_inner(
-            module,
-            unwind_context,
-            kind,
-            tcx.alloc_error_handler_kind(()).unwrap(),
-            tcx.sess.opts.unstable_opts.oom,
-        );
-        true
-    } else {
-        false
-    }
+    let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
+    codegen_inner(
+        module,
+        unwind_context,
+        kind,
+        tcx.alloc_error_handler_kind(()).unwrap(),
+        tcx.sess.opts.unstable_opts.oom,
+    );
+    true
 }
 
 fn codegen_inner(