Skip to content

Commit ccf8c44

Browse files
committed
Auto merge of #41971 - japaric:pre-link-args, r=alexcrichton
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]: rust-embedded/wg#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
2 parents 0ed1ec9 + 94d2c43 commit ccf8c44

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/librustc/session/config.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
824824
linker: Option<String> = (None, parse_opt_string, [UNTRACKED],
825825
"system linker to link outputs with"),
826826
link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
827-
"a single extra argument to pass to the linker (can be used several times)"),
827+
"a single extra argument to append to the linker invocation (can be used several times)"),
828828
link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
829-
"extra arguments to pass to the linker (space separated)"),
829+
"extra arguments to append to the linker invocation (space separated)"),
830830
link_dead_code: bool = (false, parse_bool, [UNTRACKED],
831831
"don't let linker strip dead code (turning it on can be used for code coverage)"),
832832
lto: bool = (false, parse_bool, [TRACKED],
@@ -1029,6 +1029,10 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10291029
"add a mapping target to the file path remapping config"),
10301030
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
10311031
"force all crates to be `rustc_private` unstable"),
1032+
pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
1033+
"a single extra argument to prepend the linker invocation (can be used several times)"),
1034+
pre_link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
1035+
"extra arguments to prepend to the linker invocation (space separated)"),
10321036
}
10331037

10341038
pub fn default_lib_output() -> CrateType {

src/librustc_trans/back/link.rs

+4
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ fn link_natively(sess: &Session,
715715
if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
716716
cmd.args(args);
717717
}
718+
if let Some(ref args) = sess.opts.debugging_opts.pre_link_args {
719+
cmd.args(args);
720+
}
721+
cmd.args(&sess.opts.debugging_opts.pre_link_arg);
718722

719723
let pre_link_objects = if crate_type == config::CrateTypeExecutable {
720724
&sess.target.target.options.pre_link_objects_exe

0 commit comments

Comments
 (0)