Skip to content

Commit ce52e0e

Browse files
committed
rustc: Tweak default linker selection
This commit refactors how the path to the linker that we're going to invoke is selected. Previously all targets listed *both* a `LinkerFlavor` and a `linker` (path) option, but this meant that whenever you changed one you had to change the other. The purpose of this commit is to avoid coupling these where possible. Target specifications now only unconditionally define the *flavor* of the linker that they're using by default. If not otherwise specified each flavor now implies a particular default linker to run. As a result, this means that if you'd like to test out `ld` for example you should be able to do: rustc -Z linker-flavor=ld foo.rs whereas previously you had to do rustc -Z linker-flavor=ld -C linker=ld foo.rs This will hopefully make it a bit easier to tinker around with variants that should otherwise be well known to work, for example with LLD, `ld` on OSX, etc.
1 parent 50642c8 commit ce52e0e

24 files changed

+56
-101
lines changed

src/librustc_back/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ pub enum LinkerFlavor {
5757
RustcEncodable, RustcDecodable)]
5858
pub enum LldFlavor {
5959
Wasm,
60+
Ld64,
61+
Ld,
62+
Link,
6063
}
6164

6265
impl ToJson for LinkerFlavor {
@@ -94,6 +97,9 @@ flavor_mappings! {
9497
((LinkerFlavor::Ld), "ld"),
9598
((LinkerFlavor::Msvc), "msvc"),
9699
((LinkerFlavor::Lld(LldFlavor::Wasm)), "wasm-ld"),
100+
((LinkerFlavor::Lld(LldFlavor::Ld64)), "ld64.lld"),
101+
((LinkerFlavor::Lld(LldFlavor::Ld)), "ld.lld"),
102+
((LinkerFlavor::Lld(LldFlavor::Link)), "lld-link"),
97103
}
98104

99105
#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]

src/librustc_back/target/aarch64_unknown_cloudabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn target() -> TargetResult {
1515
let mut base = super::cloudabi_base::opts();
1616
base.max_atomic_width = Some(128);
1717
base.abi_blacklist = super::arm_base::abi_blacklist();
18-
base.linker = "aarch64-unknown-cloudabi-cc".to_string();
18+
base.linker = Some("aarch64-unknown-cloudabi-cc".to_string());
1919

2020
Ok(Target {
2121
llvm_target: "aarch64-unknown-cloudabi".to_string(),

src/librustc_back/target/armv7_unknown_cloudabi_eabihf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn target() -> TargetResult {
1717
base.max_atomic_width = Some(64);
1818
base.features = "+v7,+vfp3,+neon".to_string();
1919
base.abi_blacklist = super::arm_base::abi_blacklist();
20-
base.linker = "armv7-unknown-cloudabi-eabihf-cc".to_string();
20+
base.linker = Some("armv7-unknown-cloudabi-eabihf-cc".to_string());
2121

2222
Ok(Target {
2323
llvm_target: "armv7-unknown-cloudabi-eabihf".to_string(),

src/librustc_back/target/asmjs_unknown_emscripten.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use LinkerFlavor;
1212
use super::{LinkArgs, Target, TargetOptions};
13-
use super::emscripten_base::{cmd};
1413

1514
pub fn target() -> Result<Target, String> {
1615
let mut args = LinkArgs::new();
@@ -19,8 +18,6 @@ pub fn target() -> Result<Target, String> {
1918
"ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()]);
2019

2120
let opts = TargetOptions {
22-
linker: cmd("emcc"),
23-
2421
dynamic_linking: false,
2522
executables: true,
2623
exe_suffix: ".js".to_string(),

src/librustc_back/target/emscripten_base.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/librustc_back/target/haiku_base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::default::Default;
1313

1414
pub fn opts() -> TargetOptions {
1515
TargetOptions {
16-
linker: "cc".to_string(),
1716
dynamic_linking: true,
1817
executables: true,
1918
has_rpath: false,

src/librustc_back/target/i686_unknown_cloudabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn target() -> TargetResult {
1515
let mut base = super::cloudabi_base::opts();
1616
base.cpu = "pentium4".to_string();
1717
base.max_atomic_width = Some(64);
18-
base.linker = "i686-unknown-cloudabi-cc".to_string();
18+
base.linker = Some("i686-unknown-cloudabi-cc".to_string());
1919
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string());
2020
base.stack_probes = true;
2121

src/librustc_back/target/l4re_base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ pub fn opts() -> Result<TargetOptions, String> {
7373
has_elf_tls: false,
7474
exe_allocation_crate: None,
7575
panic_strategy: PanicStrategy::Abort,
76-
linker: "ld".to_string(),
7776
pre_link_args,
7877
post_link_args,
7978
target_family: Some("unix".to_string()),

src/librustc_back/target/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ mod arm_base;
5858
mod bitrig_base;
5959
mod cloudabi_base;
6060
mod dragonfly_base;
61-
mod emscripten_base;
6261
mod freebsd_base;
6362
mod haiku_base;
6463
mod linux_base;
@@ -276,8 +275,8 @@ pub struct TargetOptions {
276275
/// Whether the target is built-in or loaded from a custom target specification.
277276
pub is_builtin: bool,
278277

279-
/// Linker to invoke. Defaults to "cc".
280-
pub linker: String,
278+
/// Linker to invoke
279+
pub linker: Option<String>,
281280

282281
/// Linker arguments that are unconditionally passed *before* any
283282
/// user-defined libraries.
@@ -480,7 +479,7 @@ impl Default for TargetOptions {
480479
fn default() -> TargetOptions {
481480
TargetOptions {
482481
is_builtin: false,
483-
linker: option_env!("CFG_DEFAULT_LINKER").unwrap_or("cc").to_string(),
482+
linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.to_string()),
484483
pre_link_args: LinkArgs::new(),
485484
post_link_args: LinkArgs::new(),
486485
asm_args: Vec::new(),
@@ -730,7 +729,7 @@ impl Target {
730729
}
731730

732731
key!(is_builtin, bool);
733-
key!(linker);
732+
key!(linker, optional);
734733
key!(pre_link_args, link_args);
735734
key!(pre_link_objects_exe, list);
736735
key!(pre_link_objects_dll, list);

src/librustc_back/target/msp430_none_elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn target() -> TargetResult {
3232
// to gcc to get object files. For this reason we have a hard
3333
// dependency on this specific gcc.
3434
asm_args: vec!["-mcpu=msp430".to_string()],
35-
linker: "msp430-elf-gcc".to_string(),
35+
linker: Some("msp430-elf-gcc".to_string()),
3636
no_integrated_as: true,
3737

3838
// There are no atomic instructions available in the MSP430

0 commit comments

Comments
 (0)