Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick the max DWARF version when LTO'ing modules with different versions #136659

Merged
merged 2 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
// Android has the same issue (#22398)
llvm::add_module_flag_u32(
self.llmod,
llvm::ModuleFlagMergeBehavior::Warning,
// In the case where multiple CGUs with different dwarf version
// values are being merged together, such as with cross-crate
// LTO, then we want to use the highest version of dwarf
// we can. This matches Clang's behavior as well.
llvm::ModuleFlagMergeBehavior::Max,
"Dwarf Version",
sess.dwarf_version(),
);
Expand Down
5 changes: 5 additions & 0 deletions tests/assembly/auxiliary/dwarf-mixed-versions-lto-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4

pub fn check_is_even(number: &u64) -> bool {
number % 2 == 0
}
19 changes: 19 additions & 0 deletions tests/assembly/dwarf-mixed-versions-lto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This test ensures that if LTO occurs between crates with different DWARF versions, we
// will choose the highest DWARF version for the final binary. This matches Clang's behavior.

//@ only-linux
//@ aux-build:dwarf-mixed-versions-lto-aux.rs
//@ compile-flags: -C lto -g -Zdwarf-version=5
//@ assembly-output: emit-asm
//@ no-prefer-dynamic

extern crate dwarf_mixed_versions_lto_aux;

fn main() {
dwarf_mixed_versions_lto_aux::check_is_even(&0);
}

// CHECK: .section .debug_info
// CHECK-NOT: {{\.(short|hword)}} 2
// CHECK-NOT: {{\.(short|hword)}} 4
// CHECK: {{\.(short|hword)}} 5
5 changes: 5 additions & 0 deletions tests/ui/lto/auxiliary/dwarf-mixed-versions-lto-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4

pub fn say_hi() {
println!("hello there")
}
15 changes: 15 additions & 0 deletions tests/ui/lto/dwarf-mixed-versions-lto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This test verifies that we do not produce a warning when performing LTO on a
// crate graph that contains a mix of different DWARF version settings. This
// matches Clang's behavior.

//@ ignore-msvc Platform must use DWARF
//@ aux-build:dwarf-mixed-versions-lto-aux.rs
//@ compile-flags: -C lto -g -Zdwarf-version=5
//@ no-prefer-dynamic
//@ build-pass

extern crate dwarf_mixed_versions_lto_aux;

fn main() {
dwarf_mixed_versions_lto_aux::say_hi();
}
Loading