Skip to content

Commit 80913e4

Browse files
authored
Rollup merge of rust-lang#98350 - pcwalton:dwarf5, r=michaelwoerister
Implement support for DWARF version 5. DWARF version 5 brings a number of improvements over version 4. Quoting from the announcement [1]: > Version 5 incorporates improvements in many areas: better data compression, > separation of debugging data from executable files, improved description of > macros and source files, faster searching for symbols, improved debugging > optimized code, as well as numerous improvements in functionality and > performance. On platforms where DWARF version 5 is supported (Linux, primarily), this commit adds support for it behind a new `-Z dwarf-version=5` flag. [1]: https://dwarfstd.org/Public_Review.php r? `@michaelwoerister`
2 parents db78ab7 + 1e0ad0c commit 80913e4

File tree

13 files changed

+59
-21
lines changed

13 files changed

+59
-21
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
103103
// for macOS to understand. For more info see #11352
104104
// This can be overridden using --llvm-opts -dwarf-version,N.
105105
// Android has the same issue (#22398)
106-
if let Some(version) = sess.target.dwarf_version {
107-
llvm::LLVMRustAddModuleFlag(
108-
self.llmod,
109-
llvm::LLVMModFlagBehavior::Warning,
110-
"Dwarf Version\0".as_ptr().cast(),
111-
version,
112-
)
113-
}
106+
let dwarf_version =
107+
sess.opts.debugging_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
108+
llvm::LLVMRustAddModuleFlag(
109+
self.llmod,
110+
llvm::LLVMModFlagBehavior::Warning,
111+
"Dwarf Version\0".as_ptr().cast(),
112+
dwarf_version,
113+
);
114114

115115
// Indicate that we want CodeView debug information on MSVC
116116
if sess.target.is_like_msvc {

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ fn test_debugging_options_tracking_hash() {
733733
tracked!(dep_info_omit_d_target, true);
734734
tracked!(drop_tracking, true);
735735
tracked!(dual_proc_macros, true);
736+
tracked!(dwarf_version, Some(5));
736737
tracked!(fewer_names, Some(true));
737738
tracked!(force_unstable_if_unmarked, true);
738739
tracked!(fuel, Some(("abc".to_string(), 99)));

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,8 @@ options! {
12721272
computed `block` spans (one span encompassing a block's terminator and \
12731273
all statements). If `-Z instrument-coverage` is also enabled, create \
12741274
an additional `.html` file showing the computed coverage spans."),
1275+
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
1276+
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
12751277
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
12761278
"emit a section containing stack size metadata (default: no)"),
12771279
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],

compiler/rustc_session/src/session.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,12 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
14981498
))
14991499
}
15001500
}
1501+
1502+
if let Some(dwarf_version) = sess.opts.debugging_opts.dwarf_version {
1503+
if dwarf_version > 5 {
1504+
sess.err(&format!("requested DWARF version {} is greater than 5", dwarf_version));
1505+
}
1506+
}
15011507
}
15021508

15031509
/// Holds data on the current incremental compilation session, if there is one.

compiler/rustc_target/src/spec/android_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::spec::TargetOptions;
33
pub fn opts() -> TargetOptions {
44
let mut base = super::linux_base::opts();
55
base.os = "android".into();
6-
base.dwarf_version = Some(2);
6+
base.default_dwarf_version = 2;
77
base.position_independent_executables = true;
88
base.has_thread_local = false;
99
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867

compiler/rustc_target/src/spec/apple_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
2828
executables: true,
2929
families: cvs!["unix"],
3030
is_like_osx: true,
31-
dwarf_version: Some(2),
31+
default_dwarf_version: 2,
3232
frame_pointer: FramePointer::Always,
3333
has_rpath: true,
3434
dll_suffix: ".dylib".into(),

compiler/rustc_target/src/spec/dragonfly_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn opts() -> TargetOptions {
99
has_rpath: true,
1010
position_independent_executables: true,
1111
relro_level: RelroLevel::Full,
12-
dwarf_version: Some(2),
12+
default_dwarf_version: 2,
1313
..Default::default()
1414
}
1515
}

compiler/rustc_target/src/spec/freebsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn opts() -> TargetOptions {
1010
position_independent_executables: true,
1111
relro_level: RelroLevel::Full,
1212
abi_return_struct_as_int: true,
13-
dwarf_version: Some(2),
13+
default_dwarf_version: 2,
1414
..Default::default()
1515
}
1616
}

