@@ -607,6 +607,19 @@ pub fn run_passes(sess: &Session,
607607 } ;
608608
609609 let link_obj = |output_path : & Path | {
610+ // Some builds of MinGW GCC will pass --force-exe-suffix to ld, which
611+ // will automatically add a .exe extension if the extension is not
612+ // already .exe or .dll. To ensure consistent behavior on Windows, we
613+ // add the .exe suffix explicitly and then rename the output file to
614+ // the desired path. This will give the correct behavior whether or
615+ // not GCC adds --force-exe-suffix.
616+ let windows_output_path =
617+ if sess. targ_cfg . os == abi:: OsWindows {
618+ Some ( output_path. with_extension ( "o.exe" ) )
619+ } else {
620+ None
621+ } ;
622+
610623 let pname = get_cc_prog ( sess) ;
611624 let mut cmd = Command :: new ( pname. as_slice ( ) ) ;
612625
@@ -617,7 +630,9 @@ pub fn run_passes(sess: &Session,
617630 cmd. arg ( crate_output. with_extension ( format ! ( "{}.o" , index) . as_slice ( ) ) ) ;
618631 }
619632
620- cmd. arg ( "-r" ) . arg ( "-o" ) . arg ( output_path) ;
633+ cmd. arg ( "-r" )
634+ . arg ( "-o" )
635+ . arg ( windows_output_path. as_ref ( ) . unwrap_or ( output_path) ) ;
621636
622637 if ( sess. opts . debugging_opts & config:: PRINT_LINK_ARGS ) != 0 {
623638 println ! ( "{}" , & cmd) ;
@@ -635,6 +650,15 @@ pub fn run_passes(sess: &Session,
635650 sess. abort_if_errors ( ) ;
636651 } ,
637652 }
653+
654+ match windows_output_path {
655+ Some ( ref windows_path) => {
656+ fs:: rename ( windows_path, output_path) . unwrap ( ) ;
657+ } ,
658+ None => {
659+ // The file is already named according to `output_path`.
660+ }
661+ }
638662 } ;
639663
640664 // Flag to indicate whether the user explicitly requested bitcode.
0 commit comments