Skip to content

Add rust.lto=off to bootstrap and set as compiler/library default #107241

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

Merged
merged 1 commit into from
Feb 3, 2023
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
3 changes: 2 additions & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ changelog-seen = 2

# Select LTO mode that will be used for compiling rustc. By default, thin local LTO
# (LTO within a single crate) is used (like for any Rust crate). You can also select
# "thin" or "fat" to apply Thin/Fat LTO to the `rustc_driver` dylib.
# "thin" or "fat" to apply Thin/Fat LTO to the `rustc_driver` dylib, or "off" to disable
# LTO entirely.
#lto = "thin-local"

# =============================================================================
Expand Down
10 changes: 10 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
if stage >= 1 {
cargo.rustflag("-Cembed-bitcode=yes");
}
if builder.config.rust_lto == RustcLto::Off {
cargo.rustflag("-Clto=off");
}

// By default, rustc does not include unwind tables unless they are required
// for a particular target. They are not required by RISC-V targets, but
Expand Down Expand Up @@ -722,6 +725,13 @@ impl Step for Rustc {
cargo.rustflag("-Cembed-bitcode=yes");
}
RustcLto::ThinLocal => { /* Do nothing, this is the default */ }
RustcLto::Off => {
Copy link
Contributor

@ehuss ehuss Jan 24, 2023

Choose a reason for hiding this comment

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

Just FYI, this doesn't disable LTO for the compiler built in stage0. I think this would need to go outside the check for the compiler stage.

To elaborate: The reason -Clto doesn't run in stage 0 is per the comment above about LTO not working in stage 0, but the "off" setting is specifically turning it off, so it doesn't have the same restriction.

cargo.rustflag("-Clto=off");
}
}
} else {
if builder.config.rust_lto == RustcLto::Off {
cargo.rustflag("-Clto=off");
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ impl SplitDebuginfo {
}

/// LTO mode used for compiling rustc itself.
#[derive(Default, Clone)]
#[derive(Default, Clone, PartialEq)]
pub enum RustcLto {
Off,
#[default]
ThinLocal,
Thin,
Expand All @@ -348,6 +349,7 @@ impl std::str::FromStr for RustcLto {
"thin-local" => Ok(RustcLto::ThinLocal),
"thin" => Ok(RustcLto::Thin),
"fat" => Ok(RustcLto::Fat),
"off" => Ok(RustcLto::Off),
_ => Err(format!("Invalid value for rustc LTO: {}", s)),
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/defaults/config.compiler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ debug-logging = true
incremental = true
# Print backtrace on internal compiler errors during bootstrap
backtrace-on-ice = true
# Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown.
lto = "off"

[llvm]
# Will download LLVM from CI if available on your platform.
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/defaults/config.library.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ bench-stage = 0
[rust]
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
incremental = true
# Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown.
lto = "off"

[llvm]
# Will download LLVM from CI if available on your platform.
Expand Down