Skip to content

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Aug 28, 2025

Continuing from #144503 this centralizes most handling of the allocator shim to a single 4 line block in the codegen coordinator. The allocator shim is small enough that making it go through the main codegen loop and spawning a worker thread for it is wasted effort.

@rustbot
Copy link
Collaborator

rustbot commented Aug 28, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
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 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 Aug 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 28, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 28, 2025

Seems that mixing prefer-dynamic and no prefer-dynamic between crate types is currently broken for more reasons than the allocator shim, so the first commit doesn't have any benefits on it's own. It is a prerequisite for the second commit however, which IMHO is big enough of an improvement that I would like to see this PR merged.

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 28, 2025

I would prefer if #145962 gets merged first.

@bjorn3 bjorn3 added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Aug 28, 2025
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

bors added a commit that referenced this pull request Aug 31, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for #145955.
fmease added a commit to fmease/rust that referenced this pull request Sep 1, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 2, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
@nnethercote
Copy link
Contributor

I have low familiarity with this part of the code, but the changes seem reasonable, with tests and some comments, and I know that you know this stuff well. r=me when you are ready to merge.

@rustbot author

@rustbot rustbot 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. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Sep 2, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 2, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 2, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 3, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 3, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 3, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 3, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 3, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 4, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang#145955.
Making it participate in LTO would be incorrect if you compile a crate
as both a dylib (which needs it) and rlib (which must not include it) in
the same rustc invocation. With linker plugin LTO, the allocator shim
will still participate in LTO as it is safe to do so in that case.
…lsewhere

A lot of places had special handling just in case they would get an
allocator module even though most of these places could never get one or
would have a trivial implementation for the allocator module. Moving all
handling of the allocator module to a single place simplifies things a
fair bit.
@rustbot
Copy link
Collaborator

rustbot commented Sep 4, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@bjorn3
Copy link
Member Author

bjorn3 commented Sep 4, 2025

#145962 has landed. Rebased.

@bors r=nnethercote

@bors
Copy link
Collaborator

bors commented Sep 4, 2025

📌 Commit 319fe23 has been approved by nnethercote

It is now in the queue for this repository.

@bors bors 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 Sep 4, 2025
@bors
Copy link
Collaborator

bors commented Sep 4, 2025

⌛ Testing commit 319fe23 with merge 71289c3...

@bors
Copy link
Collaborator

bors commented Sep 4, 2025

☀️ Test successful - checks-actions
Approved by: nnethercote
Pushing 71289c3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 4, 2025
@bors bors merged commit 71289c3 into rust-lang:master Sep 4, 2025
11 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Sep 4, 2025
Copy link
Contributor

github-actions bot commented Sep 4, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 45b9d13 (parent) -> 71289c3 (this PR)

Test differences

Show 4 test diffs

4 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 71289c378d0a406a4f537fe4001282d19362931f --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-aarch64-apple: 5682.5s -> 8016.9s (41.1%)
  2. dist-aarch64-linux: 8483.7s -> 6344.6s (-25.2%)
  3. i686-gnu-2: 6353.0s -> 5535.6s (-12.9%)
  4. i686-gnu-1: 8610.2s -> 7532.8s (-12.5%)
  5. aarch64-gnu-debug: 4320.0s -> 3799.2s (-12.1%)
  6. pr-check-1: 1633.3s -> 1438.1s (-11.9%)
  7. x86_64-gnu-llvm-19: 2784.6s -> 2476.8s (-11.1%)
  8. i686-gnu-nopt-1: 8249.2s -> 7380.9s (-10.5%)
  9. aarch64-gnu-llvm-19-2: 2473.0s -> 2231.9s (-9.8%)
  10. x86_64-mingw-1: 9637.2s -> 10539.4s (9.4%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@bjorn3 bjorn3 deleted the lto_refactors4 branch September 4, 2025 15:17
@bjorn3 bjorn3 mentioned this pull request Sep 4, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (71289c3): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.9% [0.3%, 2.0%] 229
Regressions ❌
(secondary)
0.9% [0.0%, 2.2%] 259
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.0%] 4
All ❌✅ (primary) 0.9% [0.3%, 2.0%] 229

Max RSS (memory usage)

Results (primary 4.5%, secondary 3.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
4.5% [1.2%, 7.9%] 9
Regressions ❌
(secondary)
4.7% [2.1%, 7.9%] 24
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.9%, -2.2%] 3
All ❌✅ (primary) 4.5% [1.2%, 7.9%] 9

Cycles

Results (primary 1.7%, secondary 2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [1.9%, 3.1%] 8
Regressions ❌
(secondary)
3.6% [2.0%, 13.0%] 11
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
-2.2% [-2.6%, -1.8%] 2
All ❌✅ (primary) 1.7% [-2.9%, 3.1%] 9

Binary size

Results (primary 0.9%, secondary 1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.9% [0.8%, 0.9%] 4
Regressions ❌
(secondary)
1.1% [0.4%, 1.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.9% [0.8%, 0.9%] 4

Bootstrap: 466.452s -> 467.362s (0.20%)
Artifact size: 387.89 MiB -> 390.47 MiB (0.66%)

@rustbot rustbot added the perf-regression Performance regression. label Sep 4, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Sep 4, 2025

Could this be because the allocator shim no longer participates in LTO? I plan to make it participate again a couple PRs later in this series when I moved LTO to a later in the compilation. Having the allocator shim participate in LTO earlier makes the rest of the series harder to implement. It previously was in a weird limbo state between being ignored until linking and being treated like a regular module during LTO. At the same time, I don't expect to finish making it participate in LTO again for at least a month. And the rest of the PRs will likely make it even harder to revert this PR.

@nnethercote
Copy link
Contributor

It is possible to do some kind of quick and dirty change that makes it participate in LTO, not for merging, just to test whether that fixes the regression? If we had confidence that the regression is fixable then waiting a month would be much more bearable.

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 5, 2025
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for rust-lang/rust#145955.
@bjorn3
Copy link
Member Author

bjorn3 commented Sep 5, 2025

Opened MCP908 to describe the full plan I have.

bors added a commit that referenced this pull request Sep 6, 2025
Make the allocator shim participate in LTO again

This is likely the cause of the perf regression in #145955. It also caused some functional regressions.

Fixes #146235
Fixes #146239
bors added a commit that referenced this pull request Sep 6, 2025
Make the allocator shim participate in LTO again

This is likely the cause of the perf regression in #145955. It also caused some functional regressions.

Fixes #146235
Fixes #146239
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 7, 2025
Misc LTO cleanups

Follow up to rust-lang#145955.

* Remove want_summary argument from `prepare_thin`.
   Since rust-lang#133250 ThinLTO summary writing is instead done by `llvm_optimize`.
* Two minor cleanups
rust-timer added a commit that referenced this pull request Sep 7, 2025
Rollup merge of #146209 - bjorn3:lto_refactors5, r=dianqk

Misc LTO cleanups

Follow up to #145955.

* Remove want_summary argument from `prepare_thin`.
   Since #133250 ThinLTO summary writing is instead done by `llvm_optimize`.
* Two minor cleanups
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. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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