Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub(crate) fn target_machine_factory(

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

let debuginfo_compression = match sess.opts.unstable_opts.debuginfo_compression {
let debuginfo_compression = match sess.debuginfo_compression() {
config::DebugInfoCompression::None => llvm::CompressionKind::None,
config::DebugInfoCompression::Zlib => {
if llvm::LLVMRustLLVMHasZlibCompression() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl<'a> Linker for GccLinker<'a> {
self.link_arg("--strip-all");
}
}
match self.sess.opts.unstable_opts.debuginfo_compression {
match self.sess.debuginfo_compression() {
config::DebugInfoCompression::None => {}
config::DebugInfoCompression::Zlib => {
self.link_arg("--compress-debug-sections=zlib");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub trait CodegenBackend {
/// Value printed by `--print=backend-has-zstd`.
///
/// Used by compiletest to determine whether tests involving zstd compression
/// (e.g. `-Zdebuginfo-compression=zstd`) should be executed or skipped.
/// (e.g. `-Cdebuginfo-compression=zstd`) should be executed or skipped.
fn has_zstd(&self) -> bool {
false
}
Expand Down
18 changes: 11 additions & 7 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,15 +1357,15 @@ pub mod parse {
}

pub(crate) fn parse_debuginfo_compression(
slot: &mut DebugInfoCompression,
slot: &mut Option<DebugInfoCompression>,
v: Option<&str>,
) -> bool {
match v {
Some("none") => *slot = DebugInfoCompression::None,
Some("zlib") => *slot = DebugInfoCompression::Zlib,
Some("zstd") => *slot = DebugInfoCompression::Zstd,
*slot = Some(match v {
Some("none") => DebugInfoCompression::None,
Some("zlib") => DebugInfoCompression::Zlib,
Some("zstd") => DebugInfoCompression::Zstd,
_ => return false,
};
});
true
}

Expand Down Expand Up @@ -2101,6 +2101,9 @@ options! {
debuginfo: DebugInfo = (DebugInfo::None, parse_debuginfo, [TRACKED],
"debug info emission level (0-2, none, line-directives-only, \
line-tables-only, limited, or full; default: 0)"),
#[rustc_lint_opt_deny_field_access("use `Session::debuginfo_compression` instead of this field")]
debuginfo_compression: Option<DebugInfoCompression> = (None, parse_debuginfo_compression, [TRACKED],
"compress debug info sections (none, zlib, zstd, default: none)"),
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
"allow the linker to link its default libraries (default: no)"),
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
Expand Down Expand Up @@ -2291,7 +2294,8 @@ options! {
"emit discriminators and other data necessary for AutoFDO"),
debug_info_type_line_numbers: bool = (false, parse_bool, [TRACKED],
"emit type and line information for additional data types (default: no)"),
debuginfo_compression: DebugInfoCompression = (DebugInfoCompression::None, parse_debuginfo_compression, [TRACKED],
#[rustc_lint_opt_deny_field_access("use `Session::debuginfo_compression` instead of this field")]
debuginfo_compression: Option<DebugInfoCompression> = (None, parse_debuginfo_compression, [TRACKED],
"compress debug info sections (none, zlib, zstd, default: none)"),
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
"deduplicate identical diagnostics (default: yes)"),
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ use rustc_target::spec::{
use crate::code_stats::CodeStats;
pub use crate::code_stats::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
use crate::config::{
self, CoverageLevel, CoverageOptions, CrateType, DebugInfo, ErrorOutputType, FunctionReturn,
Input, InstrumentCoverage, OptLevel, OutFileName, OutputType, SwitchWithOptPath,
self, CoverageLevel, CoverageOptions, CrateType, DebugInfo, DebugInfoCompression,
ErrorOutputType, FunctionReturn, Input, InstrumentCoverage, OptLevel, OutFileName, OutputType,
SwitchWithOptPath,
};
use crate::filesearch::FileSearch;
use crate::lint::LintId;
Expand Down Expand Up @@ -713,6 +714,14 @@ impl Session {
.unwrap_or(self.target.default_dwarf_version)
}

pub fn debuginfo_compression(&self) -> DebugInfoCompression {
self.opts
.cg
.debuginfo_compression
.or(self.opts.unstable_opts.debuginfo_compression)
.unwrap_or(DebugInfoCompression::None)
}

pub fn stack_protector(&self) -> StackProtector {
if self.target.options.supports_stack_protector {
self.opts.unstable_opts.stack_protector
Expand Down
20 changes: 20 additions & 0 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ following values:

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

## debuginfo-compression

This flag controls how debug information is compressed. It takes one of the
following values:

* `none`: debug info is not compressed (the default).
* `zlib`: debug info is compressed using zlib.
* `zstd`: debug info is compressed using zstd.

Tools which read debug info such as debuggers and profilers must support the
compression algorithm or they will be unable to process the debug info. `zlib`
compression tends to be well supported by Linux tools but `zstd` may require
very recent versions of such tools.

Compressing debug info can improve binary size but will increase time and memory
used during compilation.

This flag is ignored by the compiler if the target does not support the specified
compression algorithm.

## default-linker-libraries

This flag controls whether or not the linker includes its default libraries.
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/compressed-debuginfo-zstd/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use run_make_support::{Rustc, llvm_readobj, run_in_tmpdir};
fn check_compression(compression: &str, to_find: &str) {
// check compressed debug sections via rustc flag
prepare_and_check(to_find, |rustc| {
rustc.arg(&format!("-Zdebuginfo-compression={compression}"))
rustc.arg(&format!("-Cdebuginfo-compression={compression}"))
});

// check compressed debug sections via rust-lld flag
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/compressed-debuginfo/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn check_compression(compression: &str, to_find: &str) {
.crate_type("lib")
.emit("obj")
.arg("-Cdebuginfo=full")
.arg(&format!("-Zdebuginfo-compression={compression}"))
.arg(&format!("-Cdebuginfo-compression={compression}"))
.input("foo.rs")
.run();
let stderr = out.stderr_utf8();
Expand Down
Loading