Skip to content

Commit afa859f

Browse files
committed
Auto merge of rust-lang#136926 - wesleywiser:stabilize_dwarf-version, r=petrochenkov
Stabilize `-Zdwarf-version` as `-Cdwarf-version` I propose stabilizing `-Zdwarf-version` as `-Cdwarf-version`. This PR adds a new `-Cdwarf-version` flag, leaving the unstable `-Z` flag as is to ease the transition period. The `-Z` flag will be removed in the future. # `-Zdwarf-version` stabilization report ## What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized? No RFC/MCP, this flag was added in rust-lang#98350 and was not deemed large enough to require additional process. The tracking issue for this feature is rust-lang#103057. ## What behavior are we committing to that has been controversial? Summarize the major arguments pro/con. None that has been extensively debated but there are a few questions that could have been chosen differently: 1. What should the flag name be? The current flag name is very specific to DWARF. Other debuginfo formats exist (msvc's CodeView format or https://en.wikipedia.org/wiki/Stabs) so we could have chosen to generalize the flag name (`-{C,Z} debuginfo-version=dwarf-5` for example). While this would extend cleanly to support formats other than DWARF, there are some downsides to this design. Neither CodeView nor Stabs have specification or format versions so it's not clear what values would be supported beyond `dwarf-{2,3,4,5}` or `codeview`. We would also need to take care to ensure the name does not lead users to think they can pick a format other than one supported by the target. For instance, what would `--target x86_64-pc-windows-msvc -Cdebuginfo-version=dwarf-5` do? 2. What is the behavior when flag is used on targets that do not support DWARF? Currently, passing `-{C,Z} dwarf-version` on targets like `*-windows-msvc` does not do anything. It may be preferable to emit a warning alerting the user that the flag has no effect on the target platform. Alternatively, we could emit an error but this could be annoying since it would require the use of target specific RUSTFLAGS to use the flag correctly (and there isn't a way to target "any platform that uses DWARF" using cfgs). 3. Does the precompiled standard library potentially using a different version of DWARF a problem? I don't believe this is an issue as debuggers (and other such tools) already must deal with the possibility that an application uses different DWARF versions across its statically or dynamically linked libraries. ## Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those. No extensions per se, although future DWARF versions could be considered as such. At present, we validate the requested DWARF version is between 2 and 5 (inclusive) so new DWARF versions will not automatically be supported until the validation logic is adjusted. ## Summarize the major parts of the implementation and provide links into the code (or to PRs) - Targets define their preferred or default DWARF version: https://github.com/rust-lang/rust/blob/34a5ea911c56e79bd451c63f04ea2f5023d7d1a3/compiler/rustc_target/src/spec/mod.rs#L2369 - We use the target default but this can be overriden by `-{C,Z} dwarf-version` https://github.com/rust-lang/rust/blob/34a5ea911c56e79bd451c63f04ea2f5023d7d1a3/compiler/rustc_session/src/session.rs#L738 - The flag is validated https://github.com/rust-lang/rust/blob/34a5ea911c56e79bd451c63f04ea2f5023d7d1a3/compiler/rustc_session/src/session.rs#L1253-L1258 - When debuginfo is generated, we tell LLVM to use the requested value or the target default https://github.com/rust-lang/rust/blob/34a5ea911c56e79bd451c63f04ea2f5023d7d1a3/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs#L106 ## Summarize existing test coverage of this feature - Test that we actually generate the appropriate DWARF version - https://github.com/rust-lang/rust/blob/master/tests/assembly/dwarf5.rs - https://github.com/rust-lang/rust/blob/master/tests/assembly/dwarf4.rs - Test that LTO with different DWARF versions picks the highest version - https://github.com/rust-lang/rust/blob/master/tests/assembly/dwarf-mixed-versions-lto.rs - Test DWARF versions 2-5 are valid while 0, 1 and 6 report an error - https://github.com/rust-lang/rust/blob/master/tests/ui/debuginfo/dwarf-versions.rs - Ensure LLVM does not report a warning when LTO'ing different DWARF versions together - https://github.com/rust-lang/rust/blob/master/tests/ui/lto/dwarf-mixed-versions-lto.rs ## Has a call-for-testing period been conducted? If so, what feedback was received? No call-for-testing has been conducted but Rust for Linux has been using this flag without issue. ## What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking? All reported bugs have been resolved. ## Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization - Initial implementation in rust-lang#98350 by `@pcwalton` - Stop emitting `.debug_pubnames` and `.debug_pubtypes` when using DWARF 5 in rust-lang#117962 by `@weihanglo.` - Refactoring & cleanups (rust-lang#135739), fix LLVM warning on LTO with different DWARF versions (rust-lang#136659) and argument validation (rust-lang#136746) by `@wesleywiser` ## What FIXMEs are still in the code for that feature and why is it ok to leave them there? No FIXMEs related to this feature. ## What static checks are done that are needed to prevent undefined behavior? This feature cannot cause undefined behavior. We ensure the DWARF version is one of the supported values [here](https://github.com/rust-lang/rust/blob/34a5ea911c56e79bd451c63f04ea2f5023d7d1a3/compiler/rustc_session/src/session.rs#L1255-L1257). ## In what way does this feature interact with the reference/specification, and are those edits prepared? No changes to reference/spec, unstable rustc docs are moved to the stable book as part of the stabilization PR. ## Does this feature introduce new expressions and can they produce temporaries? What are the lifetimes of those temporaries? No. ## What other unstable features may be exposed by this feature? `-Zembed-source` requires use of DWARF 5 extensions but has its own feature gate. ## What is tooling support like for this feature, w.r.t rustdoc, clippy, rust-analzyer, rustfmt, etc.? No support needed for rustdoc, clippy, rust-analyzer, rustfmt or rustup. Cargo could expose this as an option in build profiles but I would expect the decision as to what version should be used would be made for the entire crate graph at build time rather than by individual package authors. cc-rs has support for detecting the presence of `-{C,Z} dwarf-version` in `RUSTFLAGS` and providing the corresponding flag to Clang/gcc (rust-lang/cc-rs#1395). --- Closes rust-lang#103057
2 parents efb1e3d + e216915 commit afa859f

