Skip to content

Commit 02379e9

Browse files
authored
Rollup merge of #91606 - joshtriplett:stabilize-print-link-args, r=pnkfelix
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. Add documentation for the new option. In the documentation, make it clear that the *exact* format of the output is not a stable guarantee.
2 parents d188287 + 371bd46 commit 02379e9

File tree

13 files changed

+24
-17
lines changed

13 files changed

+24
-17
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
667667
cmd.env_remove(k);
668668
}
669669

670-
if sess.opts.debugging_opts.print_link_args {
670+
if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
671671
println!("{:?}", &cmd);
672672
}
673673

compiler/rustc_driver/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ impl RustcDefaultCalls {
645645
temps_dir: &Option<PathBuf>,
646646
) -> Compilation {
647647
use rustc_session::config::PrintRequest::*;
648-
// PrintRequest::NativeStaticLibs is special - printed during linking
648+
// NativeStaticLibs and LinkArgs are special - printed during linking
649649
// (empty iterator returns true)
650-
if sess.opts.prints.iter().all(|&p| p == PrintRequest::NativeStaticLibs) {
650+
if sess.opts.prints.iter().all(|&p| p == NativeStaticLibs || p == LinkArgs) {
651651
return Compilation::Continue;
652652
}
653653

@@ -738,7 +738,8 @@ impl RustcDefaultCalls {
738738
codegen_backend.print(*req, sess);
739739
}
740740
// Any output here interferes with Cargo's parsing of other printed output
741-
PrintRequest::NativeStaticLibs => {}
741+
NativeStaticLibs => {}
742+
LinkArgs => {}
742743
}
743744
}
744745
Compilation::Stop

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ fn test_debugging_options_tracking_hash() {
678678
// `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
679679
untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
680680
untracked!(profile_closures, true);
681-
untracked!(print_link_args, true);
682681
untracked!(print_llvm_passes, true);
683682
untracked!(print_mono_items, Some(String::from("abc")));
684683
untracked!(print_type_sizes, true);

compiler/rustc_session/src/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ pub enum PrintRequest {
565565
TargetSpec,
566566
NativeStaticLibs,
567567
StackProtectorStrategies,
568+
LinkArgs,
568569
}
569570

570571
#[derive(Copy, Clone)]
@@ -1187,7 +1188,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
11871188
"Compiler information to print on stdout",
11881189
"[crate-name|file-names|sysroot|target-libdir|cfg|target-list|\
11891190
target-cpus|target-features|relocation-models|code-models|\
1190-
tls-models|target-spec-json|native-static-libs|stack-protector-strategies]",
1191+
tls-models|target-spec-json|native-static-libs|stack-protector-strategies\
1192+
link-args]",
11911193
),
11921194
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
11931195
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
@@ -1619,6 +1621,7 @@ fn collect_print_requests(
16191621
);
16201622
}
16211623
}
1624+
"link-args" => PrintRequest::LinkArgs,
16221625
req => early_error(error_format, &format!("unknown print request `{}`", req)),
16231626
}));
16241627

compiler/rustc_session/src/options.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1339,8 +1339,6 @@ options! {
13391339
See #77382 and #74551."),
13401340
print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
13411341
"make rustc print the total optimization fuel used by a crate"),
1342-
print_link_args: bool = (false, parse_bool, [UNTRACKED],
1343-
"print the arguments passed to the linker (default: no)"),
13441342
print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
13451343
"print the LLVM optimization passes being run (default: no)"),
13461344
print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],

src/doc/rustc/src/command-line-arguments.md

+6
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ The valid types of print values are:
170170
include a diagnostic note that indicates the linker flags to use when
171171
linking the resulting static library. The note starts with the text
172172
`native-static-libs:` to make it easier to fetch the output.
173+
- `link-args` — This flag does not disable the `--emit` step. When linking,
174+
this flag causes `rustc` to print the full linker invocation in a
175+
human-readable form. This can be useful when debugging linker options. The
176+
exact format of this debugging output is not a stable guarantee, other than
177+
that it will include the linker executable and the text of each command-line
178+
argument passed to the linker.
173179

174180
[conditional compilation]: ../reference/conditional-compilation.html
175181

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)