Skip to content

Commit 12fdab0

Browse files
committed
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 withing 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 updates the test added in the previous commit to ensure no warning is printed.
1 parent d4081bc commit 12fdab0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
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
);

tests/ui/lto/dwarf-mixed-versions-lto.stderr

-4
This file was deleted.

0 commit comments

Comments
 (0)