Skip to content

Commit eea8ce5

Browse files
committed
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 eea8ce5

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

Diff for: compiler/rustc_session/messages.ftl

+2-1
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 = supported DWARF versions are 2, 3, 4 and 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)

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

+1
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
}

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

+2-1
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 < 2 || dwarf_version > 5 {
12551256
sess.dcx().emit_err(errors::UnsupportedDwarfVersion { dwarf_version });
12561257
}
12571258
}

Diff for: tests/ui/debuginfo/dwarf-versions.one.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: requested DWARF version 1 is not supported
2+
|
3+
= help: supported DWARF versions are 2, 3, 4 and 5
4+
5+
error: aborting due to 1 previous error
6+

Diff for: tests/ui/debuginfo/dwarf-versions.rs

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

Diff for: tests/ui/debuginfo/dwarf-versions.six.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: requested DWARF version 6 is not supported
2+
|
3+
= help: supported DWARF versions are 2, 3, 4 and 5
4+
5+
error: aborting due to 1 previous error
6+

Diff for: tests/ui/debuginfo/dwarf-versions.zero.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: requested DWARF version 0 is not supported
2+
|
3+
= help: supported DWARF versions are 2, 3, 4 and 5
4+
5+
error: aborting due to 1 previous error
6+

0 commit comments

Comments
 (0)