Skip to content

Remove -Zthinlto #144744

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

Closed
wants to merge 1 commit into from
Closed

Remove -Zthinlto #144744

wants to merge 1 commit into from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jul 31, 2025

This flag enables local ThinLTO, not full ThinLTO. It seems to be a remnant of when ThinLTO was originally introduced before -Clto=thin was supported. Local ThinLTO is already the default in release mode when -Clto is not passed and there is more than 1 codegen units. In debug mode or with 1 codegen unit local ThinLTO doesn't have any benefit, so there is no reason to support enabling it in that case anyway.

This flag enables local ThinLTO, not full ThinLTO. It seems to be a
remnant of when ThinLTO was originally introduced before -Clto=thin was
supported. Local ThinLTO is already the default in release mode when
-Clto is not passed and there is more than 1 codegen units. In debug
mode or with 1 codegen unit local ThinLTO doesn't have any benefit, so
there is no reason to support enabling it in that case anyway.
@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2025

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 31, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Jul 31, 2025

This has a minor conflict with #144738 in a test.

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-19-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] tests/ui/lto/dylib-works.rs stdout ----

error: auxiliary build of /checkout/tests/ui/lto/auxiliary/dylib.rs failed to compile: 
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lto/auxiliary/dylib.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lto/dylib-works/auxiliary" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Clto=thin" "-C" "codegen-units=8" "--crate-type" "dylib" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lto/dylib-works/auxiliary"
stdout: none
--- stderr -------------------------------
error: lto cannot be used for `dylib` crate type without `-Zdylib-lto`

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/lto/msvc-imp-present.rs stdout ----

error: auxiliary build of /checkout/tests/ui/lto/auxiliary/msvc-imp-present.rs failed to compile: 
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lto/auxiliary/msvc-imp-present.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lto/msvc-imp-present/auxiliary" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Clto=thin" "-C" "codegen-units=8" "-C" "prefer-dynamic" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lto/msvc-imp-present/auxiliary"
stdout: none
--- stderr -------------------------------
error: lto cannot be used for `dylib` crate type without `-Zdylib-lto`

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/lto/thin-lto-global-allocator.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lto/thin-lto-global-allocator.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lto/thin-lto-global-allocator/a" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Clto=thin" "-C" "codegen-units=2"
stdout: none
--- stderr -------------------------------
error: cannot prefer dynamic linking when performing LTO
   |
   = note: only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/lto/thin-lto-inlines.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lto/thin-lto-inlines.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lto/thin-lto-inlines/a" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Clto=thin" "-C" "codegen-units=8" "-O"
stdout: none
--- stderr -------------------------------
error: cannot prefer dynamic linking when performing LTO
   |
   = note: only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/lto/weak-works.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lto/weak-works.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lto/weak-works/a" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-C" "codegen-units=8" "-Clto=thin"
stdout: none
--- stderr -------------------------------
error: cannot prefer dynamic linking when performing LTO
   |
   = note: only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO

error: aborting due to 1 previous error
------------------------------------------


@@ -1,4 +1,4 @@
//@ compile-flags: -Z thinlto -C codegen-units=8
//@ compile-flags: -Clto=thin -C codegen-units=8
Copy link
Contributor

Choose a reason for hiding this comment

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

To preserve behavior, shouldn't these drop the flag entirely? Otherwise they will switch from thin-local to thin?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did then also have to pass -Copt-level=1 or higher. Otherwise LTO is disabled entirely.

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 1, 2025

I think changing some tests from local ThinLTO to ThinLTO is a bit risky after all.

@bjorn3 bjorn3 closed this Aug 1, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 1, 2025
@bjorn3 bjorn3 deleted the no_z_thinlto branch August 1, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants