@@ -731,6 +731,14 @@ fn link_dwarf_object<'a>(
731731 }
732732}
733733
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+
734742/// Create a dynamic library or executable.
735743///
736744/// 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>(
936944 let mut output = prog. stderr . clone ( ) ;
937945 output. extend_from_slice ( & prog. stdout ) ;
938946 let escaped_output = escape_linker_output ( & output, flavor) ;
939- // FIXME: Add UI tests for this error.
940947 let err = errors:: LinkingFailed {
941948 linker_path : & linker_path,
942949 exit_status : prog. status ,
943950 command : & cmd,
944951 escaped_output,
952+ verbose : sess. opts . verbose ,
945953 } ;
946954 sess. dcx ( ) . emit_err ( err) ;
947955 // If MSVC's `link.exe` was expected but the return code
@@ -982,8 +990,22 @@ fn link_natively<'a>(
982990
983991 sess. dcx ( ) . abort_if_errors ( ) ;
984992 }
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+ }
9871009 }
9881010 Err ( e) => {
9891011 let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
0 commit comments