Stabilize -Zdwarf-version as -Cdwarf-version

This commit is contained in:
Wesley Wiser 2025-02-12 08:06:34 -06:00
parent 2da29dbe8f
commit e216915295
13 changed files with 42 additions and 32 deletions

View file

@ -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));

View file

@ -1956,6 +1956,9 @@ options! {
"allow the linker to link its default libraries (default: no)"),
dlltool: Option<PathBuf> = (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<u32> = (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],

View file

@ -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 });

View file

@ -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

View file

@ -1,13 +0,0 @@
## `dwarf-version`
The tracking issue for this feature is: <https://github.com/rust-lang/rust/issues/103057>
----------------------------
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.

View file

@ -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

View file

@ -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

View file

@ -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)]

View file

@ -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)]

View file

@ -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();

View file

@ -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

View file

@ -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")

View file

@ -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