@@ -721,6 +721,15 @@ fn link_dwarf_object<'a>(
721721 }
722722}
723723
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+
724733/// Create a dynamic library or executable.
725734///
726735/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
@@ -972,8 +981,22 @@ fn link_natively<'a>(
972981
973982 sess. abort_if_errors ( ) ;
974983 }
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 = stderr
990+ . strip_prefix ( "warning: " )
991+ . unwrap_or ( & stderr)
992+ . replace ( ": warning: " , ": " ) ;
993+ sess. emit_warning ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
994+ }
995+ if !prog. stdout . is_empty ( ) && sess. opts . verbose {
996+ sess. emit_warning ( LinkerOutput {
997+ inner : format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) ,
998+ } ) ;
999+ }
9771000 }
9781001 Err ( e) => {
9791002 let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
0 commit comments