Skip to content

Commit 7919ff8

Browse files
authored
Unrolled build for rust-lang#136659
Rollup merge of rust-lang#136659 - wesleywiser:dwarf_version_lto_merge_behavior, r=jieyouxu Pick the max DWARF version when LTO'ing modules with different versions Currently, when rustc compiles code with `-Clto` enabled that was built with different choices for `-Zdwarf-version`, a warning will be reported. It's very easy to observe this by compiling most anything (eg, "hello world") and specifying `-Clto -Zdwarf-version=5` since the standard library is distributed with `-Zdwarf-version=4`. This behavior isn't actually useful for a few reasons: - From observation, LLVM chooses to pick the highest DWARF version anyway after issuing the warning. - Clang specifies that in this case, the max version should be picked without a warning and as a general principle, we want to support x-lang LTO with Clang which implies using the same module flag merge behaviors. - Debuggers need to be able to handle a variety of versions within the same debugging session as you can easily have some parts of a binary (or some dynamic libraries within an application) all compiled with different DWARF versions. This commit changes the module flag merge behavior to match Clang and use the highest version of DWARF. It also adds a test to ensure this behavior is respected in the case of two crates being LTO'd together and adds a test to ensure no warning is printed. Fixes rust-lang#130041 which fails due to these warnings being printed cc rust-lang#103057
2 parents 1ff2135 + bbc40e7 commit 7919ff8

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
9797
// Android has the same issue (#22398)
9898
llvm::add_module_flag_u32(
9999
self.llmod,
100-
llvm::ModuleFlagMergeBehavior::Warning,
100+
// In the case where multiple CGUs with different dwarf version
101+
// values are being merged together, such as with cross-crate
102+
// LTO, then we want to use the highest version of dwarf
103+
// we can. This matches Clang's behavior as well.
104+
llvm::ModuleFlagMergeBehavior::Max,
101105
"Dwarf Version",
102106
sess.dwarf_version(),
103107
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4
2+
3+
pub fn check_is_even(number: &u64) -> bool {
4+
number % 2 == 0
5+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test ensures that if LTO occurs between crates with different DWARF versions, we
2+
// will choose the highest DWARF version for the final binary. This matches Clang's behavior.
3+
4+
//@ only-linux
5+
//@ aux-build:dwarf-mixed-versions-lto-aux.rs
6+
//@ compile-flags: -C lto -g -Zdwarf-version=5
7+
//@ assembly-output: emit-asm
8+
//@ no-prefer-dynamic
9+
10+
extern crate dwarf_mixed_versions_lto_aux;
11+
12+
fn main() {
13+
dwarf_mixed_versions_lto_aux::check_is_even(&0);
14+
}
15+
16+
// CHECK: .section .debug_info
17+
// CHECK-NOT: {{\.(short|hword)}} 2
18+
// CHECK-NOT: {{\.(short|hword)}} 4
19+
// CHECK: {{\.(short|hword)}} 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4
2+
3+
pub fn say_hi() {
4+
println!("hello there")
5+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test verifies that we do not produce a warning when performing LTO on a
2+
// crate graph that contains a mix of different DWARF version settings. This
3+
// matches Clang's behavior.
4+
5+
//@ ignore-msvc Platform must use DWARF
6+
//@ aux-build:dwarf-mixed-versions-lto-aux.rs
7+
//@ compile-flags: -C lto -g -Zdwarf-version=5
8+
//@ no-prefer-dynamic
9+
//@ build-pass
10+
11+
extern crate dwarf_mixed_versions_lto_aux;
12+
13+
fn main() {
14+
dwarf_mixed_versions_lto_aux::say_hi();
15+
}

0 commit comments

Comments
 (0)