@@ -750,6 +750,14 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
750
750
}
751
751
}
752
752
753
+ #[ derive( Diagnostic ) ]
754
+ #[ diag( codegen_ssa_linker_output) ]
755
+ /// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
756
+ /// end up with inconsistent languages within the same diagnostic.
757
+ struct LinkerOutput {
758
+ inner : String ,
759
+ }
760
+
753
761
/// Create a dynamic library or executable.
754
762
///
755
763
/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
@@ -1022,8 +1030,22 @@ fn link_natively(
1022
1030
1023
1031
sess. dcx ( ) . abort_if_errors ( ) ;
1024
1032
}
1025
- info ! ( "linker stderr:\n {}" , escape_string( & prog. stderr) ) ;
1026
- info ! ( "linker stdout:\n {}" , escape_string( & prog. stdout) ) ;
1033
+
1034
+ if !prog. stderr . is_empty ( ) {
1035
+ // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
1036
+ let stderr = escape_string ( & prog. stderr ) ;
1037
+ debug ! ( "original stderr: {stderr}" ) ;
1038
+ let stderr = stderr
1039
+ . strip_prefix ( "warning: " )
1040
+ . unwrap_or ( & stderr)
1041
+ . replace ( ": warning: " , ": " ) ;
1042
+ sess. dcx ( ) . emit_warn ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
1043
+ }
1044
+ if !prog. stdout . is_empty ( ) && sess. opts . verbose {
1045
+ sess. dcx ( ) . emit_warn ( LinkerOutput {
1046
+ inner : format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) ,
1047
+ } ) ;
1048
+ }
1027
1049
}
1028
1050
Err ( e) => {
1029
1051
let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
0 commit comments