Skip to content

Commit 98190b7

Browse files
committed
Revert "Work around invalid DWARF bugs for fat LTO"
Since September, the toolchain has not been generating reliable DWARF information for static variables when LTO is on. This has affected projects in the embedded space where the use of LTO is typical. In our case, it has kept us from bumping past the 2021-09-22 nightly toolchain lest our debugger break. This has been a pretty dramatic regression for people using debuggers and static variables. See rust-lang#90357 for more info and a repro case. This commit is a mechanical revert of d5de680 from PR rust-lang#89041, which caused the issue. (Note on that PR that the commit's author has requested it be reverted.) I have locally verified that this fixes rust-lang#90357 by restoring the functionality of both the repro case I posted on that bug, and debugger behavior on real programs. There do not appear to be test cases for this in the toolchain; if I've missed them, point me at 'em and I'll update them.
1 parent d4c7839 commit 98190b7

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,6 @@ 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-
342328
// Internalize everything below threshold to help strip out more modules and such.
343329
unsafe {
344330
let ptr = symbols_below_threshold.as_ptr();
@@ -757,7 +743,7 @@ pub unsafe fn optimize_thin_module(
757743
// an error.
758744
let mut cu1 = ptr::null_mut();
759745
let mut cu2 = ptr::null_mut();
760-
llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
746+
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
761747
if !cu2.is_null() {
762748
let msg = "multiple source DICompileUnits found";
763749
return Err(write::llvm_err(&diag_handler, msg));
@@ -846,7 +832,7 @@ pub unsafe fn optimize_thin_module(
846832
let _timer = cgcx
847833
.prof
848834
.generic_activity_with_arg("LLVM_thin_lto_patch_debuginfo", thin_module.name());
849-
llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1);
835+
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1);
850836
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
851837
}
852838

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2506,8 +2506,12 @@ extern "C" {
25062506
len: usize,
25072507
out_len: &mut usize,
25082508
) -> *const u8;
2509-
pub fn LLVMRustLTOGetDICompileUnit(M: &Module, CU1: &mut *mut c_void, CU2: &mut *mut c_void);
2510-
pub fn LLVMRustLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
2509+
pub fn LLVMRustThinLTOGetDICompileUnit(
2510+
M: &Module,
2511+
CU1: &mut *mut c_void,
2512+
CU2: &mut *mut c_void,
2513+
);
2514+
pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
25112515

25122516
pub fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
25132517
pub fn LLVMRustLinkerAdd(

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ LLVMRustGetBitcodeSliceFromObjectData(const char *data,
16111611
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
16121612
// the comment in `back/lto.rs` for why this exists.
16131613
extern "C" void
1614-
LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
1614+
LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
16151615
DICompileUnit **A,
16161616
DICompileUnit **B) {
16171617
Module *M = unwrap(Mod);
@@ -1629,7 +1629,7 @@ LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
16291629
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
16301630
// the comment in `back/lto.rs` for why this exists.
16311631
extern "C" void
1632-
LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
1632+
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
16331633
Module *M = unwrap(Mod);
16341634

16351635
// If the original source module didn't have a `DICompileUnit` then try to

0 commit comments

Comments
 (0)