Skip to content

Commit f77c0db

Browse files
authored
Rollup merge of rust-lang#95685 - oxidecomputer:restore-static-dwarf, r=pnkfelix
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.
2 parents 21b8b25 + 42af197 commit f77c0db

File tree

5 files changed

+93
-27
lines changed

5 files changed

+93
-27
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
@@ -1618,7 +1618,7 @@ LLVMRustGetBitcodeSliceFromObjectData(const char *data,
16181618
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
16191619
// the comment in `back/lto.rs` for why this exists.
16201620
extern "C" void
1621-
LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
1621+
LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
16221622
DICompileUnit **A,
16231623
DICompileUnit **B) {
16241624
Module *M = unwrap(Mod);
@@ -1636,7 +1636,7 @@ LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
16361636
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
16371637
// the comment in `back/lto.rs` for why this exists.
16381638
extern "C" void
1639-
LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
1639+
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
16401640
Module *M = unwrap(Mod);
16411641

16421642
// If the original source module didn't have a `DICompileUnit` then try to
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Caveat - gdb doesn't know about UTF-32 character encoding and will print a
2+
// rust char as only its numerical value.
3+
4+
// min-lldb-version: 310
5+
6+
// no-prefer-dynamic
7+
// compile-flags:-g -C lto
8+
// gdb-command:run
9+
// gdbg-command:print 'basic_types_globals::B'
10+
// gdbr-command:print B
11+
// gdb-check:$1 = false
12+
// gdbg-command:print 'basic_types_globals::I'
13+
// gdbr-command:print I
14+
// gdb-check:$2 = -1
15+
// gdbg-command:print 'basic_types_globals::C'
16+
// gdbr-command:print C
17+
// gdbg-check:$3 = 97
18+
// gdbr-check:$3 = 97
19+
// gdbg-command:print/d 'basic_types_globals::I8'
20+
// gdbr-command:print I8
21+
// gdb-check:$4 = 68
22+
// gdbg-command:print 'basic_types_globals::I16'
23+
// gdbr-command:print I16
24+
// gdb-check:$5 = -16
25+
// gdbg-command:print 'basic_types_globals::I32'
26+
// gdbr-command:print I32
27+
// gdb-check:$6 = -32
28+
// gdbg-command:print 'basic_types_globals::I64'
29+
// gdbr-command:print I64
30+
// gdb-check:$7 = -64
31+
// gdbg-command:print 'basic_types_globals::U'
32+
// gdbr-command:print U
33+
// gdb-check:$8 = 1
34+
// gdbg-command:print/d 'basic_types_globals::U8'
35+
// gdbr-command:print U8
36+
// gdb-check:$9 = 100
37+
// gdbg-command:print 'basic_types_globals::U16'
38+
// gdbr-command:print U16
39+
// gdb-check:$10 = 16
40+
// gdbg-command:print 'basic_types_globals::U32'
41+
// gdbr-command:print U32
42+
// gdb-check:$11 = 32
43+
// gdbg-command:print 'basic_types_globals::U64'
44+
// gdbr-command:print U64
45+
// gdb-check:$12 = 64
46+
// gdbg-command:print 'basic_types_globals::F32'
47+
// gdbr-command:print F32
48+
// gdb-check:$13 = 2.5
49+
// gdbg-command:print 'basic_types_globals::F64'
50+
// gdbr-command:print F64
51+
// gdb-check:$14 = 3.5
52+
// gdb-command:continue
53+
54+
#![allow(unused_variables)]
55+
#![feature(omit_gdb_pretty_printer_section)]
56+
#![omit_gdb_pretty_printer_section]
57+
58+
// N.B. These are `mut` only so they don't constant fold away.
59+
static mut B: bool = false;
60+
static mut I: isize = -1;
61+
static mut C: char = 'a';
62+
static mut I8: i8 = 68;
63+
static mut I16: i16 = -16;
64+
static mut I32: i32 = -32;
65+
static mut I64: i64 = -64;
66+
static mut U: usize = 1;
67+
static mut U8: u8 = 100;
68+
static mut U16: u16 = 16;
69+
static mut U32: u32 = 32;
70+
static mut U64: u64 = 64;
71+
static mut F32: f32 = 2.5;
72+
static mut F64: f64 = 3.5;
73+
74+
fn main() {
75+
_zzz(); // #break
76+
77+
let a = unsafe { (B, I, C, I8, I16, I32, I64, U, U8, U16, U32, U64, F32, F64) };
78+
}
79+
80+
fn _zzz() {()}

src/test/debuginfo/basic-types-globals.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// Caveats - gdb prints any 8-bit value (meaning rust I8 and u8 values)
2-
// as its numerical value along with its associated ASCII char, there
3-
// doesn't seem to be any way around this. Also, gdb doesn't know
4-
// about UTF-32 character encoding and will print a rust char as only
5-
// its numerical value.
1+
// Caveat - gdb doesn't know about UTF-32 character encoding and will print a
2+
// rust char as only its numerical value.
63

74
// min-lldb-version: 310
8-
// ignore-gdb // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155
95

106
// compile-flags:-g
117
// gdb-command:run
@@ -18,7 +14,7 @@
1814
// gdbg-command:print 'basic_types_globals::C'
1915
// gdbr-command:print C
2016
// gdbg-check:$3 = 97
21-
// gdbr-check:$3 = 97 'a'
17+
// gdbr-check:$3 = 97
2218
// gdbg-command:print/d 'basic_types_globals::I8'
2319
// gdbr-command:print I8
2420
// gdb-check:$4 = 68

0 commit comments

Comments
 (0)