@@ -731,6 +731,14 @@ fn link_dwarf_object<'a>(
731
731
}
732
732
}
733
733
734
+ #[ derive( Diagnostic ) ]
735
+ #[ diag( codegen_ssa_linker_output) ]
736
+ /// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
737
+ /// end up with inconsistent languages within the same diagnostic.
738
+ struct LinkerOutput {
739
+ inner : String ,
740
+ }
741
+
734
742
/// Create a dynamic library or executable.
735
743
///
736
744
/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
@@ -936,12 +944,12 @@ fn link_natively<'a>(
936
944
let mut output = prog. stderr . clone ( ) ;
937
945
output. extend_from_slice ( & prog. stdout ) ;
938
946
let escaped_output = escape_linker_output ( & output, flavor) ;
939
- // FIXME: Add UI tests for this error.
940
947
let err = errors:: LinkingFailed {
941
948
linker_path : & linker_path,
942
949
exit_status : prog. status ,
943
950
command : & cmd,
944
951
escaped_output,
952
+ verbose : sess. opts . verbose ,
945
953
} ;
946
954
sess. dcx ( ) . emit_err ( err) ;
947
955
// If MSVC's `link.exe` was expected but the return code
@@ -982,8 +990,22 @@ fn link_natively<'a>(
982
990
983
991
sess. dcx ( ) . abort_if_errors ( ) ;
984
992
}
985
- info ! ( "linker stderr:\n {}" , escape_string( & prog. stderr) ) ;
986
- info ! ( "linker stdout:\n {}" , escape_string( & prog. stdout) ) ;
993
+
994
+ if !prog. stderr . is_empty ( ) {
995
+ // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
996
+ let stderr = escape_string ( & prog. stderr ) ;
997
+ debug ! ( "original stderr: {stderr}" ) ;
998
+ let stderr = stderr
999
+ . strip_prefix ( "warning: " )
1000
+ . unwrap_or ( & stderr)
1001
+ . replace ( ": warning: " , ": " ) ;
1002
+ sess. dcx ( ) . emit_warn ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
1003
+ }
1004
+ if !prog. stdout . is_empty ( ) && sess. opts . verbose {
1005
+ sess. dcx ( ) . emit_warn ( LinkerOutput {
1006
+ inner : format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) ,
1007
+ } ) ;
1008
+ }
987
1009
}
988
1010
Err ( e) => {
989
1011
let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
0 commit comments