@@ -325,6 +325,20 @@ fn fat_lto(
325325 drop ( linker) ;
326326 save_temp_bitcode ( & cgcx, & module, "lto.input" ) ;
327327
328+ // Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO.
329+ // Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`.
330+ // This only works around the problem when codegen-units = 1.
331+ // Refer to the comments in the `optimize_thin_module` function for more details.
332+ let mut cu1 = ptr:: null_mut ( ) ;
333+ let mut cu2 = ptr:: null_mut ( ) ;
334+ unsafe { llvm:: LLVMRustLTOGetDICompileUnit ( llmod, & mut cu1, & mut cu2) } ;
335+ if !cu2. is_null ( ) {
336+ let _timer =
337+ cgcx. prof . generic_activity_with_arg ( "LLVM_fat_lto_patch_debuginfo" , & * module. name ) ;
338+ unsafe { llvm:: LLVMRustLTOPatchDICompileUnit ( llmod, cu1) } ;
339+ save_temp_bitcode ( cgcx, & module, "fat-lto-after-patch" ) ;
340+ }
341+
328342 // Internalize everything below threshold to help strip out more modules and such.
329343 unsafe {
330344 let ptr = symbols_below_threshold. as_ptr ( ) ;
@@ -748,7 +762,7 @@ pub unsafe fn optimize_thin_module(
748762 // an error.
749763 let mut cu1 = ptr:: null_mut ( ) ;
750764 let mut cu2 = ptr:: null_mut ( ) ;
751- llvm:: LLVMRustThinLTOGetDICompileUnit ( llmod, & mut cu1, & mut cu2) ;
765+ llvm:: LLVMRustLTOGetDICompileUnit ( llmod, & mut cu1, & mut cu2) ;
752766 if !cu2. is_null ( ) {
753767 let msg = "multiple source DICompileUnits found" ;
754768 return Err ( write:: llvm_err ( & diag_handler, msg) ) ;
@@ -847,7 +861,7 @@ pub unsafe fn optimize_thin_module(
847861 let _timer = cgcx
848862 . prof
849863 . generic_activity_with_arg ( "LLVM_thin_lto_patch_debuginfo" , thin_module. name ( ) ) ;
850- llvm:: LLVMRustThinLTOPatchDICompileUnit ( llmod, cu1) ;
864+ llvm:: LLVMRustLTOPatchDICompileUnit ( llmod, cu1) ;
851865 save_temp_bitcode ( cgcx, & module, "thin-lto-after-patch" ) ;
852866 }
853867
0 commit comments