Rollup merge of #89041 - sticnarf:sticnarf/fat-lto-dwarf, r=nagisa

Work around invalid DWARF bugs for fat LTO

This PR applies the same workaround in #46772 to fat LTO.

It seems to fix the bug reported in https://github.com/rust-lang/rust/issues/66118#issuecomment-917434036.
This commit is contained in:
the8472 2021-09-22 19:03:21 +02:00 committed by GitHub
commit 1deef1f75d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 10 deletions

View File

@ -325,6 +325,20 @@ fn fat_lto(
drop(linker); drop(linker);
save_temp_bitcode(&cgcx, &module, "lto.input"); save_temp_bitcode(&cgcx, &module, "lto.input");
// Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO.
// Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`.
// This only works around the problem when codegen-units = 1.
// Refer to the comments in the `optimize_thin_module` function for more details.
let mut cu1 = ptr::null_mut();
let mut cu2 = ptr::null_mut();
unsafe { llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2) };
if !cu2.is_null() {
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_fat_lto_patch_debuginfo", &*module.name);
unsafe { llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1) };
save_temp_bitcode(cgcx, &module, "fat-lto-after-patch");
}
// Internalize everything below threshold to help strip out more modules and such. // Internalize everything below threshold to help strip out more modules and such.
unsafe { unsafe {
let ptr = symbols_below_threshold.as_ptr(); let ptr = symbols_below_threshold.as_ptr();
@ -748,7 +762,7 @@ pub unsafe fn optimize_thin_module(
// an error. // an error.
let mut cu1 = ptr::null_mut(); let mut cu1 = ptr::null_mut();
let mut cu2 = ptr::null_mut(); let mut cu2 = ptr::null_mut();
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2); llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
if !cu2.is_null() { if !cu2.is_null() {
let msg = "multiple source DICompileUnits found"; let msg = "multiple source DICompileUnits found";
return Err(write::llvm_err(&diag_handler, msg)); return Err(write::llvm_err(&diag_handler, msg));
@ -847,7 +861,7 @@ pub unsafe fn optimize_thin_module(
let _timer = cgcx let _timer = cgcx
.prof .prof
.generic_activity_with_arg("LLVM_thin_lto_patch_debuginfo", thin_module.name()); .generic_activity_with_arg("LLVM_thin_lto_patch_debuginfo", thin_module.name());
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1); llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1);
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch"); save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
} }

View File

@ -2377,12 +2377,8 @@ pub fn LLVMRustGetBitcodeSliceFromObjectData(
len: usize, len: usize,
out_len: &mut usize, out_len: &mut usize,
) -> *const u8; ) -> *const u8;
pub fn LLVMRustThinLTOGetDICompileUnit( pub fn LLVMRustLTOGetDICompileUnit(M: &Module, CU1: &mut *mut c_void, CU2: &mut *mut c_void);
M: &Module, pub fn LLVMRustLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
CU1: &mut *mut c_void,
CU2: &mut *mut c_void,
);
pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>; pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
pub fn LLVMRustLinkerAdd( pub fn LLVMRustLinkerAdd(

View File

@ -1747,7 +1747,7 @@ LLVMRustGetBitcodeSliceFromObjectData(const char *data,
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See // Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
// the comment in `back/lto.rs` for why this exists. // the comment in `back/lto.rs` for why this exists.
extern "C" void extern "C" void
LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod, LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
DICompileUnit **A, DICompileUnit **A,
DICompileUnit **B) { DICompileUnit **B) {
Module *M = unwrap(Mod); Module *M = unwrap(Mod);
@ -1765,7 +1765,7 @@ LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See // Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
// the comment in `back/lto.rs` for why this exists. // the comment in `back/lto.rs` for why this exists.
extern "C" void extern "C" void
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) { LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
Module *M = unwrap(Mod); Module *M = unwrap(Mod);
// If the original source module didn't have a `DICompileUnit` then try to // If the original source module didn't have a `DICompileUnit` then try to