Skip to content

Commit 9d443d8

Browse files
Rollup merge of rust-lang#136746 - wesleywiser:err_dwarf1, r=Urgau
Emit an error if `-Zdwarf-version=1` is requested DWARF 1 is very different than DWARF 2+[^1] and LLVM does not really seem to support DWARF 1 as Clang does not offer a `-gdwarf-1` flag[^2] and `llc` will just generate DWARF 2 with the version set to 1[^3]. 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. cc rust-lang#103057 [^1]: https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#index-gdwarf [^2]: https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-gdwarf [^3]: https://godbolt.org/z/s85d87n3a
2 parents 751be3f + 2aca0a6 commit 9d443d8

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-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 == 1 || 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

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

0 commit comments

Comments
 (0)