Skip to content

Commit 7b649c7

Browse files
Renamed lld_link_script to link_script and support all GNU-like linkers
1 parent 7e62240 commit 7b649c7

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/librustc_codegen_ssa/back/link.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,20 +1179,19 @@ fn add_pre_link_args(
11791179
cmd.args(&sess.opts.debugging_opts.pre_link_args);
11801180
}
11811181

1182-
/// Add an LLD link script embedded in the target, if applicable.
1183-
fn add_lld_link_script(
1182+
/// Add a link script embedded in the target, if applicable.
1183+
fn add_link_script(
11841184
cmd: &mut dyn Linker,
11851185
sess: &Session,
1186-
flavor: LinkerFlavor,
11871186
tmpdir: &Path,
11881187
crate_type: CrateType,
11891188
) {
1190-
match (flavor, crate_type, &sess.target.target.options.lld_link_script) {
1191-
(
1192-
LinkerFlavor::Lld(LldFlavor::Ld),
1193-
CrateType::Cdylib | CrateType::Executable,
1194-
Some(script),
1195-
) => {
1189+
match (crate_type, &sess.target.target.options.link_script) {
1190+
(CrateType::Cdylib | CrateType::Executable, Some(script)) => {
1191+
if !sess.target.target.options.linker_is_gnu {
1192+
sess.fatal("can only use link script when linking with GNU-like linker");
1193+
}
1194+
11961195
let file_name = ["rustc", &sess.target.target.llvm_target, "linkfile.ld"].join("-");
11971196

11981197
let path = tmpdir.join(file_name);
@@ -1450,7 +1449,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
14501449
add_pre_link_args(cmd, sess, flavor, crate_type);
14511450

14521451
// NO-OPT-OUT
1453-
add_lld_link_script(cmd, sess, flavor, tmpdir, crate_type);
1452+
add_link_script(cmd, sess, tmpdir, crate_type);
14541453

14551454
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
14561455
if sess.target.target.options.is_like_fuchsia {

src/librustc_target/spec/mipsel_sony_psp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn target() -> TargetResult {
2727
cpu: "mips2".to_string(),
2828
executables: true,
2929
linker: Some("rust-lld".to_owned()),
30+
linker_is_gnu: true,
3031
relocation_model: RelocModel::Static,
3132

3233
// PSP FPU only supports single precision floats.
@@ -35,7 +36,7 @@ pub fn target() -> TargetResult {
3536
// PSP does not support trap-on-condition instructions.
3637
llvm_args: vec!["-mno-check-zero-division".to_string()],
3738
pre_link_args,
38-
lld_link_script: Some(LINKER_SCRIPT.to_string()),
39+
link_script: Some(LINKER_SCRIPT.to_string()),
3940
..Default::default()
4041
},
4142
})

src/librustc_target/spec/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,10 @@ pub struct TargetOptions {
668668
/// Linker arguments that are unconditionally passed *after* any
669669
/// user-defined libraries.
670670
pub post_link_args: LinkArgs,
671-
/// Optional LLD link script applied to `dylib` and `executable` crate
672-
/// types. This is a string containing the script, not a path.
673-
pub lld_link_script: Option<String>,
671+
/// Optional link script applied to `dylib` and `executable` crate types.
672+
/// This is a string containing the script, not a path. Can only be applied
673+
/// to linkers where `linker_is_gnu` is true.
674+
pub link_script: Option<String>,
674675

675676
/// Environment variables to be set for the linker invocation.
676677
pub link_env: Vec<(String, String)>,
@@ -900,7 +901,7 @@ impl Default for TargetOptions {
900901
pre_link_args: LinkArgs::new(),
901902
pre_link_args_crt: LinkArgs::new(),
902903
post_link_args: LinkArgs::new(),
903-
lld_link_script: None,
904+
link_script: None,
904905
asm_args: Vec::new(),
905906
cpu: "generic".to_string(),
906907
features: String::new(),
@@ -1250,7 +1251,7 @@ impl Target {
12501251
key!(post_link_objects, list);
12511252
key!(post_link_objects_crt, list);
12521253
key!(post_link_args, link_args);
1253-
key!(lld_link_script, optional);
1254+
key!(link_script, optional);
12541255
key!(link_env, env);
12551256
key!(link_env_remove, list);
12561257
key!(asm_args, list);
@@ -1480,7 +1481,7 @@ impl ToJson for Target {
14801481
target_option_val!(post_link_objects);
14811482
target_option_val!(post_link_objects_crt);
14821483
target_option_val!(link_args - post_link_args);
1483-
target_option_val!(lld_link_script);
1484+
target_option_val!(link_script);
14841485
target_option_val!(env - link_env);
14851486
target_option_val!(link_env_remove);
14861487
target_option_val!(asm_args);

0 commit comments

Comments
 (0)