Skip to content

Commit aedc0a3

Browse files
authored
Rollup merge of rust-lang#135739 - wesleywiser:dwarf_version_handling, r=lqd
Clean up uses of the unstable `dwarf_version` option - Consolidate calculation of the effective value. - Check the target `DebuginfoKind` instead of using `is_like_msvc`. - Add the tracking issue to the unstable book page for this feature. cc rust-lang#103057
2 parents a366357 + 4d5a63f commit aedc0a3

File tree

5 files changed

+38
-27
lines changed

5 files changed

+38
-27
lines changed

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
919919
.unwrap_or_default();
920920
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
921921

922-
let dwarf_version =
923-
tcx.sess.opts.unstable_opts.dwarf_version.unwrap_or(tcx.sess.target.default_dwarf_version);
922+
let dwarf_version = tcx.sess.dwarf_version();
924923
let is_dwarf_kind =
925924
matches!(tcx.sess.target.debuginfo_kind, DebuginfoKind::Dwarf | DebuginfoKind::DwarfDsym);
926925
// Don't emit `.debug_pubnames` and `.debug_pubtypes` on DWARFv4 or lower.

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+26-23
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_session::config::{self, DebugInfo};
2222
use rustc_span::{
2323
BytePos, Pos, SourceFile, SourceFileAndLine, SourceFileHash, Span, StableSourceFileId, Symbol,
2424
};
25+
use rustc_target::spec::DebuginfoKind;
2526
use smallvec::SmallVec;
2627
use tracing::debug;
2728

@@ -93,29 +94,31 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
9394

9495
pub(crate) fn finalize(&self, sess: &Session) {
9596
unsafe { llvm::LLVMRustDIBuilderFinalize(self.builder) };
96-
if !sess.target.is_like_msvc {
97-
// Debuginfo generation in LLVM by default uses a higher
98-
// version of dwarf than macOS currently understands. We can
99-
// instruct LLVM to emit an older version of dwarf, however,
100-
// for macOS to understand. For more info see #11352
101-
// This can be overridden using --llvm-opts -dwarf-version,N.
102-
// Android has the same issue (#22398)
103-
let dwarf_version =
104-
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
105-
llvm::add_module_flag_u32(
106-
self.llmod,
107-
llvm::ModuleFlagMergeBehavior::Warning,
108-
"Dwarf Version",
109-
dwarf_version,
110-
);
111-
} else {
112-
// Indicate that we want CodeView debug information on MSVC
113-
llvm::add_module_flag_u32(
114-
self.llmod,
115-
llvm::ModuleFlagMergeBehavior::Warning,
116-
"CodeView",
117-
1,
118-
);
97+
98+
match sess.target.debuginfo_kind {
99+
DebuginfoKind::Dwarf | DebuginfoKind::DwarfDsym => {
100+
// Debuginfo generation in LLVM by default uses a higher
101+
// version of dwarf than macOS currently understands. We can
102+
// instruct LLVM to emit an older version of dwarf, however,
103+
// for macOS to understand. For more info see #11352
104+
// This can be overridden using --llvm-opts -dwarf-version,N.
105+
// Android has the same issue (#22398)
106+
llvm::add_module_flag_u32(
107+
self.llmod,
108+
llvm::ModuleFlagMergeBehavior::Warning,
109+
"Dwarf Version",
110+
sess.dwarf_version(),
111+
);
112+
}
113+
DebuginfoKind::Pdb => {
114+
// Indicate that we want CodeView debug information
115+
llvm::add_module_flag_u32(
116+
self.llmod,
117+
llvm::ModuleFlagMergeBehavior::Warning,
118+
"CodeView",
119+
1,
120+
);
121+
}
119122
}
120123

121124
// Prevent bitcode readers from deleting the debug info.

Diff for: compiler/rustc_session/src/options.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ options! {
18031803
"output statistics about monomorphization collection"),
18041804
dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED],
18051805
"the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"),
1806+
#[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
18061807
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
18071808
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
18081809
dylib_lto: bool = (false, parse_bool, [UNTRACKED],

Diff for: compiler/rustc_session/src/session.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ impl Session {
732732
self.opts.cg.split_debuginfo.unwrap_or(self.target.split_debuginfo)
733733
}
734734

735+
/// Returns the DWARF version passed on the CLI or the default for the target.
736+
pub fn dwarf_version(&self) -> u32 {
737+
self.opts.unstable_opts.dwarf_version.unwrap_or(self.target.default_dwarf_version)
738+
}
739+
735740
pub fn stack_protector(&self) -> StackProtector {
736741
if self.target.options.supports_stack_protector {
737742
self.opts.unstable_opts.stack_protector
@@ -1263,8 +1268,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12631268
}
12641269

12651270
if sess.opts.unstable_opts.embed_source {
1266-
let dwarf_version =
1267-
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
1271+
let dwarf_version = sess.dwarf_version();
12681272

12691273
if dwarf_version < 5 {
12701274
sess.dcx().emit_warn(errors::EmbedSourceInsufficientDwarfVersion { dwarf_version });

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

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## `dwarf-version`
22

3+
The tracking issue for this feature is: <https://github.com/rust-lang/rust/issues/103057>
4+
5+
----------------------------
6+
37
This option controls the version of DWARF that the compiler emits, on platforms
48
that use DWARF to encode debug information. It takes one of the following
59
values:

0 commit comments

Comments
 (0)