Skip to content

Commit c419816

Browse files
committed
Stabilize -Zdebuginfo-compression as -Cdebuginfo-compression
1 parent 5497a36 commit c419816

8 files changed

Lines changed: 47 additions & 14 deletions

File tree

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub(crate) fn target_machine_factory(
250250

251251
let use_emulated_tls = matches!(sess.tls_model(), TlsModel::Emulated);
252252

253-
let debuginfo_compression = match sess.opts.unstable_opts.debuginfo_compression {
253+
let debuginfo_compression = match sess.debuginfo_compression() {
254254
config::DebugInfoCompression::None => llvm::CompressionKind::None,
255255
config::DebugInfoCompression::Zlib => {
256256
if llvm::LLVMRustLLVMHasZlibCompression() {

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl<'a> Linker for GccLinker<'a> {
756756
self.link_arg("--strip-all");
757757
}
758758
}
759-
match self.sess.opts.unstable_opts.debuginfo_compression {
759+
match self.sess.debuginfo_compression() {
760760
config::DebugInfoCompression::None => {}
761761
config::DebugInfoCompression::Zlib => {
762762
self.link_arg("--compress-debug-sections=zlib");

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub trait CodegenBackend {
8181
/// Value printed by `--print=backend-has-zstd`.
8282
///
8383
/// Used by compiletest to determine whether tests involving zstd compression
84-
/// (e.g. `-Zdebuginfo-compression=zstd`) should be executed or skipped.
84+
/// (e.g. `-Cdebuginfo-compression=zstd`) should be executed or skipped.
8585
fn has_zstd(&self) -> bool {
8686
false
8787
}

compiler/rustc_session/src/options.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,15 +1357,15 @@ pub mod parse {
13571357
}
13581358

13591359
pub(crate) fn parse_debuginfo_compression(
1360-
slot: &mut DebugInfoCompression,
1360+
slot: &mut Option<DebugInfoCompression>,
13611361
v: Option<&str>,
13621362
) -> bool {
1363-
match v {
1364-
Some("none") => *slot = DebugInfoCompression::None,
1365-
Some("zlib") => *slot = DebugInfoCompression::Zlib,
1366-
Some("zstd") => *slot = DebugInfoCompression::Zstd,
1363+
*slot = Some(match v {
1364+
Some("none") => DebugInfoCompression::None,
1365+
Some("zlib") => DebugInfoCompression::Zlib,
1366+
Some("zstd") => DebugInfoCompression::Zstd,
13671367
_ => return false,
1368-
};
1368+
});
13691369
true
13701370
}
13711371

@@ -2101,6 +2101,9 @@ options! {
21012101
debuginfo: DebugInfo = (DebugInfo::None, parse_debuginfo, [TRACKED],
21022102
"debug info emission level (0-2, none, line-directives-only, \
21032103
line-tables-only, limited, or full; default: 0)"),
2104+
#[rustc_lint_opt_deny_field_access("use `Session::debuginfo_compression` instead of this field")]
2105+
debuginfo_compression: Option<DebugInfoCompression> = (None, parse_debuginfo_compression, [TRACKED],
2106+
"compress debug info sections (none, zlib, zstd, default: none)"),
21042107
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
21052108
"allow the linker to link its default libraries (default: no)"),
21062109
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
@@ -2291,7 +2294,8 @@ options! {
22912294
"emit discriminators and other data necessary for AutoFDO"),
22922295
debug_info_type_line_numbers: bool = (false, parse_bool, [TRACKED],
22932296
"emit type and line information for additional data types (default: no)"),
2294-
debuginfo_compression: DebugInfoCompression = (DebugInfoCompression::None, parse_debuginfo_compression, [TRACKED],
2297+
#[rustc_lint_opt_deny_field_access("use `Session::debuginfo_compression` instead of this field")]
2298+
debuginfo_compression: Option<DebugInfoCompression> = (None, parse_debuginfo_compression, [TRACKED],
22952299
"compress debug info sections (none, zlib, zstd, default: none)"),
22962300
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
22972301
"deduplicate identical diagnostics (default: yes)"),

compiler/rustc_session/src/session.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ use rustc_target::spec::{
3737
use crate::code_stats::CodeStats;
3838
pub use crate::code_stats::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
3939
use crate::config::{
40-
self, CoverageLevel, CoverageOptions, CrateType, DebugInfo, ErrorOutputType, FunctionReturn,
41-
Input, InstrumentCoverage, OptLevel, OutFileName, OutputType, SwitchWithOptPath,
40+
self, CoverageLevel, CoverageOptions, CrateType, DebugInfo, DebugInfoCompression,
41+
ErrorOutputType, FunctionReturn, Input, InstrumentCoverage, OptLevel, OutFileName, OutputType,
42+
SwitchWithOptPath,
4243
};
4344
use crate::filesearch::FileSearch;
4445
use crate::lint::LintId;
@@ -713,6 +714,14 @@ impl Session {
713714
.unwrap_or(self.target.default_dwarf_version)
714715
}
715716

717+
pub fn debuginfo_compression(&self) -> DebugInfoCompression {
718+
self.opts
719+
.cg
720+
.debuginfo_compression
721+
.or(self.opts.unstable_opts.debuginfo_compression)
722+
.unwrap_or(DebugInfoCompression::None)
723+
}
724+
716725
pub fn stack_protector(&self) -> StackProtector {
717726
if self.target.options.supports_stack_protector {
718727
self.opts.unstable_opts.stack_protector

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ following values:
9191

9292
Note: The [`-g` flag][option-g-debug] is an alias for `-C debuginfo=2`.
9393

94+
## debuginfo-compression
95+
96+
This flag controls how debug information is compressed. It takes one of the
97+
following values:
98+
99+
* `none`: debug info is not compressed (the default).
100+
* `zlib`: debug info is compressed using zlib.
101+
* `zstd`: debug info is compressed using zstd.
102+
103+
Tools which read debug info such as debuggers and profilers must support the
104+
compression algorithm or they will be unable to process the debug info. `zlib`
105+
compression tends to be well supported by Linux tools but `zstd` may require
106+
very recent versions of such tools.
107+
108+
Compressing debug info can improve binary size but will increase time and memory
109+
used during compilation.
110+
111+
This flag is ignored by the compiler if the target does not support the specified
112+
compression algorithm.
113+
94114
## default-linker-libraries
95115

96116
This flag controls whether or not the linker includes its default libraries.

tests/run-make/compressed-debuginfo-zstd/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use run_make_support::{Rustc, llvm_readobj, run_in_tmpdir};
1313
fn check_compression(compression: &str, to_find: &str) {
1414
// check compressed debug sections via rustc flag
1515
prepare_and_check(to_find, |rustc| {
16-
rustc.arg(&format!("-Zdebuginfo-compression={compression}"))
16+
rustc.arg(&format!("-Cdebuginfo-compression={compression}"))
1717
});
1818

1919
// check compressed debug sections via rust-lld flag

tests/run-make/compressed-debuginfo/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn check_compression(compression: &str, to_find: &str) {
1414
.crate_type("lib")
1515
.emit("obj")
1616
.arg("-Cdebuginfo=full")
17-
.arg(&format!("-Zdebuginfo-compression={compression}"))
17+
.arg(&format!("-Cdebuginfo-compression={compression}"))
1818
.input("foo.rs")
1919
.run();
2020
let stderr = out.stderr_utf8();

0 commit comments

Comments
 (0)