Don't export of __rust_* alloc symbols if not codegened

This commit is contained in:
Collin Baker 2023-02-13 18:48:06 -05:00
parent 2ad8e1fb51
commit f2c81bb1c0

View File

@ -4,6 +4,7 @@
use crate::prelude::*; use crate::prelude::*;
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; 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_session::config::OomStrategy;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -13,24 +14,15 @@ pub(crate) fn codegen(
module: &mut impl Module, module: &mut impl Module,
unwind_context: &mut UnwindContext, unwind_context: &mut UnwindContext,
) -> bool { ) -> bool {
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| { let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
use rustc_middle::middle::dependency_format::Linkage; codegen_inner(
list.iter().any(|&linkage| linkage == Linkage::Dynamic) module,
}); unwind_context,
if any_dynamic_crate { kind,
false tcx.alloc_error_handler_kind(()).unwrap(),
} else if let Some(kind) = tcx.allocator_kind(()) { tcx.sess.opts.unstable_opts.oom,
codegen_inner( );
module, true
unwind_context,
kind,
tcx.alloc_error_handler_kind(()).unwrap(),
tcx.sess.opts.unstable_opts.oom,
);
true
} else {
false
}
} }
fn codegen_inner( fn codegen_inner(