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 @@ -934,12 +934,12 @@ fn link_natively<'a>(
934934                let  mut  output = prog. stderr . clone ( ) ; 
935935                output. extend_from_slice ( & prog. stdout ) ; 
936936                let  escaped_output = escape_linker_output ( & output,  flavor) ; 
937-                 // FIXME: Add UI tests for this error. 
938937                let  err = errors:: LinkingFailed  { 
939938                    linker_path :  & linker_path, 
940939                    exit_status :  prog. status , 
941940                    command :  & cmd, 
942941                    escaped_output, 
942+                     verbose :  sess. opts . verbose , 
943943                } ; 
944944                sess. dcx ( ) . emit_err ( err) ; 
945945                // If MSVC's `link.exe` was expected but the return code 
Original file line number Diff line number Diff line change @@ -340,6 +340,7 @@ pub struct LinkingFailed<'a> {
340340    pub  exit_status :  ExitStatus , 
341341    pub  command :  & ' a  Command , 
342342    pub  escaped_output :  String , 
343+     pub  verbose :  bool , 
343344} 
344345
345346impl < G :  EmissionGuarantee >  IntoDiagnostic < ' _ ,  G >  for  LinkingFailed < ' _ >  { 
@@ -350,7 +351,13 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for LinkingFailed<'_> {
350351
351352        let  contains_undefined_ref = self . escaped_output . contains ( "undefined reference to" ) ; 
352353
353-         diag. note ( format ! ( "{:?}" ,  self . command) ) . note ( self . escaped_output ) ; 
354+         if  self . verbose  { 
355+             diag. note ( format ! ( "{:?}" ,  self . command) ) ; 
356+         }  else  { 
357+             diag. note ( "use `--verbose` to show all linker arguments" ) ; 
358+         } 
359+ 
360+         diag. note ( self . escaped_output ) ; 
354361
355362        // Trying to match an error from OS linkers 
356363        // 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