mirror of
https://github.com/rui314/mold.git
synced 2026-11-09 04:49:33 -10:00
Borrow canonical target names from static storage
This commit is contained in:
1 parent
dc127e5280
commit
9b051c1d43
24 files changed
+33
-33
No files matched your search
+2
-2
@@ -9,7 +9,7 @@
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
type LinkFn = fn(&[std::ffi::OsString]) -> Result<i32, String>;
|
||||
type LinkFn = fn(&[std::ffi::OsString]) -> Result<i32, &'static str>;
|
||||
|
||||
// Each target has its own monomorphized link function. Start with the first
|
||||
// enabled target and switch to the matching function if the inputs differ.
|
||||
@@ -56,7 +56,7 @@ const TARGETS: &[(&str, LinkFn)] = &[
|
||||
("loongarch32", mold_target_loongarch32::link),
|
||||
];
|
||||
|
||||
fn link_for_target(target: &str, cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
fn link_for_target(target: &str, cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
for &(name, link) in TARGETS {
|
||||
if name == target {
|
||||
return link(cmdline);
|
||||
|
||||
+3
-3
@@ -522,7 +522,7 @@ pub struct Args {
|
||||
pub separate_debug_file: PathBuf,
|
||||
pub soname: OsString,
|
||||
pub sysroot: PathBuf,
|
||||
pub emulation: String,
|
||||
pub emulation: &'static str,
|
||||
pub section_align: HashMap<Vec<u8>, u64>,
|
||||
pub section_start: HashMap<Vec<u8>, u64>,
|
||||
pub discard_section: HashSet<Vec<u8>>,
|
||||
@@ -665,7 +665,7 @@ impl Default for Args {
|
||||
separate_debug_file: PathBuf::new(),
|
||||
soname: OsString::new(),
|
||||
sysroot: PathBuf::new(),
|
||||
emulation: String::new(),
|
||||
emulation: "",
|
||||
section_align: HashMap::new(),
|
||||
section_start: HashMap::new(),
|
||||
discard_section: HashSet::new(),
|
||||
@@ -1239,7 +1239,7 @@ pub fn parse_args(target: &TargetTraits, raw_cmdline: &[OsString]) -> ParsedArgs
|
||||
a.plugin_opt.push(raw_arg.as_encoded_bytes().to_vec());
|
||||
} else if read_arg!("m") {
|
||||
match arch::emulation_to_target(&arg) {
|
||||
Some(name) => a.emulation = name.to_string(),
|
||||
Some(name) => a.emulation = name,
|
||||
None => fatal!("unknown -m argument: {arg}"),
|
||||
}
|
||||
} else if read_flag!("end-lib") {
|
||||
|
||||
+5
-5
@@ -24,7 +24,7 @@ use crate::{error, fatal, passes};
|
||||
pub fn main(
|
||||
argv: Vec<std::ffi::OsString>,
|
||||
initial_target: &str,
|
||||
link_for_target: impl Fn(&str, &[std::ffi::OsString]) -> Result<i32, String>,
|
||||
link_for_target: impl Fn(&str, &[std::ffi::OsString]) -> Result<i32, &'static str>,
|
||||
) -> i32 {
|
||||
// A parent's transparent huge page disable flag is inherited. Restore
|
||||
// the system's default policy so large links can use huge pages.
|
||||
@@ -49,12 +49,12 @@ pub fn main(
|
||||
|
||||
// Parse with an enabled target's defaults; if the target turns out to
|
||||
// be different, start over with the right one.
|
||||
let mut target = initial_target.to_string();
|
||||
let mut target = initial_target;
|
||||
loop {
|
||||
if let Some(cwd) = &orig_cwd {
|
||||
let _ = std::env::set_current_dir(cwd);
|
||||
}
|
||||
match link_for_target(&target, &cmdline) {
|
||||
match link_for_target(target, &cmdline) {
|
||||
Ok(status) => return status,
|
||||
Err(actual) => target = actual,
|
||||
}
|
||||
@@ -99,7 +99,7 @@ fn wait_for_background<T>(receiver: mpsc::Receiver<T>, name: &str) -> T {
|
||||
|
||||
/// Links for the target `E`, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link<E: Arch>(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link<E: Arch>(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
let parsed = cmdline::parse_args(&target_traits::<E>(), cmdline);
|
||||
let cmdline::ParsedArgs { args, jobs, .. } = parsed;
|
||||
let mut ctx = Context::<E>::new(args, cmdline.to_vec());
|
||||
@@ -111,7 +111,7 @@ pub fn link<E: Arch>(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
|
||||
// Redo if -m does not match with our speculation.
|
||||
if ctx.args.emulation != E::NAME {
|
||||
return Err(ctx.args.emulation.clone());
|
||||
return Err(ctx.args.emulation);
|
||||
}
|
||||
|
||||
let t_all = ctx.timer("all");
|
||||
|
||||
+3
-3
@@ -221,7 +221,7 @@ fn push_loaded<E: Arch>(ctx: &mut Context<E>, loaded: Loaded<E>) {
|
||||
}
|
||||
|
||||
/// Deduces the target from the first recognizable input file.
|
||||
pub fn detect_machine_type<E: Arch>(ctx: &mut Context<E>, jobs: &[ReaderJob]) -> String {
|
||||
pub fn detect_machine_type<E: Arch>(ctx: &mut Context<E>, jobs: &[ReaderJob]) -> &'static str {
|
||||
for job in jobs {
|
||||
if job.is_lib {
|
||||
continue;
|
||||
@@ -229,7 +229,7 @@ pub fn detect_machine_type<E: Arch>(ctx: &mut Context<E>, jobs: &[ReaderJob]) ->
|
||||
if let Some(mf) = open_file(&ctx.args.chroot, &job.name) {
|
||||
if get_file_type(ctx, mf) != FileType::Text {
|
||||
if let Some(target) = filetype::get_machine_type(&ctx.args.plugin, mf, || None) {
|
||||
return target.to_string();
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,7 @@ pub fn detect_machine_type<E: Arch>(ctx: &mut Context<E>, jobs: &[ReaderJob]) ->
|
||||
if let Some(mf) = open_file(&ctx.args.chroot, &job.name) {
|
||||
if get_file_type(ctx, mf) == FileType::Text {
|
||||
if let Some(target) = crate::linker_script::output_target(ctx, &job.rctx, mf) {
|
||||
return target.to_string();
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Arm32>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Arm32Be>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Arm64>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Arm64Be>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::I386>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::LoongArch32>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::LoongArch64>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::M68k>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Ppc32>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Ppc64V1>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Ppc64V2>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Riscv32>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Riscv32Be>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Riscv64>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Riscv64Be>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::S390x>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Sh4>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Sh4Be>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::Sparc64>(cmdline)
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
/// Links for this target, or reports the target the inputs are actually
|
||||
/// for.
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, String> {
|
||||
pub fn link(cmdline: &[std::ffi::OsString]) -> Result<i32, &'static str> {
|
||||
mold::driver::link::<mold::arch::X86_64>(cmdline)
|
||||
}
|
||||
Reference in new issue
Block a user