Better use of CodegenResults::modules

This commit is contained in:
bjorn3 2018-11-19 19:11:21 +01:00
parent f4ae9a4dbb
commit 8e28d80a3d
2 changed files with 12 additions and 15 deletions

View File

@ -120,7 +120,6 @@ impl<'tcx> Caches<'tcx> {
struct CraneliftCodegenBackend;
pub struct CodegenResults {
artifact: faerie::Artifact,
modules: Vec<CompiledModule>,
allocator_module: Option<CompiledModule>,
metadata: Vec<u8>,
@ -281,19 +280,17 @@ impl CodegenBackend for CraneliftCodegenBackend {
std::fs::write(&tmp_file, obj).unwrap();
return Box::new(CodegenResults {
artifact,
metadata: metadata.raw_data,
crate_name: tcx.crate_name(LOCAL_CRATE),
crate_info: CrateInfo::new(tcx),
linker_info: LinkerInfo::new(tcx),
modules: vec![CompiledModule {
name: "dummy".to_string(),
name: "dummy_name".to_string(),
kind: ModuleKind::Regular,
object: Some(tmp_file),
bytecode: None,
bytecode_compressed: None,
}],
//modules: vec![],
allocator_module: None,
});
}

View File

@ -23,13 +23,17 @@ pub(crate) fn link_rlib(sess: &Session, res: &CodegenResults, output_name: PathB
let mut builder = ar::Builder::new(file);
// Add main object file
let obj = res.artifact.emit().unwrap();
builder
.append(
&ar::Header::new(b"data.o".to_vec(), obj.len() as u64),
::std::io::Cursor::new(obj),
)
.unwrap();
for module in &res.modules {
if let Some(ref object_path) = module.object {
let object = File::open(object_path).expect("Someone deleted our object file");
let object_len = object.metadata().unwrap().len();
builder.append(
&ar::Header::new((module.name.to_string() + RUST_CGU_EXT).into_bytes(), object_len),
object,
)
.unwrap();
}
}
// Non object files need to be added after object files, because ranlib will
// try to read the native architecture from the first file, even if it isn't
@ -63,10 +67,6 @@ pub(crate) fn link_bin(sess: &Session, codegen_results: &CodegenResults, out_fil
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
};
// TODO: link executable
let obj = codegen_results.artifact.emit().unwrap();
std::fs::write(tmpdir.path().join("out".to_string() + RUST_CGU_EXT), obj).unwrap();
let (linker, flavor) = linker_and_flavor(sess);
let (pname, mut cmd) = get_linker(sess, &linker, flavor);