@@ -721,6 +721,15 @@ fn link_dwarf_object<'a>(
721
721
}
722
722
}
723
723
724
+ #[ derive( Diagnostic ) ]
725
+ #[ diag( codegen_ssa_linker_output) ]
726
+ /// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
727
+ /// end up with inconsistent languages within the same diagnostic. Ideally we'd accept strings in
728
+ /// `emit_warning`, but I didn't feel like doing that much of a refactor.
729
+ struct LinkerOutput {
730
+ inner : String ,
731
+ }
732
+
724
733
/// Create a dynamic library or executable.
725
734
///
726
735
/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
@@ -972,8 +981,20 @@ fn link_natively<'a>(
972
981
973
982
sess. abort_if_errors ( ) ;
974
983
}
975
- info ! ( "linker stderr:\n {}" , escape_string( & prog. stderr) ) ;
976
- info ! ( "linker stdout:\n {}" , escape_string( & prog. stdout) ) ;
984
+
985
+ if !prog. stderr . is_empty ( ) {
986
+ // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
987
+ let stderr = escape_string ( & prog. stderr ) ;
988
+ debug ! ( "original stderr: {stderr}" ) ;
989
+ let stderr =
990
+ stderr. strip_prefix ( "warning: " ) . unwrap_or ( & stderr) . replace ( " warning: " , " " ) ;
991
+ sess. emit_warning ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
992
+ }
993
+ if !prog. stdout . is_empty ( ) && sess. opts . verbose {
994
+ sess. emit_warning ( LinkerOutput {
995
+ inner : format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) ,
996
+ } ) ;
997
+ }
977
998
}
978
999
Err ( e) => {
979
1000
let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
0 commit comments