]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #41971 - japaric:pre-link-args, r=alexcrichton
authorMark Simulacrum <mark.simulacrum@gmail.com>
Fri, 19 May 2017 20:16:14 +0000 (14:16 -0600)
committerGitHub <noreply@github.com>
Fri, 19 May 2017 20:16:14 +0000 (14:16 -0600)
add -Z pre-link-arg{,s} to rustc

This PR adds two unstable flags to `rustc`: `-Z pre-link-arg` and `-Z
pre-link-args`. These are the counterpart of the existing `-C link-arg{,s}`
flags and can be used to pass extra arguments at the *beginning* of the linker
invocation, before the Rust object files are passed.

I have [started] a discussion on the rust-embedded RFCs repo about settling on a
convention for passing extra arguments to the linker and there are two options
on discussion: `.cargo/config`'s `target.$T.rustflags` and custom target
specification files (`{pre,,post}-link-args` fields). However, to compare these
two options on equal footing this `-Z pre-link-arg` feature is required.

[started]: https://github.com/rust-embedded/rfcs/pull/24

Therefore I'm requesting landing this `-Z pre-link-arg` flag as an experimental
feature to evaluate these two options.

cc @brson
r? @alexcrichton

src/librustc/session/config.rs
src/librustc_trans/back/link.rs

index e3b43b3290fc9e4994c080464bf6a6a909aacca1..7cb5f2510d5c7acdc363048165bca73f44d2d85d 100644 (file)
@@ -824,9 +824,9 @@ fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) ->
     linker: Option<String> = (None, parse_opt_string, [UNTRACKED],
         "system linker to link outputs with"),
     link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
-        "a single extra argument to pass to the linker (can be used several times)"),
+        "a single extra argument to append to the linker invocation (can be used several times)"),
     link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
-        "extra arguments to pass to the linker (space separated)"),
+        "extra arguments to append to the linker invocation (space separated)"),
     link_dead_code: bool = (false, parse_bool, [UNTRACKED],
         "don't let linker strip dead code (turning it on can be used for code coverage)"),
     lto: bool = (false, parse_bool, [TRACKED],
@@ -1029,6 +1029,10 @@ fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) ->
         "add a mapping target to the file path remapping config"),
     force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
         "force all crates to be `rustc_private` unstable"),
+    pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
+        "a single extra argument to prepend the linker invocation (can be used several times)"),
+    pre_link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
+        "extra arguments to prepend to the linker invocation (space separated)"),
 }
 
 pub fn default_lib_output() -> CrateType {
index b8aabef65a984adf76c8364ba0337797460ee009..f85d3f9f54dfd7cd8b63ad152089bfa10e10eca0 100644 (file)
@@ -715,6 +715,10 @@ fn link_natively(sess: &Session,
     if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
         cmd.args(args);
     }
+    if let Some(ref args) = sess.opts.debugging_opts.pre_link_args {
+        cmd.args(args);
+    }
+    cmd.args(&sess.opts.debugging_opts.pre_link_arg);
 
     let pre_link_objects = if crate_type == config::CrateTypeExecutable {
         &sess.target.target.options.pre_link_objects_exe