forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#136659 - wesleywiser:dwarf_version_lto_merg…
…e_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
- Loading branch information
Showing
5 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |