Skip to content

Commit bf5a5d5

Browse files
committed
Auto merge of #9182 - alexcrichton:fix-lto-off, r=ehuss
Propagate `lto=off` harder This commit fixes an issue with LTO calculation for various units when `lto=off` is specified in the profile. This ensures now that `lto=off` is passed to all transitive dependencies as well to disable thin-local LTO. As an added bonus this also passed `embed-bitcode=no` whenever `lto=off` is specified since we know we won't be using bitcode anyway. Closes #9171
2 parents adb3580 + 1e05dbb commit bf5a5d5

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/cargo/core/compiler/lto.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub fn generate(bcx: &BuildContext<'_, '_>) -> CargoResult<HashMap<Unit, Lto>> {
4545
for unit in bcx.roots.iter() {
4646
let root_lto = match unit.profile.lto {
4747
// LTO not requested, no need for bitcode.
48-
profiles::Lto::Bool(false) | profiles::Lto::Off => Lto::OnlyObject,
48+
profiles::Lto::Bool(false) => Lto::OnlyObject,
49+
profiles::Lto::Off => Lto::Off,
4950
_ => {
5051
let crate_types = unit.target.rustc_crate_types();
5152
if unit.target.for_host() {
@@ -127,8 +128,8 @@ fn calculate(
127128
(Lto::Run(_), false) => Lto::OnlyBitcode,
128129
// LTO when something needs object code.
129130
(Lto::Run(_), true) | (Lto::OnlyBitcode, true) => lto_when_needs_object(&crate_types),
130-
// LTO is disabled, no need for bitcode.
131-
(Lto::Off, _) => Lto::OnlyObject,
131+
// LTO is disabled, continue to disable it.
132+
(Lto::Off, _) => Lto::Off,
132133
// If this doesn't have any requirements, or the requirements are
133134
// already satisfied, then stay with our parent.
134135
(_, false) | (Lto::OnlyObject, true) | (Lto::ObjectAndBitcode, true) => parent_lto,

src/cargo/core/compiler/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,10 @@ fn lto_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
968968
match cx.lto[unit] {
969969
lto::Lto::Run(None) => push("lto"),
970970
lto::Lto::Run(Some(s)) => push(&format!("lto={}", s)),
971-
lto::Lto::Off => push("lto=off"),
971+
lto::Lto::Off => {
972+
push("lto=off");
973+
push("embed-bitcode=no");
974+
}
972975
lto::Lto::ObjectAndBitcode => {} // this is rustc's default
973976
lto::Lto::OnlyBitcode => push("linker-plugin-lto"),
974977
lto::Lto::OnlyObject => push("embed-bitcode=no"),

tests/testsuite/lto.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ fn off_in_manifest_works() {
254254
[DOWNLOADING] [..]
255255
[DOWNLOADED] [..]
256256
[COMPILING] bar v0.0.1
257-
[RUNNING] `rustc --crate-name bar [..]--crate-type lib [..]-C embed-bitcode=no[..]
257+
[RUNNING] `rustc --crate-name bar [..]--crate-type lib [..]-C lto=off -C embed-bitcode=no[..]
258258
[COMPILING] test [..]
259-
[RUNNING] `rustc --crate-name test [..]--crate-type lib [..]-C embed-bitcode=no[..]
259+
[RUNNING] `rustc --crate-name test [..]--crate-type lib [..]-C lto=off -C embed-bitcode=no[..]
260260
[RUNNING] `rustc --crate-name test src/main.rs [..]--crate-type bin [..]-C lto=off[..]
261261
[FINISHED] [..]
262262
",

0 commit comments

Comments
 (0)