compiler/rustc_target/src/spec/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,9 @@ pub struct TargetOptions {
12751275
pub is_like_msvc: bool,
12761276
/// Whether a target toolchain is like WASM.
12771277
pub is_like_wasm: bool,
1278-
/// Version of DWARF to use if not using the default.
1278+
/// Default supported version of DWARF on this platform.
12791279
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
1280-
pub dwarf_version: Option<u32>,
1280+
pub default_dwarf_version: u32,
12811281
/// Whether the linker support GNU-like arguments such as -O. Defaults to true.
12821282
pub linker_is_gnu: bool,
12831283
/// The MinGW toolchain has a known issue that prevents it from correctly
@@ -1539,7 +1539,7 @@ impl Default for TargetOptions {
15391539
is_like_windows: false,
15401540
is_like_msvc: false,
15411541
is_like_wasm: false,
1542-
dwarf_version: None,
1542+
default_dwarf_version: 4,
15431543
linker_is_gnu: true,
15441544
allows_weak_linkage: true,
15451545
has_rpath: false,
@@ -1778,13 +1778,13 @@ impl Target {
17781778
base.$key_name = s;
17791779
}
17801780
} );
1781-
($key_name:ident, Option<u32>) => ( {
1781+
($key_name:ident, u32) => ( {
17821782
let name = (stringify!($key_name)).replace("_", "-");
17831783
if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) {
17841784
if s < 1 || s > 5 {
17851785
return Err("Not a valid DWARF version number".into());
17861786
}
1787-
base.$key_name = Some(s as u32);
1787+
base.$key_name = s as u32;
17881788
}
17891789
} );
17901790
($key_name:ident, Option<u64>) => ( {
@@ -2143,7 +2143,7 @@ impl Target {
21432143
key!(is_like_windows, bool);
21442144
key!(is_like_msvc, bool);
21452145
key!(is_like_wasm, bool);
2146-
key!(dwarf_version, Option<u32>);
2146+
key!(default_dwarf_version, u32);
21472147
key!(linker_is_gnu, bool);
21482148
key!(allows_weak_linkage, bool);
21492149
key!(has_rpath, bool);
@@ -2387,7 +2387,7 @@ impl ToJson for Target {
23872387
target_option_val!(is_like_windows);
23882388
target_option_val!(is_like_msvc);
23892389
target_option_val!(is_like_wasm);
2390-
target_option_val!(dwarf_version);
2390+
target_option_val!(default_dwarf_version);
23912391
target_option_val!(linker_is_gnu);
23922392
target_option_val!(allows_weak_linkage);
23932393
target_option_val!(has_rpath);

compiler/rustc_target/src/spec/netbsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn opts() -> TargetOptions {
1111
position_independent_executables: true,
1212
relro_level: RelroLevel::Full,
1313
use_ctors_section: true,
14-
dwarf_version: Some(2),
14+
default_dwarf_version: 2,
1515
..Default::default()
1616
}
1717
}

compiler/rustc_target/src/spec/openbsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn opts() -> TargetOptions {
1111
position_independent_executables: true,
1212
frame_pointer: FramePointer::Always, // FIXME 43575: should be MayOmit...
1313
relro_level: RelroLevel::Full,
14-
dwarf_version: Some(2),
14+
default_dwarf_version: 2,
1515
..Default::default()
1616
}
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## `dwarf-version`
2+
3+
This option controls the version of DWARF that the compiler emits, on platforms
4+
that use DWARF to encode debug information. It takes one of the following
5+
values:
6+
7+
* `2`: DWARF version 2 (the default on certain platforms, like macOS).
8+
* `4`: DWARF version 4 (the default on certain platforms, like Linux).
9+
* `5`: DWARF version 5.

src/test/assembly/dwarf5.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Makes sure that `-Z dwarf-version=5` causes `rustc` to emit DWARF version 5.
2+
// assembly-output: emit-asm
3+
// compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=5
4+
// needs-llvm-components: x86
5+
6+
#![feature(no_core, lang_items)]
7+
#![crate_type = "rlib"]
8+
#![no_core]
9+
10+
#[lang = "sized"]
11+
trait Sized {}
12+
#[lang = "copy"]
13+
trait Copy {}
14+
15+
pub fn wibble() {}
16+
17+
// CHECK: .section .debug_info
18+
// CHECK-NOT: .short 2
19+
// CHECK-NOT: .short 4
20+
// CHECK: .short 5

0 commit comments

Comments
 (0)