Compare commits

...

1 Commits

Author SHA1 Message Date
occheung 9573311a0d nac3artiq: generate buffered object 2022-03-22 13:43:09 +08:00
1 changed files with 28 additions and 26 deletions

View File

@ -782,34 +782,36 @@ impl Nac3 {
CodeModel::Default, CodeModel::Default,
) )
.expect("couldn't create target machine"); .expect("couldn't create target machine");
target_machine let object_file = target_machine
.write_to_file(&main, FileType::Object, &working_directory.join("module.o")) .write_to_memory_buffer(&main, FileType::Object)
.expect("couldn't write module to file"); .expect("couldn't write module to object file buffer")
.create_object_file()
.expect("couldn't convert memory buffer into object file");
let mut linker_args = vec![ // let mut linker_args = vec![
"-shared".to_string(), // "-shared".to_string(),
"--eh-frame-hdr".to_string(), // "--eh-frame-hdr".to_string(),
"-x".to_string(), // "-x".to_string(),
"-o".to_string(), // "-o".to_string(),
filename.to_string(), // filename.to_string(),
working_directory.join("module.o").to_string_lossy().to_string(), // working_directory.join("module.o").to_string_lossy().to_string(),
]; // ];
if isa != Isa::Host { // if isa != Isa::Host {
linker_args.push( // linker_args.push(
"-T".to_string() // "-T".to_string()
+ self.working_directory.path().join("kernel.ld").to_str().unwrap(), // + self.working_directory.path().join("kernel.ld").to_str().unwrap(),
); // );
} // }
if let Ok(linker_status) = Command::new("ld.lld").args(linker_args).status() { // if let Ok(linker_status) = Command::new("ld.lld").args(linker_args).status() {
if !linker_status.success() { // if !linker_status.success() {
return Err(CompileError::new_err("failed to start linker")); // return Err(CompileError::new_err("failed to start linker"));
} // }
} else { // } else {
return Err(CompileError::new_err( // return Err(CompileError::new_err(
"linker returned non-zero status code", // "linker returned non-zero status code",
)); // ));
} // }
Ok(()) Ok(())
} }