1
Fork 0

Merge commit '61667dedf5' into sync_cg_clif-2021-09-19

This commit is contained in:
bjorn3 2021-09-19 13:56:58 +02:00
commit 86f9bcfb8e
24 changed files with 332 additions and 294 deletions

View file

@ -11,8 +11,10 @@ use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_session::config::{DebugInfo, OutputType};
use rustc_session::Session;
use cranelift_object::ObjectModule;
use cranelift_codegen::isa::TargetIsa;
use cranelift_object::{ObjectBuilder, ObjectModule};
use crate::{prelude::*, BackendConfig};
@ -24,6 +26,16 @@ impl<HCX> HashStable<HCX> for ModuleCodegenResult {
}
}
fn make_module(sess: &Session, isa: Box<dyn TargetIsa>, name: String) -> ObjectModule {
let mut builder =
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
// Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
// is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
// can easily double the amount of time necessary to perform linking.
builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false));
ObjectModule::new(builder)
}
fn emit_module(
tcx: TyCtxt<'_>,
backend_config: &BackendConfig,
@ -104,7 +116,7 @@ fn module_codegen(
let mono_items = cgu.items_in_deterministic_order(tcx);
let isa = crate::build_isa(tcx.sess, &backend_config);
let mut module = crate::backend::make_module(tcx.sess, isa, cgu_name.as_str().to_string());
let mut module = make_module(tcx.sess, isa, cgu_name.as_str().to_string());
let mut cx = crate::CodegenCx::new(
tcx,
@ -227,8 +239,7 @@ pub(crate) fn run_aot(
tcx.sess.abort_if_errors();
let isa = crate::build_isa(tcx.sess, &backend_config);
let mut allocator_module =
crate::backend::make_module(tcx.sess, isa, "allocator_shim".to_string());
let mut allocator_module = make_module(tcx.sess, isa, "allocator_shim".to_string());
assert_eq!(pointer_ty(tcx), allocator_module.target_config().pointer_type());
let mut allocator_unwind_context = UnwindContext::new(tcx, allocator_module.isa(), true);
let created_alloc_shim =
@ -266,9 +277,7 @@ pub(crate) fn run_aot(
let tmp_file =
tcx.output_filenames(()).temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| {
crate::metadata::write_metadata(tcx, object);
});
let obj = crate::metadata::new_metadata_object(tcx, &metadata_cgu_name, &metadata);
if let Err(err) = std::fs::write(&tmp_file, obj) {
tcx.sess.fatal(&format!("error writing metadata object file: {}", err));