Skip to content

Fix incremental compilation for fat LTO - #163317

Open
bjorn3 wants to merge 7 commits into
rust-lang:mainfrom
bjorn3:lto_refactors22
Open

bjorn3 wants to merge 7 commits into
rust-lang:mainfrom
bjorn3:lto_refactors22

Conversation

@bjorn3

@bjorn3 bjorn3 commented Sep 25, 2026

Copy link
Copy Markdown
Member

Previously we would copy post-LTO artifacts into the incr comp cache for fat LTO despite them never getting used. Also the pre-LTO bitcode didn't get tracked and thus determine_cgu_reuse believed it had to regenerate bitcode for all CGUs even when all CGUs would be green.

Also move incr comp session dirs out of CodegenContext. CodegenContext will in the future be serialized and deserialized into a different rustc instance when -Zno-link/-Zlink-only is used. A separate incr comp session has to be used for both rustc invocations.

Part of rust-lang/compiler-team#908

@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 Sep 25, 2026
@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 77 candidates
  • Random selection from 21 candidates

@rust-log-analyzer

This comment has been minimized.

CodegenContext will in the future be serialized and deserialized into a
different rustc instance when -Zno-link/-Zlink-only is used. A separate
incr comp session has to be used for both rustc invocations.
Previously we would copy post LTO artifacts into the incr comp cache for
fat LTO despite them never getting used. Also the pre LTO bitcode didn't
get tracked and thus determine_cgu_reuse believed it had to regenerate
bitcode for all CGUs even when all CGUs would be green.
if !self.check_config(cfg) {
debug!("check_attr: config does not match, ignoring attr");
return;
continue;

@bjorn3 bjorn3 Sep 25, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This caused us to skip all assertions after the first one with a cfg that doesn't match. Surprisingly nothing regressed by the lack of test coverage since the introduction of this bug.

View changes since the review

@bjorn3 bjorn3 changed the title Fix incr comp for fat LTO Fix incremental compilation for fat LTO Sep 27, 2026

@mejrs mejrs left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure about this otherwise.

r? @nnethercote perhaps?

View changes since this review

Comment thread compiler/rustc_codegen_llvm/src/back/llvm_backend.rs
@rustbot rustbot assigned nnethercote and unassigned mejrs Sep 30, 2026
Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>

@nnethercote nnethercote left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r=me with the nits addressed.

View changes since this review

Comment thread compiler/rustc_session/src/session.rs Outdated
};

// FIXME include pre-LTO bitcode in workproduct tracking
// FIXME add separate incr comp session for post-LTO outputs to use during link step

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How important are these FIXMEs? Are you planning to fix them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm working on a follow up PR to do this.

@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 2, 2026
@bjorn3

bjorn3 commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

@bors r=nnethercote

@rust-bors

rust-bors Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ebdd423 has been tentatively approved by nnethercote

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 2, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 2, 2026
Fix incremental compilation for fat LTO

Previously we would copy post-LTO artifacts into the incr comp cache for fat LTO despite them never getting used. Also the pre-LTO bitcode didn't get tracked and thus `determine_cgu_reuse` believed it had to regenerate bitcode for all CGUs even when all CGUs would be green.

Also move incr comp session dirs out of `CodegenContext`. `CodegenContext` will in the future be serialized and deserialized into a different rustc instance when `-Zno-link`/`-Zlink-only` is used. A separate incr comp session has to be used for both rustc invocations.

Part of rust-lang/compiler-team#908
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 2, 2026
Fix incremental compilation for fat LTO

Previously we would copy post-LTO artifacts into the incr comp cache for fat LTO despite them never getting used. Also the pre-LTO bitcode didn't get tracked and thus `determine_cgu_reuse` believed it had to regenerate bitcode for all CGUs even when all CGUs would be green.

Also move incr comp session dirs out of `CodegenContext`. `CodegenContext` will in the future be serialized and deserialized into a different rustc instance when `-Zno-link`/`-Zlink-only` is used. A separate incr comp session has to be used for both rustc invocations.

Part of rust-lang/compiler-team#908
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #163317 (Fix incremental compilation for fat LTO)
 - #163582 (Reapply "bootstrap: Enable rustdoc mergeable CCI for std and internal docs")
 - #151793 (Add mul_add_relaxed methods for floating-point types)
 - #162782 (Fix rustdoc ICE caused by mishandling of ambiguity errors)
 - #163010 (Miri can do dirfd now)
 - #163535 (Improve `DocStrings` perf)
 - #163576 (Fix `TypeOutlives` fast-path)
 - #163587 (Several small span improvements)
 - #163612 (fix `ValidateBoundVars`)
 - #163632 (bump rustc-build-sysroot)
 - #163635 (Revert note about signum of NaN)
 - #163644 (Add mailmap entry)
 - #163651 (Remove variants from `feature-gate-autodiff-use` test)
@JonathanBrouwer

Copy link
Copy Markdown
Member

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #163650 (comment)

@bors try jobs=test-x86_64-mingw-1

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 2, 2026
@rust-bors

rust-bors Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#163656), which was unapproved.

View changes since this unapproval

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
Fix incremental compilation for fat LTO


try-job: test-x86_64-mingw-1
@rust-bors

