@@ -607,6 +607,19 @@ pub fn run_passes(sess: &Session,
607
607
} ;
608
608
609
609
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
+
610
623
let pname = get_cc_prog ( sess) ;
611
624
let mut cmd = Command :: new ( pname. as_slice ( ) ) ;
612
625
@@ -617,7 +630,9 @@ pub fn run_passes(sess: &Session,
617
630
cmd. arg ( crate_output. with_extension ( format ! ( "{}.o" , index) . as_slice ( ) ) ) ;
618
631
}
619
632
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) ) ;
621
636
622
637
if ( sess. opts . debugging_opts & config:: PRINT_LINK_ARGS ) != 0 {
623
638
println ! ( "{}" , & cmd) ;
@@ -635,6 +650,15 @@ pub fn run_passes(sess: &Session,
635
650
sess. abort_if_errors ( ) ;
636
651
} ,
637
652
}
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
+ }
638
662
} ;
639
663
640
664
// Flag to indicate whether the user explicitly requested bitcode.
0 commit comments