@@ -820,6 +820,10 @@ pub(crate) unsafe fn codegen(
820
820
let bc_out = cgcx. output_filenames . temp_path ( OutputType :: Bitcode , module_name) ;
821
821
let obj_out = cgcx. output_filenames . temp_path ( OutputType :: Object , module_name) ;
822
822
823
+ // Ensure we don't overwrite any hard links from previous compilation sessions.
824
+ ensure_removed ( dcx, & bc_out) ;
825
+ ensure_removed ( dcx, & obj_out) ;
826
+
823
827
if config. bitcode_needed ( ) {
824
828
if config. emit_bc || config. emit_obj == EmitObj :: Bitcode {
825
829
let thin = {
@@ -860,8 +864,11 @@ pub(crate) unsafe fn codegen(
860
864
if config. emit_ir {
861
865
let _timer =
862
866
cgcx. prof . generic_activity_with_arg ( "LLVM_module_codegen_emit_ir" , & * module. name ) ;
863
- let out = cgcx. output_filenames . temp_path ( OutputType :: LlvmAssembly , module_name) ;
864
- let out_c = path_to_c_string ( & out) ;
867
+ let ir_out = cgcx. output_filenames . temp_path ( OutputType :: LlvmAssembly , module_name) ;
868
+ // Ensure we don't overwrite any hard links from previous compilation sessions.
869
+ ensure_removed ( dcx, & ir_out) ;
870
+
871
+ let out_c = path_to_c_string ( & ir_out) ;
865
872
866
873
extern "C" fn demangle_callback (
867
874
input_ptr : * const c_char ,
@@ -893,16 +900,20 @@ pub(crate) unsafe fn codegen(
893
900
unsafe { llvm:: LLVMRustPrintModule ( llmod, out_c. as_ptr ( ) , demangle_callback) } ;
894
901
895
902
if result == llvm:: LLVMRustResult :: Success {
896
- record_artifact_size ( & cgcx. prof , "llvm_ir" , & out ) ;
903
+ record_artifact_size ( & cgcx. prof , "llvm_ir" , & ir_out ) ;
897
904
}
898
905
899
- result. into_result ( ) . map_err ( |( ) | llvm_err ( dcx, LlvmError :: WriteIr { path : & out } ) ) ?;
906
+ result
907
+ . into_result ( )
908
+ . map_err ( |( ) | llvm_err ( dcx, LlvmError :: WriteIr { path : & ir_out } ) ) ?;
900
909
}
901
910
902
911
if config. emit_asm {
903
912
let _timer =
904
913
cgcx. prof . generic_activity_with_arg ( "LLVM_module_codegen_emit_asm" , & * module. name ) ;
905
- let path = cgcx. output_filenames . temp_path ( OutputType :: Assembly , module_name) ;
914
+ let asm_out = cgcx. output_filenames . temp_path ( OutputType :: Assembly , module_name) ;
915
+ // Ensure we don't overwrite any hard links from previous compilation sessions.
916
+ ensure_removed ( dcx, & asm_out) ;
906
917
907
918
// We can't use the same module for asm and object code output,
908
919
// because that triggers various errors like invalid IR or broken
@@ -918,7 +929,7 @@ pub(crate) unsafe fn codegen(
918
929
tm. raw ( ) ,
919
930
config. no_builtins ,
920
931
llmod,
921
- & path ,
932
+ & asm_out ,
922
933
None ,
923
934
llvm:: FileType :: AssemblyFile ,
924
935
& cgcx. prof ,
@@ -933,6 +944,9 @@ pub(crate) unsafe fn codegen(
933
944
. generic_activity_with_arg ( "LLVM_module_codegen_emit_obj" , & * module. name ) ;
934
945
935
946
let dwo_out = cgcx. output_filenames . temp_path_dwo ( module_name) ;
947
+ // Ensure we don't overwrite any hard links from previous compilation sessions.
948
+ ensure_removed ( dcx, & dwo_out) ;
949
+
936
950
let dwo_out = match ( cgcx. split_debuginfo , cgcx. split_dwarf_kind ) {
937
951
// Don't change how DWARF is emitted when disabled.
938
952
( SplitDebuginfo :: Off , _) => None ,
0 commit comments