Replace LinkArgs with Cow<'static, str>

This commit is contained in:
Loïc BRANSTETT 2022-03-28 15:06:46 +02:00
parent ce61d4044d
commit c16a558f24
5 changed files with 12 additions and 11 deletions

View File

@ -40,6 +40,7 @@ use std::ffi::OsString;
use std::fs::{File, OpenOptions};
use std::io::{BufWriter, Write};
use std::lazy::OnceCell;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::process::{ExitStatus, Output, Stdio};
use std::{ascii, char, env, fmt, fs, io, mem, str};
@ -1586,7 +1587,7 @@ fn add_post_link_objects(
/// FIXME: Determine where exactly these args need to be inserted.
fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
if let Some(args) = sess.target.pre_link_args.get(&flavor) {
cmd.args(args);
cmd.args(args.iter().map(Deref::deref));
}
cmd.args(&sess.opts.debugging_opts.pre_link_args);
}
@ -1634,15 +1635,15 @@ fn add_late_link_args(
});
if any_dynamic_crate {
if let Some(args) = sess.target.late_link_args_dynamic.get(&flavor) {
cmd.args(args);
cmd.args(args.iter().map(Deref::deref));
}
} else {
if let Some(args) = sess.target.late_link_args_static.get(&flavor) {
cmd.args(args);
cmd.args(args.iter().map(Deref::deref));
}
}
if let Some(args) = sess.target.late_link_args.get(&flavor) {
cmd.args(args);
cmd.args(args.iter().map(Deref::deref));
}
}
@ -1650,7 +1651,7 @@ fn add_late_link_args(
/// FIXME: Determine where exactly these args need to be inserted.
fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
if let Some(args) = sess.target.post_link_args.get(&flavor) {
cmd.args(args);
cmd.args(args.iter().map(Deref::deref));
}
}

View File

@ -17,7 +17,7 @@ pub fn target(target_cpu: &'static str) -> Target {
linker: Some("avr-gcc".into()),
executables: true,
eh_frame_header: false,
pre_link_args: [(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu)])]
pre_link_args: [(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu).into()])]
.into_iter()
.collect(),
late_link_args: [(LinkerFlavor::Gcc, vec!["-lgcc".into()])].into_iter().collect(),

View File

@ -459,7 +459,7 @@ impl fmt::Display for LinkOutputKind {
}
}
pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<String>>;
pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<Cow<'static, str>>>;
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
pub enum SplitDebuginfo {
@ -1978,7 +1978,7 @@ impl Target {
.map(|(i,s)| {
let s = s.as_string().ok_or_else(||
format!("{}.{}[{}]: expected a JSON string", name, k, i))?;
Ok(s.into())
Ok(s.to_string().into())
})
.collect::<Result<Vec<_>, String>>()?;

View File

@ -5,9 +5,9 @@ use std::collections::BTreeMap;
pub fn options() -> TargetOptions {
let mut lld_args = Vec::new();
let mut clang_args = Vec::new();
let mut arg = |arg: &str| {
let mut arg = |arg: &'static str| {
lld_args.push(arg.into());
clang_args.push(format!("-Wl,{}", arg));
clang_args.push(format!("-Wl,{}", arg).into());
};
// By default LLD only gives us one page of stack (64k) which is a

View File

@ -68,7 +68,7 @@ pub fn target() -> Target {
position_independent_executables: true,
pre_link_args: iter::once((
LinkerFlavor::Lld(LldFlavor::Ld),
PRE_LINK_ARGS.iter().cloned().map(String::from).collect(),
PRE_LINK_ARGS.iter().cloned().map(Cow::from).collect(),
))
.collect(),
override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(Cow::from).collect()),