Skip to content

Commit 173f65b

Browse files
committed
Stabilize -Zdwarf-version as -Cdwarf-version
1 parent 021fb9c commit 173f65b

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
@@ -1953,6 +1953,9 @@ options! {
19531953
"allow the linker to link its default libraries (default: no)"),
19541954
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
19551955
"import library generation tool (ignored except when targeting windows-gnu)"),
1956+
#[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
1957+
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
1958+
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
19561959
embed_bitcode: bool = (true, parse_bool, [TRACKED],
19571960
"emit bitcode in rlibs (default: yes)"),
19581961
extra_filename: String = (String::new(), parse_string, [UNTRACKED],

compiler/rustc_session/src/session.rs

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

737737
/// Returns the DWARF version passed on the CLI or the default for the target.
738738
pub fn dwarf_version(&self) -> u32 {
739-
self.opts.unstable_opts.dwarf_version.unwrap_or(self.target.default_dwarf_version)
739+
self.opts
740+
.cg
741+
.dwarf_version
742+
.or(self.opts.unstable_opts.dwarf_version)
743+
.unwrap_or(self.target.default_dwarf_version)
740744
}
741745

742746
pub fn stack_protector(&self) -> StackProtector {
@@ -1250,7 +1254,9 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12501254
sess.dcx().emit_err(errors::BranchProtectionRequiresAArch64);
12511255
}
12521256

1253-
if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version {
1257+
if let Some(dwarf_version) =
1258+
sess.opts.cg.dwarf_version.or(sess.opts.unstable_opts.dwarf_version)
1259+
{
12541260
// DWARF 1 is not supported by LLVM and DWARF 6 is not yet finalized.
12551261
if dwarf_version < 2 || dwarf_version > 5 {
12561262
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
@@ -3,7 +3,7 @@
33

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

tests/assembly/dwarf4.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
3-
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=4 -Copt-level=0
3+
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -C dwarf-version=4 -Copt-level=0
44
//@ needs-llvm-components: x86
55

66
#![feature(no_core, lang_items)]

tests/assembly/dwarf5.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
//@ assembly-output: emit-asm
3-
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=5 -Copt-level=0
3+
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -C dwarf-version=5 -Copt-level=0
44
//@ needs-llvm-components: x86
55

66
#![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,27 +1,27 @@
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
//@[zero] error-pattern: requested DWARF version 0 is not supported
88

9-
//@[one] compile-flags: -Zdwarf-version=1
9+
//@[one] compile-flags: -Cdwarf-version=1
1010
//@[one] error-pattern: requested DWARF version 1 is not supported
1111

12-
//@[two] compile-flags: -Zdwarf-version=2
12+
//@[two] compile-flags: -Cdwarf-version=2
1313
//@[two] check-pass
1414

15-
//@[three] compile-flags: -Zdwarf-version=3
15+
//@[three] compile-flags: -Cdwarf-version=3
1616
//@[three] check-pass
1717

18-
//@[four] compile-flags: -Zdwarf-version=4
18+
//@[four] compile-flags: -Cdwarf-version=4
1919
//@[four] check-pass
2020

21-
//@[five] compile-flags: -Zdwarf-version=5
21+
//@[five] compile-flags: -Cdwarf-version=5
2222
//@[five] check-pass
2323

24-
//@[six] compile-flags: -Zdwarf-version=6
24+
//@[six] compile-flags: -Cdwarf-version=6
2525
//@[six] error-pattern: requested DWARF version 6 is not supported
2626

2727
//@ compile-flags: -g --target x86_64-unknown-linux-gnu --crate-type cdylib

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)