Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 513912d

Browse files
committedFeb 8, 2025·
Emit an error if -Zdwarf-version=1 is requested
DWARF 1 is very different than DWARF 2+ (see the commentary in https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#index-gdwarf) and LLVM does not really seem to support DWARF 1 as Clang does not offer a `-gdwarf-1` flag and `llc` will just generate DWARF 2 with the version set to 1: https://godbolt.org/z/s85d87n3a. Since this isn't actually supported (and it's not clear it would be useful anyway), report that DWARF 1 is not supported if it is requested. Also add a help message to the error saying which versions are supported.
1 parent 8ad2c97 commit 513912d

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed
 

‎compiler/rustc_session/messages.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination`
133133
session_unsupported_crate_type_for_target =
134134
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`
135135
136-
session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is greater than 5
136+
session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is not supported
137+
session_unsupported_dwarf_version_help = valid DWARF versions are 2 - 5
137138
138139
session_unsupported_reg_struct_return_arch = `-Zreg-struct-return` is only supported on x86
139140
session_unsupported_regparm = `-Zregparm={$regparm}` is unsupported (valid values 0-3)

‎compiler/rustc_session/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub(crate) struct UnstableVirtualFunctionElimination;
161161

162162
#[derive(Diagnostic)]
163163
#[diag(session_unsupported_dwarf_version)]
164+
#[help(session_unsupported_dwarf_version_help)]
164165
pub(crate) struct UnsupportedDwarfVersion {
165166
pub(crate) dwarf_version: u32,
166167
}

‎compiler/rustc_session/src/session.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,8 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12511251
}
12521252

12531253
if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version {
1254-
if dwarf_version > 5 {
1254+
// DWARF 1 is not supported by LLVM and DWARF 6 is not yet finalized.
1255+
if dwarf_version == 1 || dwarf_version > 5 {
12551256
sess.dcx().emit_err(errors::UnsupportedDwarfVersion { dwarf_version });
12561257
}
12571258
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: requested DWARF version 1 is not supported
2+
|
3+
= help: valid DWARF versions are 2 - 5
4+
5+
error: aborting due to 1 previous error
6+

‎tests/ui/debuginfo/dwarf-versions.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@ revisions: one two three four five six
2+
3+
//@[one] compile-flags: -Zdwarf-version=1
4+
5+
//@[two] compile-flags: -Zdwarf-version=2
6+
//@[two] check-pass
7+
8+
//@[three] compile-flags: -Zdwarf-version=3
9+
//@[three] check-pass
10+
11+
//@[four] compile-flags: -Zdwarf-version=4
12+
//@[four] check-pass
13+
14+
//@[five] compile-flags: -Zdwarf-version=5
15+
//@[five] check-pass
16+
17+
//@[six] compile-flags: -Zdwarf-version=6
18+
19+
//@ compile-flags: -g --target x86_64-unknown-linux-gnu --crate-type cdylib
20+
//@ needs-llvm-components: x86
21+
22+
// This test verifies the expected behavior of various options passed
23+
// to `-Zdwarf-version`: 1 & 6 (not supported), 2 - 5 (valid)
24+
25+
#![feature(no_core, lang_items)]
26+
27+
#![no_core]
28+
#![no_std]
29+
30+
#[lang = "sized"]
31+
pub trait Sized {}
32+
33+
pub fn foo() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: requested DWARF version 6 is not supported
2+
|
3+
= help: valid DWARF versions are 2 - 5
4+
5+
error: aborting due to 1 previous error
6+

0 commit comments

Comments
 (0)
Please sign in to comment.