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