forked from M-Labs/nac3
nac3artiq: switch ld.lld to nac3ld for non-host target
This commit is contained in:
parent
a96371145d
commit
ac560ba985
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -489,6 +489,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"inkwell",
|
"inkwell",
|
||||||
"nac3core",
|
"nac3core",
|
||||||
|
"nac3ld",
|
||||||
"nac3parser",
|
"nac3parser",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
|
@ -14,6 +14,7 @@ parking_lot = "0.11"
|
|||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
nac3parser = { path = "../nac3parser" }
|
nac3parser = { path = "../nac3parser" }
|
||||||
nac3core = { path = "../nac3core" }
|
nac3core = { path = "../nac3core" }
|
||||||
|
nac3ld = { path = "../nac3ld" }
|
||||||
|
|
||||||
[dependencies.inkwell]
|
[dependencies.inkwell]
|
||||||
git = "https://github.com/TheDan64/inkwell.git"
|
git = "https://github.com/TheDan64/inkwell.git"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io::Write;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -36,6 +37,8 @@ use nac3core::{
|
|||||||
typecheck::{type_inferencer::PrimitiveStore, typedef::Type},
|
typecheck::{type_inferencer::PrimitiveStore, typedef::Type},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use nac3ld::Linker;
|
||||||
|
|
||||||
use tempfile::{self, TempDir};
|
use tempfile::{self, TempDir};
|
||||||
|
|
||||||
use crate::codegen::attributes_writeback;
|
use crate::codegen::attributes_writeback;
|
||||||
@ -854,7 +857,7 @@ impl Nac3 {
|
|||||||
Isa::RiscV32IMA => (TargetTriple::create("riscv32-unknown-linux"), "+a,+m".to_string()),
|
Isa::RiscV32IMA => (TargetTriple::create("riscv32-unknown-linux"), "+a,+m".to_string()),
|
||||||
Isa::CortexA9 => (
|
Isa::CortexA9 => (
|
||||||
TargetTriple::create("armv7-unknown-linux-gnueabihf"),
|
TargetTriple::create("armv7-unknown-linux-gnueabihf"),
|
||||||
"+dsp,+fp16,+neon,+vfp3".to_string(),
|
"+dsp,+fp16,+neon,+vfp3,+long-calls".to_string(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
let target =
|
let target =
|
||||||
@ -869,11 +872,12 @@ impl Nac3 {
|
|||||||
CodeModel::Default,
|
CodeModel::Default,
|
||||||
)
|
)
|
||||||
.expect("couldn't create target machine");
|
.expect("couldn't create target machine");
|
||||||
|
|
||||||
|
if isa == Isa::Host {
|
||||||
target_machine
|
target_machine
|
||||||
.write_to_file(&main, FileType::Object, &working_directory.join("module.o"))
|
.write_to_file(&main, FileType::Object, &working_directory.join("module.o"))
|
||||||
.expect("couldn't write module to file");
|
.expect("couldn't write module to file");
|
||||||
|
let 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(),
|
||||||
@ -881,12 +885,6 @@ impl Nac3 {
|
|||||||
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 {
|
|
||||||
linker_args.push(
|
|
||||||
"-T".to_string()
|
|
||||||
+ self.working_directory.path().join("kernel.ld").to_str().unwrap(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
let lld_command = "ld.lld";
|
let lld_command = "ld.lld";
|
||||||
@ -901,6 +899,20 @@ impl Nac3 {
|
|||||||
"linker returned non-zero status code",
|
"linker returned non-zero status code",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
let object_mem = target_machine
|
||||||
|
.write_to_memory_buffer(&main, FileType::Object)
|
||||||
|
.expect("couldn't write module to object file buffer");
|
||||||
|
if let Ok(dyn_lib) = Linker::ld(object_mem.as_slice()) {
|
||||||
|
if let Ok(mut file) = fs::File::create(filename) {
|
||||||
|
file.write_all(&dyn_lib).expect("couldn't write linked library to file");
|
||||||
|
} else {
|
||||||
|
return Err(CompileError::new_err("failed to create file"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(CompileError::new_err("linker failed to process object file"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user