Skip to content

Commit cd626fe

Browse files
committed
Stabilize -Z print-link-args as --print link-args
We have stable options for adding linker arguments; we should have a stable option to help debug linker arguments.
1 parent 0fb1c37 commit cd626fe

File tree

12 files changed

+18
-17
lines changed

12 files changed

+18
-17
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
722722
cmd.env_remove(k);
723723
}
724724

725-
if sess.opts.debugging_opts.print_link_args {
725+
if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
726726
println!("{:?}", &cmd);
727727
}
728728

compiler/rustc_driver/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,9 @@ impl RustcDefaultCalls {
652652
temps_dir: &Option<PathBuf>,
653653
) -> Compilation {
654654
use rustc_session::config::PrintRequest::*;
655-
// PrintRequest::NativeStaticLibs is special - printed during linking
655+
// NativeStaticLibs and LinkArgs are special - printed during linking
656656
// (empty iterator returns true)
657-
if sess.opts.prints.iter().all(|&p| p == PrintRequest::NativeStaticLibs) {
657+
if sess.opts.prints.iter().all(|&p| p == NativeStaticLibs || p == LinkArgs) {
658658
return Compilation::Continue;
659659
}
660660

@@ -745,7 +745,8 @@ impl RustcDefaultCalls {
745745
codegen_backend.print(*req, sess);
746746
}
747747
// Any output here interferes with Cargo's parsing of other printed output
748-
PrintRequest::NativeStaticLibs => {}
748+
NativeStaticLibs => {}
749+
LinkArgs => {}
749750
}
750751
}
751752
Compilation::Stop

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ fn test_debugging_options_tracking_hash() {
675675
// `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
676676
untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
677677
untracked!(profile_closures, true);
678-
untracked!(print_link_args, true);
679678
untracked!(print_llvm_passes, true);
680679
untracked!(print_mono_items, Some(String::from("abc")));
681680
untracked!(print_type_sizes, true);

compiler/rustc_session/src/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ pub enum PrintRequest {
534534
TargetSpec,
535535
NativeStaticLibs,
536536
StackProtectorStrategies,
537+
LinkArgs,
537538
}
538539

539540
#[derive(Copy, Clone)]
@@ -1115,7 +1116,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
11151116
"Compiler information to print on stdout",
11161117
"[crate-name|file-names|sysroot|target-libdir|cfg|target-list|\
11171118
target-cpus|target-features|relocation-models|code-models|\
1118-
tls-models|target-spec-json|native-static-libs|stack-protector-strategies]",
1119+
tls-models|target-spec-json|native-static-libs|stack-protector-strategies\
1120+
link-args]",
11191121
),
11201122
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
11211123
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
@@ -1547,6 +1549,7 @@ fn collect_print_requests(
15471549
);
15481550
}
15491551
}
1552+
"link-args" => PrintRequest::LinkArgs,
15501553
req => early_error(error_format, &format!("unknown print request `{}`", req)),
15511554
}));
15521555

compiler/rustc_session/src/options.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,6 @@ options! {
12941294
See #77382 and #74551."),
12951295
print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
12961296
"make rustc print the total optimization fuel used by a crate"),
1297-
print_link_args: bool = (false, parse_bool, [UNTRACKED],
1298-
"print the arguments passed to the linker (default: no)"),
12991297
print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
13001298
"print the LLVM optimization passes being run (default: no)"),
13011299
print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],

src/test/run-make-fulldeps/codegen-options-parsing/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ all:
2424
$(RUSTC) -C lto dummy.rs
2525

2626
# Should not link dead code...
27-
$(RUSTC) -Z print-link-args dummy.rs 2>&1 | \
27+
$(RUSTC) --print link-args dummy.rs 2>&1 | \
2828
$(CGREP) -e '--gc-sections|-z[^ ]* [^ ]*<ignore>|-dead_strip|/OPT:REF'
2929
# ... unless you specifically ask to keep it
30-
$(RUSTC) -Z print-link-args -C link-dead-code dummy.rs 2>&1 | \
30+
$(RUSTC) --print link-args -C link-dead-code dummy.rs 2>&1 | \
3131
$(CGREP) -ve '--gc-sections|-z[^ ]* [^ ]*<ignore>|-dead_strip|/OPT:REF'

src/test/run-make-fulldeps/interdependent-c-libraries/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar)
1212
$(RUSTC) foo.rs
1313
$(RUSTC) bar.rs
14-
$(RUSTC) main.rs -Z print-link-args
14+
$(RUSTC) main.rs --print link-args
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-include ../tools.mk
2-
RUSTC_FLAGS = -C link-arg="-lfoo" -C link-arg="-lbar" -Z print-link-args
2+
RUSTC_FLAGS = -C link-arg="-lfoo" -C link-arg="-lbar" --print link-args
33

44
all:
55
$(RUSTC) $(RUSTC_FLAGS) empty.rs | $(CGREP) lfoo lbar

src/test/run-make-fulldeps/metadata-flag-frobs-symbols/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ all:
66
$(RUSTC) bar.rs \
77
--extern foo1=$(TMPDIR)/libfoo-a.rlib \
88
--extern foo2=$(TMPDIR)/libfoo-b.rlib \
9-
-Z print-link-args
9+
--print link-args
1010
$(call RUN,bar)

src/test/run-make-fulldeps/no-builtins-lto/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ all:
66
# Build an executable that depends on that crate using LTO. The no_builtins crate doesn't
77
# participate in LTO, so its rlib must be explicitly linked into the final binary. Verify this by
88
# grepping the linker arguments.
9-
$(RUSTC) main.rs -C lto -Z print-link-args | $(CGREP) 'libno_builtins.rlib'
9+
$(RUSTC) main.rs -C lto --print link-args | $(CGREP) 'libno_builtins.rlib'

src/test/run-make-fulldeps/redundant-libs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUSTC_FLAGS = \
1616
-l foo \
1717
-l static=baz \
1818
-l foo \
19-
-Z print-link-args
19+
--print link-args
2020

2121
all: $(call DYLIB,foo) $(call STATICLIB,bar) $(call STATICLIB,baz)
2222
$(RUSTC) $(RUSTC_FLAGS) main.rs

src/test/run-make-fulldeps/static-nobundle/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ all: $(call NATIVE_STATICLIB,aaa)
1313
nm $(TMPDIR)/libbbb.rlib | $(CGREP) -e "U _*native_func"
1414

1515
# Check that aaa gets linked (either as `-l aaa` or `aaa.lib`) when building ccc.
16-
$(RUSTC) ccc.rs -C prefer-dynamic --crate-type=dylib -Z print-link-args | $(CGREP) -e '-l[" ]*aaa|aaa\.lib'
16+
$(RUSTC) ccc.rs -C prefer-dynamic --crate-type=dylib --print link-args | $(CGREP) -e '-l[" ]*aaa|aaa\.lib'
1717

1818
# Check that aaa does NOT get linked when building ddd.
19-
$(RUSTC) ddd.rs -Z print-link-args | $(CGREP) -ve '-l[" ]*aaa|aaa\.lib'
19+
$(RUSTC) ddd.rs --print link-args | $(CGREP) -ve '-l[" ]*aaa|aaa\.lib'
2020

2121
$(call RUN,ddd)

0 commit comments

Comments
 (0)