Skip to content

Commit

Permalink
Renamed lld_link_script to link_script and support all GNU-like linkers
Browse files Browse the repository at this point in the history
  • Loading branch information
overdrivenpotato committed May 10, 2020
1 parent 7e62240 commit 7b649c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
19 changes: 9 additions & 10 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,20 +1179,19 @@ fn add_pre_link_args(
cmd.args(&sess.opts.debugging_opts.pre_link_args);
}

/// Add an LLD link script embedded in the target, if applicable.
fn add_lld_link_script(
/// Add a link script embedded in the target, if applicable.
fn add_link_script(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
tmpdir: &Path,
crate_type: CrateType,
) {
match (flavor, crate_type, &sess.target.target.options.lld_link_script) {
(
LinkerFlavor::Lld(LldFlavor::Ld),
CrateType::Cdylib | CrateType::Executable,
Some(script),
) => {
match (crate_type, &sess.target.target.options.link_script) {
(CrateType::Cdylib | CrateType::Executable, Some(script)) => {
if !sess.target.target.options.linker_is_gnu {
sess.fatal("can only use link script when linking with GNU-like linker");
}

let file_name = ["rustc", &sess.target.target.llvm_target, "linkfile.ld"].join("-");

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

// NO-OPT-OUT
add_lld_link_script(cmd, sess, flavor, tmpdir, crate_type);
add_link_script(cmd, sess, tmpdir, crate_type);

// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
if sess.target.target.options.is_like_fuchsia {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_target/spec/mipsel_sony_psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn target() -> TargetResult {
cpu: "mips2".to_string(),
executables: true,
linker: Some("rust-lld".to_owned()),
linker_is_gnu: true,
relocation_model: RelocModel::Static,

// PSP FPU only supports single precision floats.
Expand All @@ -35,7 +36,7 @@ pub fn target() -> TargetResult {
// PSP does not support trap-on-condition instructions.
llvm_args: vec!["-mno-check-zero-division".to_string()],
pre_link_args,
lld_link_script: Some(LINKER_SCRIPT.to_string()),
link_script: Some(LINKER_SCRIPT.to_string()),
..Default::default()
},
})
Expand Down
13 changes: 7 additions & 6 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,10 @@ pub struct TargetOptions {
/// Linker arguments that are unconditionally passed *after* any
/// user-defined libraries.
pub post_link_args: LinkArgs,
/// Optional LLD link script applied to `dylib` and `executable` crate
/// types. This is a string containing the script, not a path.
pub lld_link_script: Option<String>,
/// Optional link script applied to `dylib` and `executable` crate types.
/// This is a string containing the script, not a path. Can only be applied
/// to linkers where `linker_is_gnu` is true.
pub link_script: Option<String>,

/// Environment variables to be set for the linker invocation.
pub link_env: Vec<(String, String)>,
Expand Down Expand Up @@ -900,7 +901,7 @@ impl Default for TargetOptions {
pre_link_args: LinkArgs::new(),
pre_link_args_crt: LinkArgs::new(),
post_link_args: LinkArgs::new(),
lld_link_script: None,
link_script: None,
asm_args: Vec::new(),
cpu: "generic".to_string(),
features: String::new(),
Expand Down Expand Up @@ -1250,7 +1251,7 @@ impl Target {
key!(post_link_objects, list);
key!(post_link_objects_crt, list);
key!(post_link_args, link_args);
key!(lld_link_script, optional);
key!(link_script, optional);
key!(link_env, env);
key!(link_env_remove, list);
key!(asm_args, list);
Expand Down Expand Up @@ -1480,7 +1481,7 @@ impl ToJson for Target {
target_option_val!(post_link_objects);
target_option_val!(post_link_objects_crt);
target_option_val!(link_args - post_link_args);
target_option_val!(lld_link_script);
target_option_val!(link_script);
target_option_val!(env - link_env);
target_option_val!(link_env_remove);
target_option_val!(asm_args);
Expand Down

0 comments on commit 7b649c7

Please sign in to comment.