File tree Expand file tree Collapse file tree 5 files changed +24
-9
lines changed
compiler/rustc_codegen_ssa/src Expand file tree Collapse file tree 5 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -935,12 +935,12 @@ fn link_natively<'a>(
935935 let mut output = prog. stderr . clone ( ) ;
936936 output. extend_from_slice ( & prog. stdout ) ;
937937 let escaped_output = escape_linker_output ( & output, flavor) ;
938- // FIXME: Add UI tests for this error.
939938 let err = errors:: LinkingFailed {
940939 linker_path : & linker_path,
941940 exit_status : prog. status ,
942941 command : & cmd,
943942 escaped_output,
943+ verbose : sess. opts . verbose ,
944944 } ;
945945 sess. dcx ( ) . emit_err ( err) ;
946946 // If MSVC's `link.exe` was expected but the return code
Original file line number Diff line number Diff line change @@ -408,6 +408,7 @@ pub struct LinkingFailed<'a> {
408408 pub exit_status : ExitStatus ,
409409 pub command : & ' a Command ,
410410 pub escaped_output : String ,
411+ pub verbose : bool ,
411412}
412413
413414impl IntoDiagnostic < ' _ > for LinkingFailed < ' _ > {
@@ -418,7 +419,13 @@ impl IntoDiagnostic<'_> for LinkingFailed<'_> {
418419
419420 let contains_undefined_ref = self . escaped_output . contains ( "undefined reference to" ) ;
420421
421- diag. note ( format ! ( "{:?}" , self . command) ) . note ( self . escaped_output ) ;
422+ if self . verbose {
423+ diag. note ( format ! ( "{:?}" , self . command) ) ;
424+ } else {
425+ diag. note ( "use `--verbose` to show all linker arguments" ) ;
426+ }
427+
428+ diag. note ( self . escaped_output ) ;
422429
423430 // Trying to match an error from OS linkers
424431 // which by now we have no way to translate.
Original file line number Diff line number Diff line change @@ -6,5 +6,5 @@ RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args=
66RUSTC_FLAGS_PRE = -C linker-flavor=ld -Z pre-link-arg=a -Z pre-link-args="b c" -Z pre-link-args="d e" -Z pre-link-arg=f
77
88all :
9- $(RUSTC ) $(RUSTC_FLAGS ) empty.rs 2>&1 | $(CGREP ) ' "a" "b" "c" "d" "e" "f"'
10- $(RUSTC ) $(RUSTC_FLAGS_PRE ) empty.rs 2>&1 | $(CGREP ) ' "a" "b" "c" "d" "e" "f"'
9+ $(RUSTC ) $(RUSTC_FLAGS ) empty.rs --print=link-args | $(CGREP ) ' "a" "b" "c" "d" "e" "f"'
10+ $(RUSTC ) $(RUSTC_FLAGS_PRE ) empty.rs --print=link-args | $(CGREP ) ' "a" "b" "c" "d" "e" "f"'
Original file line number Diff line number Diff line change 66 $(RUSTC ) depa.rs
77 $(RUSTC ) depb.rs
88 $(RUSTC ) depc.rs
9- $(RUSTC ) empty.rs --cfg bar 2>&1 | $(CGREP ) ' "-ltesta" "-ltestb" "-ltesta"'
10- $(RUSTC ) empty.rs 2>&1 | $(CGREP ) ' "-ltesta"'
11- $(RUSTC ) empty.rs 2>&1 | $(CGREP ) -v ' "-ltestb"'
12- $(RUSTC ) empty.rs 2>&1 | $(CGREP ) -v ' "-ltesta" "-ltesta" "-ltesta"'
9+ $(RUSTC ) empty.rs --cfg bar --print=link-args | $(CGREP ) ' "-ltesta" "-ltestb" "-ltesta"'
10+ $(RUSTC ) empty.rs --print=link-args | $(CGREP ) ' "-ltesta"'
11+ $(RUSTC ) empty.rs --print=link-args | $(CGREP ) -v ' "-ltestb"'
12+ $(RUSTC ) empty.rs --print=link-args | $(CGREP ) -v ' "-ltesta" "-ltesta" "-ltesta"'
Original file line number Diff line number Diff line change @@ -2,16 +2,24 @@ include ../tools.mk
22
33RUN_RUSTC := $(RUSTC_ORIGINAL ) main.rs -o $(TMPDIR ) /main -C linker=./fake-linker.sh
44
5- all :
5+ all : succeeds_with_warnings errors linker_args
6+
7+ succeeds_with_warnings :
68 # Run rustc with our fake linker, and make sure it shows warnings
79 $(RUN_RUSTC ) -C link-arg=run_make_warn 2>&1 | $(CGREP ) " warning: linker stderr: bar"
810
911 # Make sure it shows stdout, but only when --verbose is passed
1012 $(RUN_RUSTC) -C link-arg=run_make_info --verbose 2>&1 | $(CGREP) "warning: linker stdout: foo"
1113 $(RUN_RUSTC) -C link-arg=run_make_info 2>&1 | $(CGREP) -v "warning: linker stdout: foo"
1214
15+ errors :
1316 # Make sure we short-circuit this new path if the linker exits with an error (so the diagnostic is less verbose)
1417 rm -f $(TMPDIR ) /main
1518 $(RUN_RUSTC ) -C link-arg=run_make_error 2>&1 | $(CGREP ) " note: error: baz"
1619 ! [ -e $( TMPDIR) /main ]
1720
21+ linker_args :
22+ # Make sure we don't show the linker args unless `--verbose` is passed
23+ $(RUN_RUSTC ) --verbose -C link-arg=run_make_error 2>&1 | $(CGREP ) -e " PATH=.*fake-linker.sh.*run_make_error"
24+ $(RUN_RUSTC ) -C link-arg=run_make_error 2>&1 | $(CGREP ) -v -e " PATH=.*fake-linker.sh.*run_make_error"
25+
You can’t perform that action at this time.
0 commit comments