@@ -18,6 +18,7 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
18
18
use rustc_errors:: { DiagCtxtHandle , ErrorGuaranteed , FatalError } ;
19
19
use rustc_fs_util:: { fix_windows_verbatim_for_gcc, try_canonicalize} ;
20
20
use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
21
+ use rustc_macros:: Diagnostic ;
21
22
use rustc_metadata:: fs:: { METADATA_FILENAME , copy_to_stdout, emit_wrapper_file} ;
22
23
use rustc_metadata:: { find_native_static_library, walk_native_lib_search_dirs} ;
23
24
use rustc_middle:: bug;
@@ -762,6 +763,14 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
762
763
}
763
764
}
764
765
766
+ #[ derive( Diagnostic ) ]
767
+ #[ diag( codegen_ssa_linker_output) ]
768
+ /// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
769
+ /// end up with inconsistent languages within the same diagnostic.
770
+ struct LinkerOutput {
771
+ inner : String ,
772
+ }
773
+
765
774
/// Create a dynamic library or executable.
766
775
///
767
776
/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
@@ -1045,8 +1054,22 @@ fn link_natively(
1045
1054
1046
1055
sess. dcx ( ) . abort_if_errors ( ) ;
1047
1056
}
1048
- info ! ( "linker stderr:\n {}" , escape_string( & prog. stderr) ) ;
1049
- info ! ( "linker stdout:\n {}" , escape_string( & prog. stdout) ) ;
1057
+
1058
+ if !prog. stderr . is_empty ( ) {
1059
+ // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
1060
+ let stderr = escape_string ( & prog. stderr ) ;
1061
+ debug ! ( "original stderr: {stderr}" ) ;
1062
+ let stderr = stderr
1063
+ . strip_prefix ( "warning: " )
1064
+ . unwrap_or ( & stderr)
1065
+ . replace ( ": warning: " , ": " ) ;
1066
+ sess. dcx ( ) . emit_warn ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
1067
+ }
1068
+ if !prog. stdout . is_empty ( ) && sess. opts . verbose {
1069
+ sess. dcx ( ) . emit_warn ( LinkerOutput {
1070
+ inner : format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) ,
1071
+ } ) ;
1072
+ }
1050
1073
}
1051
1074
Err ( e) => {
1052
1075
let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
0 commit comments