From e21691529549152625a509e7e69af0b813420c53 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Wed, 12 Feb 2025 08:06:34 -0600 Subject: [PATCH] Stabilize `-Zdwarf-version` as `-Cdwarf-version` --- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_session/src/options.rs | 3 +++ compiler/rustc_session/src/session.rs | 10 ++++++++-- src/doc/rustc/src/codegen-options/index.md | 13 +++++++++++++ .../src/compiler-flags/dwarf-version.md | 13 ------------- .../auxiliary/dwarf-mixed-versions-lto-aux.rs | 2 +- tests/assembly/dwarf-mixed-versions-lto.rs | 2 +- tests/assembly/dwarf4.rs | 4 ++-- tests/assembly/dwarf5.rs | 4 ++-- tests/run-make/embed-source-dwarf/rmake.rs | 2 +- tests/ui/debuginfo/dwarf-versions.rs | 16 ++++++++-------- .../auxiliary/dwarf-mixed-versions-lto-aux.rs | 2 +- tests/ui/lto/dwarf-mixed-versions-lto.rs | 2 +- 13 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 src/doc/unstable-book/src/compiler-flags/dwarf-version.md diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 75a1b61b41650..d405d044cae66 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -614,6 +614,7 @@ fn test_codegen_options_tracking_hash() { tracked!(control_flow_guard, CFGuard::Checks); tracked!(debug_assertions, Some(true)); tracked!(debuginfo, DebugInfo::Limited); + tracked!(dwarf_version, Some(5)); tracked!(embed_bitcode, false); tracked!(force_frame_pointers, FramePointer::Always); tracked!(force_unwind_tables, Some(true)); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index c70f1500d3930..ea3a1f8bd8cc7 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1956,6 +1956,9 @@ options! { "allow the linker to link its default libraries (default: no)"), dlltool: Option = (None, parse_opt_pathbuf, [UNTRACKED], "import library generation tool (ignored except when targeting windows-gnu)"), + #[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")] + dwarf_version: Option = (None, parse_opt_number, [TRACKED], + "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"), embed_bitcode: bool = (true, parse_bool, [TRACKED], "emit bitcode in rlibs (default: yes)"), extra_filename: String = (String::new(), parse_string, [UNTRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 1359f7eb7bb4e..010ae42c2802d 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -764,7 +764,11 @@ impl Session { /// Returns the DWARF version passed on the CLI or the default for the target. pub fn dwarf_version(&self) -> u32 { - self.opts.unstable_opts.dwarf_version.unwrap_or(self.target.default_dwarf_version) + self.opts + .cg + .dwarf_version + .or(self.opts.unstable_opts.dwarf_version) + .unwrap_or(self.target.default_dwarf_version) } pub fn stack_protector(&self) -> StackProtector { @@ -1327,7 +1331,9 @@ fn validate_commandline_args_with_session_available(sess: &Session) { sess.dcx().emit_err(errors::BranchProtectionRequiresAArch64); } - if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version { + if let Some(dwarf_version) = + sess.opts.cg.dwarf_version.or(sess.opts.unstable_opts.dwarf_version) + { // DWARF 1 is not supported by LLVM and DWARF 6 is not yet finalized. if dwarf_version < 2 || dwarf_version > 5 { sess.dcx().emit_err(errors::UnsupportedDwarfVersion { dwarf_version }); diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 8c1769a8c7722..a3b70e7f97711 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -110,6 +110,19 @@ It takes a path to [the dlltool executable](https://sourceware.org/binutils/docs If this flag is not specified, a dlltool executable will be inferred based on the host environment and target. +## dwarf-version + +This option controls the version of DWARF that the compiler emits, on platforms +that use DWARF to encode debug information. It takes one of the following +values: + +* `2`: DWARF version 2 (the default on certain platforms, like Android). +* `3`: DWARF version 3 (the default on certain platforms, like AIX). +* `4`: DWARF version 4 (the default on most platforms, like Linux & macOS). +* `5`: DWARF version 5. + +DWARF version 1 is not supported. + ## embed-bitcode This flag controls whether or not the compiler embeds LLVM bitcode into object diff --git a/src/doc/unstable-book/src/compiler-flags/dwarf-version.md b/src/doc/unstable-book/src/compiler-flags/dwarf-version.md deleted file mode 100644 index e88799d2cf044..0000000000000 --- a/src/doc/unstable-book/src/compiler-flags/dwarf-version.md +++ /dev/null @@ -1,13 +0,0 @@ -## `dwarf-version` - -The tracking issue for this feature is: - ----------------------------- - -This option controls the version of DWARF that the compiler emits, on platforms -that use DWARF to encode debug information. It takes one of the following -values: - -* `2`: DWARF version 2 (the default on certain platforms, like macOS). -* `4`: DWARF version 4 (the default on certain platforms, like Linux). -* `5`: DWARF version 5. diff --git a/tests/assembly/auxiliary/dwarf-mixed-versions-lto-aux.rs b/tests/assembly/auxiliary/dwarf-mixed-versions-lto-aux.rs index faff6e7e2d052..257608f881f16 100644 --- a/tests/assembly/auxiliary/dwarf-mixed-versions-lto-aux.rs +++ b/tests/assembly/auxiliary/dwarf-mixed-versions-lto-aux.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4 +//@ compile-flags: -g --crate-type=rlib -Cdwarf-version=4 pub fn check_is_even(number: &u64) -> bool { number % 2 == 0 diff --git a/tests/assembly/dwarf-mixed-versions-lto.rs b/tests/assembly/dwarf-mixed-versions-lto.rs index f1fc0814c9db6..9910a6e2f5fcc 100644 --- a/tests/assembly/dwarf-mixed-versions-lto.rs +++ b/tests/assembly/dwarf-mixed-versions-lto.rs @@ -4,7 +4,7 @@ //@ only-linux //@ aux-build:dwarf-mixed-versions-lto-aux.rs -//@ compile-flags: -C lto -g -Zdwarf-version=5 +//@ compile-flags: -C lto -g -Cdwarf-version=5 //@ assembly-output: emit-asm //@ no-prefer-dynamic diff --git a/tests/assembly/dwarf4.rs b/tests/assembly/dwarf4.rs index 6013adf3386ae..03a388603b44b 100644 --- a/tests/assembly/dwarf4.rs +++ b/tests/assembly/dwarf4.rs @@ -1,7 +1,7 @@ -// Makes sure that `-Z dwarf-version=4` causes `rustc` to emit DWARF version 4. +// Makes sure that `-C dwarf-version=4` causes `rustc` to emit DWARF version 4. //@ assembly-output: emit-asm //@ add-core-stubs -//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=4 -Copt-level=0 +//@ compile-flags: -g --target x86_64-unknown-linux-gnu -C dwarf-version=4 -Copt-level=0 //@ needs-llvm-components: x86 #![feature(no_core, lang_items)] diff --git a/tests/assembly/dwarf5.rs b/tests/assembly/dwarf5.rs index 9cd596e783459..9bd92cc0d0979 100644 --- a/tests/assembly/dwarf5.rs +++ b/tests/assembly/dwarf5.rs @@ -1,7 +1,7 @@ -// Makes sure that `-Z dwarf-version=5` causes `rustc` to emit DWARF version 5. +// Makes sure that `-C dwarf-version=5` causes `rustc` to emit DWARF version 5. //@ add-core-stubs //@ assembly-output: emit-asm -//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=5 -Copt-level=0 +//@ compile-flags: -g --target x86_64-unknown-linux-gnu -C dwarf-version=5 -Copt-level=0 //@ needs-llvm-components: x86 #![feature(no_core, lang_items)] diff --git a/tests/run-make/embed-source-dwarf/rmake.rs b/tests/run-make/embed-source-dwarf/rmake.rs index 0aae07ff2e647..550c8b9b3c903 100644 --- a/tests/run-make/embed-source-dwarf/rmake.rs +++ b/tests/run-make/embed-source-dwarf/rmake.rs @@ -21,7 +21,7 @@ fn main() { .output(&output) .arg("-g") .arg("-Zembed-source=yes") - .arg("-Zdwarf-version=5") + .arg("-Cdwarf-version=5") .run(); let output = rfs::read(output); let obj = object::File::parse(output.as_slice()).unwrap(); diff --git a/tests/ui/debuginfo/dwarf-versions.rs b/tests/ui/debuginfo/dwarf-versions.rs index bb18cadce4352..8f731f10ead4b 100644 --- a/tests/ui/debuginfo/dwarf-versions.rs +++ b/tests/ui/debuginfo/dwarf-versions.rs @@ -1,25 +1,25 @@ // This test verifies the expected behavior of various options passed to -// `-Zdwarf-version`: 2 - 5 (valid) with all other options being invalid. +// `-Cdwarf-version`: 2 - 5 (valid) with all other options being invalid. //@ revisions: zero one two three four five six -//@[zero] compile-flags: -Zdwarf-version=0 +//@[zero] compile-flags: -Cdwarf-version=0 -//@[one] compile-flags: -Zdwarf-version=1 +//@[one] compile-flags: -Cdwarf-version=1 -//@[two] compile-flags: -Zdwarf-version=2 +//@[two] compile-flags: -Cdwarf-version=2 //@[two] check-pass -//@[three] compile-flags: -Zdwarf-version=3 +//@[three] compile-flags: -Cdwarf-version=3 //@[three] check-pass -//@[four] compile-flags: -Zdwarf-version=4 +//@[four] compile-flags: -Cdwarf-version=4 //@[four] check-pass -//@[five] compile-flags: -Zdwarf-version=5 +//@[five] compile-flags: -Cdwarf-version=5 //@[five] check-pass -//@[six] compile-flags: -Zdwarf-version=6 +//@[six] compile-flags: -Cdwarf-version=6 //@ compile-flags: -g --target x86_64-unknown-linux-gnu --crate-type cdylib //@ needs-llvm-components: x86 diff --git a/tests/ui/lto/auxiliary/dwarf-mixed-versions-lto-aux.rs b/tests/ui/lto/auxiliary/dwarf-mixed-versions-lto-aux.rs index 3c81127ee65c0..2f2bf57f42b4f 100644 --- a/tests/ui/lto/auxiliary/dwarf-mixed-versions-lto-aux.rs +++ b/tests/ui/lto/auxiliary/dwarf-mixed-versions-lto-aux.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -g --crate-type=rlib -Zdwarf-version=4 +//@ compile-flags: -g --crate-type=rlib -Cdwarf-version=4 pub fn say_hi() { println!("hello there") diff --git a/tests/ui/lto/dwarf-mixed-versions-lto.rs b/tests/ui/lto/dwarf-mixed-versions-lto.rs index 14ef65a868e02..900274eb22f44 100644 --- a/tests/ui/lto/dwarf-mixed-versions-lto.rs +++ b/tests/ui/lto/dwarf-mixed-versions-lto.rs @@ -4,7 +4,7 @@ //@ ignore-msvc Platform must use DWARF //@ aux-build:dwarf-mixed-versions-lto-aux.rs -//@ compile-flags: -C lto -g -Zdwarf-version=5 +//@ compile-flags: -C lto -g -Cdwarf-version=5 //@ no-prefer-dynamic //@ build-pass