Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: add split-debuginfo config #95612

Merged
merged 4 commits into from
Apr 21, 2022
Merged
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_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(

// On MSVC packed debug information is produced by the linker itself so
// there's no need to do anything else here.
SplitDebuginfo::Packed if sess.target.is_like_msvc => {}
SplitDebuginfo::Packed if sess.target.is_like_windows => {}

// ... and otherwise we're processing a `*.dwp` packed dwarf file.
//
Expand Down
24 changes: 17 additions & 7 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,23 @@ changelog-seen = 2
# FIXME(#61117): Some tests fail when this option is enabled.
#debuginfo-level-tests = 0

# Whether to run `dsymutil` on Apple platforms to gather debug info into .dSYM
# bundles. `dsymutil` adds time to builds for no clear benefit, and also makes
# it more difficult for debuggers to find debug info. The compiler currently
# defaults to running `dsymutil` to preserve its historical default, but when
# compiling the compiler itself, we skip it by default since we know it's safe
# to do so in that case.
#run-dsymutil = false
# Should rustc be build with split debuginfo? Default is platform dependent.
# Valid values are the same as those accepted by `-C split-debuginfo`
# (`off`/`unpacked`/`packed`).
#
# On Linux, split debuginfo is disabled by default.
#
# On Apple platforms, unpacked split debuginfo is used by default. Unpacked
# debuginfo does not run `dsymutil`, which packages debuginfo from disparate
# object files into a single `.dSYM` file. `dsymutil` adds time to builds for
# no clear benefit, and also makes it more difficult for debuggers to find
# debug info. The compiler currently defaults to running `dsymutil` to preserve
# its historical default, but when compiling the compiler itself, we skip it by
# default since we know it's safe to do so in that case.
#
# On Windows platforms, packed debuginfo is the only supported option,
# producing a `.pdb` file.
#split-debuginfo = if linux { off } else if windows { packed } else if apple { unpacked }

# Whether or not `panic!`s generate backtraces (RUST_BACKTRACE)
#backtrace = true
Expand Down
22 changes: 11 additions & 11 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::time::{Duration, Instant};
use crate::cache::{Cache, Interned, INTERNER};
use crate::check;
use crate::compile;
use crate::config::TargetSelection;
use crate::config::{SplitDebuginfo, TargetSelection};
use crate::dist;
use crate::doc;
use crate::flags::{Color, Subcommand};
Expand Down Expand Up @@ -1365,17 +1365,17 @@ impl<'a> Builder<'a> {
},
);

