File tree 5 files changed +24
-9
lines changed
compiler/rustc_codegen_ssa/src
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>(
935
935
let mut output = prog. stderr . clone ( ) ;
936
936
output. extend_from_slice ( & prog. stdout ) ;
937
937
let escaped_output = escape_linker_output ( & output, flavor) ;
938
- // FIXME: Add UI tests for this error.
939
938
let err = errors:: LinkingFailed {
940
939
linker_path : & linker_path,
941
940
exit_status : prog. status ,
942
941
command : & cmd,
943
942
escaped_output,
943
+ verbose : sess. opts . verbose ,
944
944
} ;
945
945
sess. dcx ( ) . emit_err ( err) ;
946
946
// 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> {
408
408
pub exit_status : ExitStatus ,
409
409
pub command : & ' a Command ,
410
410
pub escaped_output : String ,
411
+ pub verbose : bool ,
411
412
}
412
413
413
414
impl IntoDiagnostic < ' _ > for LinkingFailed < ' _ > {
@@ -418,7 +419,13 @@ impl IntoDiagnostic<'_> for LinkingFailed<'_> {
418
419
419
420
let contains_undefined_ref = self . escaped_output . contains ( "undefined reference to" ) ;
420
421
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 ) ;
422
429
423
430
// Trying to match an error from OS linkers
424
431
// 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=
6
6
RUSTC_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
7
7
8
8
all :
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 6
6
$(RUSTC ) depa.rs
7
7
$(RUSTC ) depb.rs
8
8
$(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
2
2
3
3
RUN_RUSTC := $(RUSTC_ORIGINAL ) main.rs -o $(TMPDIR ) /main -C linker=./fake-linker.sh
4
4
5
- all :
5
+ all : succeeds_with_warnings errors linker_args
6
+
7
+ succeeds_with_warnings :
6
8
# Run rustc with our fake linker, and make sure it shows warnings
7
9
$(RUN_RUSTC ) -C link-arg=run_make_warn 2>&1 | $(CGREP ) " warning: linker stderr: bar"
8
10
9
11
# Make sure it shows stdout, but only when --verbose is passed
10
12
$(RUN_RUSTC) -C link-arg=run_make_info --verbose 2>&1 | $(CGREP) "warning: linker stdout: foo"
11
13
$(RUN_RUSTC) -C link-arg=run_make_info 2>&1 | $(CGREP) -v "warning: linker stdout: foo"
12
14
15
+ errors :
13
16
# Make sure we short-circuit this new path if the linker exits with an error (so the diagnostic is less verbose)
14
17
rm -f $(TMPDIR ) /main
15
18
$(RUN_RUSTC ) -C link-arg=run_make_error 2>&1 | $(CGREP ) " note: error: baz"
16
19
! [ -e $( TMPDIR) /main ]
17
20
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