rust-bors Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

💔 Test for e4021fc failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-x86_64-mingw-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [run-make] tests\run-make\lto-empty stdout ----

error: rmake recipe failed to complete
status: exit code: 1
command: "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\run-make\\lto-empty\\rmake.exe"
stdout: none
--- stderr -------------------------------
"D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\stage2\\bin\\rustc.exe" "-L" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\run-make\\lto-empty\\rmake_out" "lib.rs" "-Clto=fat" "-Copt-level=3" "-Cincremental=inc-fat" "--target=x86_64-pc-windows-gnu"
output status: `exit code: 0`
=== STDOUT ===



=== STDERR ===



command failed at line 16
"D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\stage2\\bin\\rustc.exe" "-L" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\run-make\\lto-empty\\rmake_out" "lib.rs" "-Clto=fat" "-Copt-level=3" "-Cincremental=inc-fat" "--target=x86_64-pc-windows-gnu"
output status: `exit code: 1`
=== STDOUT ===



=== STDERR ===
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "x86_64-w64-mingw32-gcc" "-Wl,D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\run-make\\lto-empty\\rmake_out\\rustcnFGqkA\\list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "<21 object files omitted>" "-Wl,-Bstatic" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\run-make\\lto-empty\\rmake_out\\rustcnFGqkA/libstd-f19ec5cf82cf2e36.rlib" "<sysroot>\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib/libcompiler_builtins-*.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-ldbghelp" "-lsynchronization" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\run-make\\lto-empty\\rmake_out" "-o" "lib.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=liblib.dll.a" "-Wl,-O1" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.object-748e56779e68aa6c.object.633ec871561b15de-cgu.0.rcgu.o.05j0x8c.rcgu.o:object.633ec871561b15de-cgu.0:(.text+0x45b): undefined reference to `__imp__RNvNvNtNtNtCsjJQlRGTNn6I_6memchr4arch6x86_646memchr10memchr_raw2FN'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.object-748e56779e68aa6c.object.633ec871561b15de-cgu.0.rcgu.o.05j0x8c.rcgu.o:object.633ec871561b15de-cgu.0:(.text+0x536): undefined reference to `__imp__RNvNvNtNtNtCsjJQlRGTNn6I_6memchr4arch6x86_646memchr10memchr_raw2FN'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x21519): undefined reference to `__imp__RNvNvNtNtNtCsjJQlRGTNn6I_6memchr4arch6x86_646memchr10memchr_raw2FN'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x215c0): undefined reference to `__imp__RNvNvNtNtNtCsjJQlRGTNn6I_6memchr4arch6x86_646memchr10memchr_raw2FN'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x21739): undefined reference to `__imp__RNvNvNtNtNtCsjJQlRGTNn6I_6memchr4arch6x86_646memchr10memchr_raw2FN'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x217ae): more undefined references to `__imp__RNvNvNtNtNtCsjJQlRGTNn6I_6memchr4arch6x86_646memchr10memchr_raw2FN' follow
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x267f6): undefined reference to `__imp__RNvNtNtNtCslNM2aqSgGGX_4core2io5error12os_functions12OS_FUNCTIONS'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x27af7): undefined reference to `__imp__RNvNtNtNtCslNM2aqSgGGX_4core2io5error12os_functions12OS_FUNCTIONS'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x27eef): undefined reference to `__imp__RNvNtNtNtCslNM2aqSgGGX_4core2io5error12os_functions12OS_FUNCTIONS'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x27ff8): undefined reference to `__imp__RNvNtNtNtCslNM2aqSgGGX_4core2io5error12os_functions12OS_FUNCTIONS'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x2ae06): undefined reference to `__imp__RNvNtNtNtCslNM2aqSgGGX_4core2io5error12os_functions12OS_FUNCTIONS'
          D:/a/rust/rust/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib.std-f19ec5cf82cf2e36.std.978b82965100b081-cgu.0.rcgu.o.05j0x8c.rcgu.o:std.978b82965100b081-cgu.0:(.text+0x2b89b): more undefined references to `__imp__RNvNtNtNtCslNM2aqSgGGX_4core2io5error12os_functions12OS_FUNCTIONS' follow
          collect2.exe: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link

error: aborting due to 1 previous error
---
Currently active steps:
test::RunMake { test_compiler: Compiler { stage: 2, host: x86_64-pc-windows-gnu, forced_compiler: false }, target: x86_64-pc-windows-gnu } at src\bootstrap\src\core\build_steps\test.rs:2024
test::Compiletest { test_compiler: Compiler { stage: 2, host: x86_64-pc-windows-gnu, forced_compiler: false }, target: x86_64-pc-windows-gnu, mode: run-make, suite: "run-make", path: "tests/run-make", compare_mode: None } at src\bootstrap\src\core\build_steps\test.rs:2024
Build completed unsuccessfully in 2:29:04
make: *** [Makefile:126: ci-mingw-x] Error 1
  local time: Fri Oct  2 16:46:25 CUT 2026
  network time: Fri, 02 Oct 2026 16:46:25 GMT
##[error]Process completed with exit code 2.
##[group]Run echo "disk usage:"
echo "disk usage:"

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

6 participants