// `dsymutil` adds time to builds on Apple platforms for no clear benefit, and also makes
// it more difficult for debuggers to find debug info. The compiler currently defaults to
// running `dsymutil` to preserve its historical default, but when compiling the compiler
// itself, we skip it by default since we know it's safe to do so in that case.
// See https://github.com/rust-lang/rust/issues/79361 for more info on this flag.
if target.contains("apple") {
if self.config.rust_run_dsymutil {
rustflags.arg("-Csplit-debuginfo=packed");
} else {
rustflags.arg("-Csplit-debuginfo=unpacked");
// FIXME(davidtwco): #[cfg(not(bootstrap))] - #95612 needs to be in the bootstrap compiler
// for this conditional to be removed.
if !target.contains("windows") || compiler.stage >= 1 {
if target.contains("linux") || target.contains("windows") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition "linux" or "windows" is way too restrictive: all others unix needs -Zunstable-options too.

Currently, i am unable to build nightly on OpenBSD due to that:

running: "/data/semarie/build-rust/install_dir/beta/bin/cargo" "build" "--target" "x86_64-unknown-openbsd" "-Zbinary-dep-depinfo" "-j" "4" "-v" "--release" "--frozen" "--manifest-path"
"/data/semarie/build-rust/build_dir/rustc-nightly-src/src/tools/unstable-book-gen/Cargo.toml" "--message-format" "json-render-diagnostics"
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/data/semarie/build-rust/build_dir/build/bootstrap/debug/rustc - --crate-name ___ --print=file-names --cfg=bootstrap -Csymbol-mangling-version=v0 -Zmacro-backtrace -Clink-args=-Wl,-z,origin
'-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Csplit-debuginfo=off -Ztls-model=initial-exec --target x86_64-unknown-openbsd --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro
--print=sysroot --print=cfg` (exit status: 1)
  --- stdout

  Did not run successfully: exit status: 1
  "/data/semarie/build-rust/install_dir/beta/bin/rustc" "-" "--crate-name" "___" "--print=file-names" "--cfg=bootstrap" "-Csymbol-mangling-version=v0" "-Zmacro-backtrace" "-Clink-args=-Wl,-z,origin" "-Clink-args=-Wl,-rpath,$ORIGIN/../lib"
"-Csplit-debuginfo=off" "-Ztls-model=initial-exec" "--target" "x86_64-unknown-openbsd" "--crate-type" "bin" "--crate-type" "rlib" "--crate-type" "dylib" "--crate-type" "cdylib" "--crate-type" "staticlib" "--crate-type" "proc-macro"
"--print=sysroot" "--print=cfg" "-Wrust_2018_idioms" "-Wunused_lifetimes" "-Wsemicolon_in_expressions_from_macros" "-Dwarnings" "--sysroot" "/data/semarie/build-rust/install_dir/beta"
  -------------

  --- stderr
  error: `-Csplit-debuginfo` is unstable on this platform

Adding || target.contains("openbsd") makes the build to continue.

I wonder if ! target.contains("apple") would be the right conditionnal.

rustflags.arg("-Zunstable-options");
}
match self.config.rust_split_debuginfo {
SplitDebuginfo::Packed => rustflags.arg("-Csplit-debuginfo=packed"),
SplitDebuginfo::Unpacked => rustflags.arg("-Csplit-debuginfo=unpacked"),
SplitDebuginfo::Off => rustflags.arg("-Csplit-debuginfo=off"),
};
}

if self.config.cmd.bless() {
Expand Down
50 changes: 48 additions & 2 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub struct Config {
pub rust_debuginfo_level_std: u32,
pub rust_debuginfo_level_tools: u32,
pub rust_debuginfo_level_tests: u32,
pub rust_run_dsymutil: bool,
pub rust_split_debuginfo: SplitDebuginfo,
pub rust_rpath: bool,
pub rustc_parallel: bool,
pub rustc_default_linker: Option<String>,
Expand Down Expand Up @@ -221,6 +221,46 @@ impl FromStr for LlvmLibunwind {
}
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SplitDebuginfo {
Packed,
Unpacked,
Off,
}

impl Default for SplitDebuginfo {
fn default() -> Self {
SplitDebuginfo::Off
}
}

impl std::str::FromStr for SplitDebuginfo {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"packed" => Ok(SplitDebuginfo::Packed),
"unpacked" => Ok(SplitDebuginfo::Unpacked),
"off" => Ok(SplitDebuginfo::Off),
_ => Err(()),
}
}
}

impl SplitDebuginfo {
/// Returns the default `-Csplit-debuginfo` value for the current target. See the comment for
/// `rust.split-debuginfo` in `config.toml.example`.
fn default_for_platform(target: &str) -> Self {
if target.contains("apple") {
SplitDebuginfo::Unpacked
} else if target.contains("windows") {
SplitDebuginfo::Packed
} else {
SplitDebuginfo::Off
}
}
}

#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TargetSelection {
pub triple: Interned<String>,
Expand Down Expand Up @@ -586,6 +626,7 @@ define_config! {
debuginfo_level_std: Option<u32> = "debuginfo-level-std",
debuginfo_level_tools: Option<u32> = "debuginfo-level-tools",
debuginfo_level_tests: Option<u32> = "debuginfo-level-tests",
split_debuginfo: Option<String> = "split-debuginfo",
run_dsymutil: Option<bool> = "run-dsymutil",
backtrace: Option<bool> = "backtrace",
incremental: Option<bool> = "incremental",
Expand Down Expand Up @@ -992,7 +1033,12 @@ impl Config {
debuginfo_level_std = rust.debuginfo_level_std;
debuginfo_level_tools = rust.debuginfo_level_tools;
debuginfo_level_tests = rust.debuginfo_level_tests;
config.rust_run_dsymutil = rust.run_dsymutil.unwrap_or(false);
config.rust_split_debuginfo = rust
.split_debuginfo
.as_deref()
.map(SplitDebuginfo::from_str)
.map(|v| v.expect("invalid value for rust.split_debuginfo"))
.unwrap_or(SplitDebuginfo::default_for_platform(&config.build.triple));
optimize = rust.optimize;
ignore_git = rust.ignore_git;
config.rust_new_symbol_mangling = rust.new_symbol_mangling;
Expand Down