Simplify implementation of -Z gcc-ld
- The logic is now unified for all targets (wasm targets should also be supported now) - Additional "symlink" files like `ld64` are eliminated - lld-wrapper is used for propagating the correct lld flavor - Cleanup "unwrap or exit" logic in lld-wrapper
This commit is contained in:
parent
1b5e1215ef
commit
2984bf674f
8 changed files with 71 additions and 122 deletions
|
@ -105,12 +105,7 @@ impl Command {
|
|||
}
|
||||
Program::Lld(ref p, flavor) => {
|
||||
let mut c = process::Command::new(p);
|
||||
c.arg("-flavor").arg(match flavor {
|
||||
LldFlavor::Wasm => "wasm",
|
||||
LldFlavor::Ld => "gnu",
|
||||
LldFlavor::Link => "link",
|
||||
LldFlavor::Ld64 => "darwin",
|
||||
});
|
||||
c.arg("-flavor").arg(flavor.as_str());
|
||||
if let LldFlavor::Wasm = flavor {
|
||||
// LLVM expects host-specific formatting for @file
|
||||
// arguments, but we always generate posix formatted files
|
||||
|
|
|
@ -2698,37 +2698,20 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
|||
if let LinkerFlavor::Gcc = flavor {
|
||||
match ld_impl {
|
||||
LdImpl::Lld => {
|
||||
if sess.target.lld_flavor == LldFlavor::Ld64 {
|
||||
let tools_path = sess.get_tools_search_paths(false);
|
||||
let ld64_exe = tools_path
|
||||
.into_iter()
|
||||
.map(|p| p.join("gcc-ld"))
|
||||
.map(|p| {
|
||||
p.join(if sess.host.is_like_windows { "ld64.exe" } else { "ld64" })
|
||||
})
|
||||
.find(|p| p.exists())
|
||||
.unwrap_or_else(|| sess.fatal("rust-lld (as ld64) not found"));
|
||||
cmd.cmd().arg({
|
||||
let mut arg = OsString::from("-fuse-ld=");
|
||||
arg.push(ld64_exe);
|
||||
arg
|
||||
});
|
||||
} else {
|
||||
let tools_path = sess.get_tools_search_paths(false);
|
||||
let lld_path = tools_path
|
||||
.into_iter()
|
||||
.map(|p| p.join("gcc-ld"))
|
||||
.find(|p| {
|
||||
p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" })
|
||||
.exists()
|
||||
})
|
||||
.unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found"));
|
||||
cmd.cmd().arg({
|
||||
let mut arg = OsString::from("-B");
|
||||
arg.push(lld_path);
|
||||
arg
|
||||
});
|
||||
}
|
||||
let tools_path = sess.get_tools_search_paths(false);
|
||||
let gcc_ld_dir = tools_path
|
||||
.into_iter()
|
||||
.map(|p| p.join("gcc-ld"))
|
||||
.find(|p| {
|
||||
p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" }).exists()
|
||||
})
|
||||
.unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found"));
|
||||
cmd.arg({
|
||||
let mut arg = OsString::from("-B");
|
||||
arg.push(gcc_ld_dir);
|
||||
arg
|
||||
});
|
||||
cmd.arg(format!("-Wl,-rustc-lld-flavor={}", sess.target.lld_flavor.as_str()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -108,6 +108,15 @@ pub enum LldFlavor {
|
|||
}
|
||||
|
||||
impl LldFlavor {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
LldFlavor::Wasm => "wasm",
|
||||
LldFlavor::Ld64 => "darwin",
|
||||
LldFlavor::Ld => "gnu",
|
||||
LldFlavor::Link => "link",
|
||||
}
|
||||
}
|
||||
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
Some(match s {
|
||||
"darwin" => LldFlavor::Ld64,
|
||||
|
@ -121,13 +130,7 @@ impl LldFlavor {
|
|||
|
||||
impl ToJson for LldFlavor {
|
||||
fn to_json(&self) -> Json {
|
||||
match *self {
|
||||
LldFlavor::Ld64 => "darwin",
|
||||
LldFlavor::Ld => "gnu",
|
||||
LldFlavor::Link => "link",
|
||||
LldFlavor::Wasm => "wasm",
|
||||
}
|
||||
.to_json()
|
||||
self.as_str().to_json()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue