Skip to content

Commit 5378936

Browse files
committed
embed-source: explicitly require -Zdwarf-version=5
1 parent 30503f1 commit 5378936

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

compiler/rustc_session/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ session_crate_name_empty = crate name must not be empty
1414
1515
session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has a leading hyphen
1616
17+
session_embed_source_insufficient_dwarf_version = `-Cembed-source=y` requires at least `-Z dwarf-version=5` while sesssion uses version {$dwarf_version}
18+
1719
session_expr_parentheses_needed = parentheses are required to parse this as an expression
1820
1921
session_failed_to_create_profiler = failed to create profiler: {$err}

compiler/rustc_session/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ pub(crate) struct UnsupportedDwarfVersion {
163163
pub(crate) dwarf_version: u32,
164164
}
165165

166+
#[derive(Diagnostic)]
167+
#[diag(session_embed_source_insufficient_dwarf_version)]
168+
pub(crate) struct EmbedSourceInsufficientDwarfVersion {
169+
pub(crate) dwarf_version: u32,
170+
}
171+
166172
#[derive(Diagnostic)]
167173
#[diag(session_target_stack_protector_not_supported)]
168174
pub(crate) struct StackProtectorNotSupportedForTarget<'a> {

compiler/rustc_session/src/session.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,12 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13021302
.emit_err(errors::SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() });
13031303
}
13041304

1305+
let dwarf_version =
1306+
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
1307+
if sess.opts.cg.embed_source && dwarf_version < 5 {
1308+
sess.dcx().emit_err(errors::EmbedSourceInsufficientDwarfVersion { dwarf_version });
1309+
}
1310+
13051311
if sess.opts.unstable_opts.instrument_xray.is_some() && !sess.target.options.supports_xray {
13061312
sess.dcx().emit_err(errors::InstrumentationNotSupported { us: "XRay".to_string() });
13071313
}

src/doc/rustc/src/codegen-options/index.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ at start-up, because the combination is invalid.
148148
149149
## embed-source
150150

151-
TODO
151+
This flag controls whether the compiler embeds the program source code text into
152+
object debug info section. It takes one of the following values:
153+
154+
* `y`, `yes`, `on` or `true`: put source code in debug info.
155+
* `n`, `no`, `off`, `false` or no value: omit source code from debug info (the default).
156+
157+
`-C embed-source` requires DWARFv5. Use `-Zdwarf-version` to control the
158+
compiler's DWARF target version.
152159

153160
## extra-filename
154161

0 commit comments

Comments
 (0)