@@ -325,6 +325,20 @@ fn fat_lto(
325
325
drop ( linker) ;
326
326
save_temp_bitcode ( & cgcx, & module, "lto.input" ) ;
327
327
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
+
328
342
// Internalize everything below threshold to help strip out more modules and such.
329
343
unsafe {
330
344
let ptr = symbols_below_threshold. as_ptr ( ) ;
@@ -748,7 +762,7 @@ pub unsafe fn optimize_thin_module(
748
762
// an error.
749
763
let mut cu1 = ptr:: null_mut ( ) ;
750
764
let mut cu2 = ptr:: null_mut ( ) ;
751
- llvm:: LLVMRustThinLTOGetDICompileUnit ( llmod, & mut cu1, & mut cu2) ;
765
+ llvm:: LLVMRustLTOGetDICompileUnit ( llmod, & mut cu1, & mut cu2) ;
752
766
if !cu2. is_null ( ) {
753
767
let msg = "multiple source DICompileUnits found" ;
754
768
return Err ( write:: llvm_err ( & diag_handler, msg) ) ;
@@ -847,7 +861,7 @@ pub unsafe fn optimize_thin_module(
847
861
let _timer = cgcx
848
862
. prof
849
863
. generic_activity_with_arg ( "LLVM_thin_lto_patch_debuginfo" , thin_module. name ( ) ) ;
850
- llvm:: LLVMRustThinLTOPatchDICompileUnit ( llmod, cu1) ;
864
+ llvm:: LLVMRustLTOPatchDICompileUnit ( llmod, cu1) ;
851
865
save_temp_bitcode ( cgcx, & module, "thin-lto-after-patch" ) ;
852
866
}
853
867
0 commit comments