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