File tree

13 files changed

+42
-32
lines changed

13 files changed

+42
-32
lines changed

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ fn test_codegen_options_tracking_hash() {
614614
tracked!(control_flow_guard, CFGuard::Checks);
615615
tracked!(debug_assertions, Some(true));
616616
tracked!(debuginfo, DebugInfo::Limited);
617+
tracked!(dwarf_version, Some(5));
617618
tracked!(embed_bitcode, false);
618619
tracked!(force_frame_pointers, FramePointer::Always);
619620
tracked!(force_unwind_tables, Some(true));

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,9 @@ options! {
19561956
"allow the linker to link its default libraries (default: no)"),
19571957
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
19581958
"import library generation tool (ignored except when targeting windows-gnu)"),
1959+
#[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
1960+
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
1961+
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
19591962
embed_bitcode: bool = (true, parse_bool, [TRACKED],
19601963
"emit bitcode in rlibs (default: yes)"),
19611964
extra_filename: String = (String::new(), parse_string, [UNTRACKED],

compiler/rustc_session/src/session.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,11 @@ impl Session {
764764

765765
/// Returns the DWARF version passed on the CLI or the default for the target.
766766
pub fn dwarf_version(&self) -> u32 {
767-
self.opts.unstable_opts.dwarf_version.unwrap_or(self.target.default_dwarf_version)
767+
self.opts
768+
.cg
769+
.dwarf_version
770+
.or(self.opts.unstable_opts.dwarf_version)
771+
.unwrap_or(self.target.default_dwarf_version)
768772
}
769773

770774
pub fn stack_protector(&self) -> StackProtector {
@@ -1327,7 +1331,9 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13271331
sess.dcx().emit_err(errors::BranchProtectionRequiresAArch64);
13281332
}
13291333

1330-
if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version {
1334+
if let Some(dwarf_version) =
1335+
sess.opts.cg.dwarf_version.or(sess.opts.unstable_opts.dwarf_version)
1336+
{
13311337
// DWARF 1 is not supported by LLVM and DWARF 6 is not yet finalized.
13321338
if dwarf_version < 2 || dwarf_version > 5 {
13331339
sess.dcx().emit_err(errors::UnsupportedDwarfVersion { dwarf_version });

src/doc/rustc/src/codegen-options/index.md

+13
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ It takes a path to [the dlltool executable](https://sourceware.org/binutils/docs
110110
If this flag is not specified, a dlltool executable will be inferred based on
111111
the host environment and target.
112112

113+
## dwarf-version
114+
115+
This option controls the version of DWARF that the compiler emits, on platforms
116+
that use DWARF to encode debug information. It takes one of the following
117+
values:
118+
119+
* `2`: DWARF version 2 (the default on certain platforms, like Android).
120+
* `3`: DWARF version 3 (the default on certain platforms, like AIX).
121+
* `4`: DWARF version 4 (the default on most platforms, like Linux & macOS).
122+
* `5`: DWARF version 5.
123+
124+
DWARF version 1 is not supported.
125+
113126
## embed-bitcode
114127

115128
This flag controls whether or not the compiler embeds LLVM bitcode into object

src/doc/unstable-book/src/compiler-flags/dwarf-version.md

-13
This file was deleted.

tests/assembly/auxiliary/dwarf-mixed-versions-lto-aux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4
1+
//@ compile-flags: -g --crate-type=rlib -Cdwarf-version=4
22

33
pub fn check_is_even(number: &u64) -> bool {
44
number % 2 == 0

tests/assembly/dwarf-mixed-versions-lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//@ only-linux
66
//@ aux-build:dwarf-mixed-versions-lto-aux.rs
7-
//@ compile-flags: -C lto -g -Zdwarf-version=5
7+
//@ compile-flags: -C lto -g -Cdwarf-version=5
88
//@ assembly-output: emit-asm
99
//@ no-prefer-dynamic
1010

tests/assembly/dwarf4.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Makes sure that `-Z dwarf-version=4` causes `rustc` to emit DWARF version 4.
1+
// Makes sure that `-C dwarf-version=4` causes `rustc` to emit DWARF version 4.
22
//@ assembly-output: emit-asm
33
//@ add-core-stubs
4-
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=4 -Copt-level=0
4+
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -C dwarf-version=4 -Copt-level=0
55
//@ needs-llvm-components: x86
66

77
#![feature(no_core, lang_items)]

tests/assembly/dwarf5.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Makes sure that `-Z dwarf-version=5` causes `rustc` to emit DWARF version 5.
1+
// Makes sure that `-C dwarf-version=5` causes `rustc` to emit DWARF version 5.
22
//@ add-core-stubs
33
//@ assembly-output: emit-asm
4-
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=5 -Copt-level=0
4+
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -C dwarf-version=5 -Copt-level=0
55
//@ needs-llvm-components: x86
66

77
#![feature(no_core, lang_items)]

tests/run-make/embed-source-dwarf/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
.output(&output)
2222
.arg("-g")
2323
.arg("-Zembed-source=yes")
24-
.arg("-Zdwarf-version=5")
24+
.arg("-Cdwarf-version=5")
2525
.run();
2626
let output = rfs::read(output);
2727
let obj = object::File::parse(output.as_slice()).unwrap();

tests/ui/debuginfo/dwarf-versions.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// This test verifies the expected behavior of various options passed to
2-
// `-Zdwarf-version`: 2 - 5 (valid) with all other options being invalid.
2+
// `-Cdwarf-version`: 2 - 5 (valid) with all other options being invalid.
33

44
//@ revisions: zero one two three four five six
55

6-
//@[zero] compile-flags: -Zdwarf-version=0
6+
//@[zero] compile-flags: -Cdwarf-version=0
77

8-
//@[one] compile-flags: -Zdwarf-version=1
8+
//@[one] compile-flags: -Cdwarf-version=1
99

10-
//@[two] compile-flags: -Zdwarf-version=2
10+
//@[two] compile-flags: -Cdwarf-version=2
1111
//@[two] check-pass
1212

13-
//@[three] compile-flags: -Zdwarf-version=3
13+
//@[three] compile-flags: -Cdwarf-version=3
1414
//@[three] check-pass
1515

16-
//@[four] compile-flags: -Zdwarf-version=4
16+
//@[four] compile-flags: -Cdwarf-version=4
1717
//@[four] check-pass
1818

19-
//@[five] compile-flags: -Zdwarf-version=5
19+
//@[five] compile-flags: -Cdwarf-version=5
2020
//@[five] check-pass
2121

22-
//@[six] compile-flags: -Zdwarf-version=6
22+
//@[six] compile-flags: -Cdwarf-version=6
2323

2424
//@ compile-flags: -g --target x86_64-unknown-linux-gnu --crate-type cdylib
2525
//@ needs-llvm-components: x86

tests/ui/lto/auxiliary/dwarf-mixed-versions-lto-aux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4
1+
//@ compile-flags: -g --crate-type=rlib -Cdwarf-version=4
22

33
pub fn say_hi() {
44
println!("hello there")

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//@ ignore-msvc Platform must use DWARF
66
//@ aux-build:dwarf-mixed-versions-lto-aux.rs
7-
//@ compile-flags: -C lto -g -Zdwarf-version=5
7+
//@ compile-flags: -C lto -g -Cdwarf-version=5
88
//@ no-prefer-dynamic
99
//@ build-pass
1010

0 commit comments

Comments
 (0)