Skip to content

Commit ad43500

Browse files
committed
Only borrow EncodedMetadata in codegen_crate
And move passing it to the linker to the driver code.
1 parent 99e783d commit ad43500

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

src/driver/aot.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pub(crate) struct OngoingCodegen {
6262
modules: Vec<OngoingModuleCodegen>,
6363
allocator_module: Option<CompiledModule>,
6464
metadata_module: Option<CompiledModule>,
65-
metadata: EncodedMetadata,
6665
crate_info: CrateInfo,
6766
concurrency_limiter: ConcurrencyLimiter,
6867
}
@@ -135,7 +134,6 @@ impl OngoingCodegen {
135134
modules,
136135
allocator_module: self.allocator_module,
137136
metadata_module: self.metadata_module,
138-
metadata: self.metadata,
139137
crate_info: self.crate_info,
140138
};
141139

@@ -706,11 +704,7 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {
706704
}
707705
}
708706

709-
pub(crate) fn run_aot(
710-
tcx: TyCtxt<'_>,
711-
metadata: EncodedMetadata,
712-
need_metadata_module: bool,
713-
) -> Box<OngoingCodegen> {
707+
pub(crate) fn run_aot(tcx: TyCtxt<'_>, metadata: Option<&EncodedMetadata>) -> Box<OngoingCodegen> {
714708
// FIXME handle `-Ctarget-cpu=native`
715709
let target_cpu = match tcx.sess.opts.cg.target_cpu {
716710
Some(ref name) => name,
@@ -727,7 +721,6 @@ pub(crate) fn run_aot(
727721
modules: vec![],
728722
allocator_module: None,
729723
metadata_module: None,
730-
metadata,
731724
crate_info: CrateInfo::new(tcx, target_cpu),
732725
concurrency_limiter: ConcurrencyLimiter::new(0),
733726
});
@@ -787,14 +780,12 @@ pub(crate) fn run_aot(
787780

788781
let allocator_module = emit_allocator_module(tcx);
789782

790-
let metadata_module =
791-
if need_metadata_module { Some(emit_metadata_module(tcx, &metadata)) } else { None };
783+
let metadata_module = metadata.map(|metadata| emit_metadata_module(tcx, metadata));
792784

793785
Box::new(OngoingCodegen {
794786
modules,
795787
allocator_module,
796788
metadata_module,
797-
metadata,
798789
crate_info: CrateInfo::new(tcx, target_cpu),
799790
concurrency_limiter: concurrency_limiter.0,
800791
})

src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
238238
println!("Cranelift version: {}", cranelift_codegen::VERSION);
239239
}
240240

241-
fn codegen_crate(
242-
&self,
243-
tcx: TyCtxt<'_>,
244-
metadata: EncodedMetadata,
245-
need_metadata_module: bool,
246-
) -> Box<dyn Any> {
241+
fn codegen_crate(&self, tcx: TyCtxt<'_>, metadata: Option<&EncodedMetadata>) -> Box<dyn Any> {
247242
info!("codegen crate {}", tcx.crate_name(LOCAL_CRATE));
248243
let config = self.config.clone().unwrap_or_else(|| {
249244
BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args)
@@ -256,7 +251,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
256251
#[cfg(not(feature = "jit"))]
257252
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
258253
} else {
259-
driver::aot::run_aot(tcx, metadata, need_metadata_module)
254+
driver::aot::run_aot(tcx, metadata)
260255
}
261256
}
262257

0 commit comments

Comments
 (0)