Move metadata object generation for dylibs to the linker code
This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.
This commit is contained in:
@@ -141,7 +141,6 @@ impl ModuleConfig {
|
||||
|| match kind {
|
||||
ModuleKind::Regular => sess.opts.output_types.contains_key(&OutputType::Object),
|
||||
ModuleKind::Allocator => false,
|
||||
ModuleKind::Metadata => sess.opts.output_types.contains_key(&OutputType::Metadata),
|
||||
};
|
||||
|
||||
let emit_obj = if !should_emit_obj {
|
||||
@@ -349,7 +348,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
|
||||
pub output_filenames: Arc<OutputFilenames>,
|
||||
pub invocation_temp: Option<String>,
|
||||
pub regular_module_config: Arc<ModuleConfig>,
|
||||
pub metadata_module_config: Arc<ModuleConfig>,
|
||||
pub allocator_module_config: Arc<ModuleConfig>,
|
||||
pub tm_factory: TargetMachineFactoryFn<B>,
|
||||
pub msvc_imps_needed: bool,
|
||||
@@ -394,7 +392,6 @@ impl<B: WriteBackendMethods> CodegenContext<B> {
|
||||
pub fn config(&self, kind: ModuleKind) -> &ModuleConfig {
|
||||
match kind {
|
||||
ModuleKind::Regular => &self.regular_module_config,
|
||||
ModuleKind::Metadata => &self.metadata_module_config,
|
||||
ModuleKind::Allocator => &self.allocator_module_config,
|
||||
}
|
||||
}
|
||||
@@ -473,7 +470,6 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
|
||||
backend: B,
|
||||
tcx: TyCtxt<'_>,
|
||||
target_cpu: String,
|
||||
metadata_module: Option<CompiledModule>,
|
||||
) -> OngoingCodegen<B> {
|
||||
let (coordinator_send, coordinator_receive) = channel();
|
||||
|
||||
@@ -483,7 +479,6 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
|
||||
let crate_info = CrateInfo::new(tcx, target_cpu);
|
||||
|
||||
let regular_config = ModuleConfig::new(ModuleKind::Regular, tcx, no_builtins);
|
||||
let metadata_config = ModuleConfig::new(ModuleKind::Metadata, tcx, no_builtins);
|
||||
let allocator_config = ModuleConfig::new(ModuleKind::Allocator, tcx, no_builtins);
|
||||
|
||||
let (shared_emitter, shared_emitter_main) = SharedEmitter::new();
|
||||
@@ -497,14 +492,12 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
|
||||
codegen_worker_send,
|
||||
coordinator_receive,
|
||||
Arc::new(regular_config),
|
||||
Arc::new(metadata_config),
|
||||
Arc::new(allocator_config),
|
||||
coordinator_send.clone(),
|
||||
);
|
||||
|
||||
OngoingCodegen {
|
||||
backend,
|
||||
metadata_module,
|
||||
crate_info,
|
||||
|
||||
codegen_worker_receive,
|
||||
@@ -840,12 +833,6 @@ pub(crate) fn compute_per_cgu_lto_type(
|
||||
sess_crate_types: &[CrateType],
|
||||
module_kind: ModuleKind,
|
||||
) -> ComputedLtoType {
|
||||
// Metadata modules never participate in LTO regardless of the lto
|
||||
// settings.
|
||||
if module_kind == ModuleKind::Metadata {
|
||||
return ComputedLtoType::No;
|
||||
}
|
||||
|
||||
// If the linker does LTO, we don't have to do it. Note that we
|
||||
// keep doing full LTO, if it is requested, as not to break the
|
||||
// assumption that the output will be a single module.
|
||||
@@ -1026,10 +1013,7 @@ fn finish_intra_module_work<B: ExtraBackendMethods>(
|
||||
let dcx = cgcx.create_dcx();
|
||||
let dcx = dcx.handle();
|
||||
|
||||
if !cgcx.opts.unstable_opts.combine_cgu
|
||||
|| module.kind == ModuleKind::Metadata
|
||||
|| module.kind == ModuleKind::Allocator
|
||||
{
|
||||
if !cgcx.opts.unstable_opts.combine_cgu || module.kind == ModuleKind::Allocator {
|
||||
let module = B::codegen(cgcx, dcx, module, module_config)?;
|
||||
Ok(WorkItemResult::Finished(module))
|
||||
} else {
|
||||
@@ -1120,7 +1104,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||
codegen_worker_send: Sender<CguMessage>,
|
||||
coordinator_receive: Receiver<Box<dyn Any + Send>>,
|
||||
regular_config: Arc<ModuleConfig>,
|
||||
metadata_config: Arc<ModuleConfig>,
|
||||
allocator_config: Arc<ModuleConfig>,
|
||||
tx_to_llvm_workers: Sender<Box<dyn Any + Send>>,
|
||||
) -> thread::JoinHandle<Result<CompiledModules, ()>> {
|
||||
@@ -1213,7 +1196,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||
diag_emitter: shared_emitter.clone(),
|
||||
output_filenames: Arc::clone(tcx.output_filenames(())),
|
||||
regular_module_config: regular_config,
|
||||
metadata_module_config: metadata_config,
|
||||
allocator_module_config: allocator_config,
|
||||
tm_factory: backend.target_machine_factory(tcx.sess, ol, backend_features),
|
||||
msvc_imps_needed: msvc_imps_needed(tcx),
|
||||
@@ -1670,7 +1652,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||
assert!(compiled_allocator_module.is_none());
|
||||
compiled_allocator_module = Some(compiled_module);
|
||||
}
|
||||
ModuleKind::Metadata => bug!("Should be handled separately"),
|
||||
}
|
||||
}
|
||||
Ok(WorkItemResult::NeedsLink(module)) => {
|
||||
@@ -2052,7 +2033,6 @@ impl<B: ExtraBackendMethods> Drop for Coordinator<B> {
|
||||
|
||||
pub struct OngoingCodegen<B: ExtraBackendMethods> {
|
||||
pub backend: B,
|
||||
pub metadata_module: Option<CompiledModule>,
|
||||
pub crate_info: CrateInfo,
|
||||
pub codegen_worker_receive: Receiver<CguMessage>,
|
||||
pub shared_emitter_main: SharedEmitterMain,
|
||||
@@ -2096,7 +2076,6 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
|
||||
|
||||
modules: compiled_modules.modules,
|
||||
allocator_module: compiled_modules.allocator_module,
|
||||
metadata_module: self.metadata_module,
|
||||
},
|
||||
work_products,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user