Skip to content

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Sep 29, 2025

This PR generalizes the previous hardcoded logic for setting self-contained LLD to be used as the default Linker on Linux GNU targets. The changes made:

  1. rust.lld now only controls whether LLD is built and included in the sysroot. If rust.lld is set to false, it will disable the default opt into LLD on x64 Linux.
  2. The linker override for using rust-lld through cc can now be applied to all Linux targets. It is configured through target.<target>.default-linker-linux-override = "self-contained-lld-cc"/"off"

Here is how it behaves:

  1. If you don't set any options, x64 Linux will default into default-linker-linux-override = "self-contained-lld-cc" and also rust.lld = true.
  2. If you set rust.lld = false, you disable this override
  3. If you set target.x86_64-unknown-linux-gnu.default-linux-linker-override = "off", you disable this override
  4. If you set target.x86_64-unknown-linux-gnu.llvm-config = ..., you disable this override

Note that in contrast to what I described in #146640, I didn't bother moving rust.lld to llvm.lld. We can do that separately later, but I don't think it's worth the churn. I realized that rust is perhaps a better place for this, because it not only controls whether LLD is built, but also if it is included in the compiler sysroot. So to truly distinguish these two, we'd need both llvm.lld and rust.lld, which doesn't seem worth it. Note that rust.codegen-backends = ["llvm"] works in the same way, it tells bootstrap to build LLVM and include it in the sysroot. So it is consistent with rust.lld

Related to: #146640

r? @jieyouxu

@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2025

This PR modifies bootstrap.example.toml.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

These commits modify compiler targets.
(See the Target Tier Policy.)

@rustbot rustbot added A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Sep 29, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was supposed to be linux_gnu.rs, not linux_musl.rs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, the files are too similar 😆 I actually wanted to put this into linux.rs directly, as the override should also work for MUSL targets. Unless you think we should only allow it for linux-gnu.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, but if we put it into linux.rs, then musl would override link_self_contained: LinkSelfContainedDefault::InferredForMusl, that's not ideal. Ideally we should use the override at the very end of the config, not at the beginning, I guess.

@lqd
Copy link
Member

lqd commented Sep 30, 2025

3. Bootstrap no longer automatically enables LLD for x86_64-unknown-linux-gnu if there is no external LLVM config being used

Do you mean this is disabling the lld default for x64 linux and contributors have to change their local configs to keep it?

@Kobzol
Copy link
Member Author

Kobzol commented Sep 30, 2025

Currently yes. I realize now that this is probably not a good idea, as we want to have as much coverage of LLD as possible.

Then what I would do it configure this to be enabled by default in bootstrap for this specific target (either in code or bootstrap.toml default profiles), and then allow distros to opt-out.

But enabling it by default would require us to also set rust.lld to true, or only override rust-lld when rust.lld is enabled, which is essentially what happened before and what I wanted to get rid off =D

Ok then I would propose:

  • Enable the override by default
  • If rust.lld is unset, enable rust.lld when the override is enabled

Thus essentially the other way around than it was before.

@rustbot
Copy link
Collaborator

rustbot commented Oct 6, 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.

@Kobzol
Copy link
Member Author

Kobzol commented Oct 6, 2025

Updated the PR to apply the override by default, with the possibility to opt out. Updated the PR descripton.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Two nits, otherwise makes sense to me.

View changes since this review

@jieyouxu
Copy link
Member

jieyouxu commented Oct 9, 2025

@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. labels Oct 9, 2025
@Kobzol
Copy link
Member Author

Kobzol commented Oct 9, 2025

@rustbot ready

@Kobzol
Copy link
Member Author

Kobzol commented Oct 9, 2025

Actually, let's check that perf. hasn't regressed and LLD is still used.

@bors try @rust-timer queue

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

This comment has been minimized.

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2025
rust-bors bot added a commit that referenced this pull request Oct 9, 2025
Generalize configuring LLD as the default linker in bootstrap
@rust-bors
Copy link

rust-bors bot commented Oct 9, 2025

☀️ Try build successful (CI)
Build commit: 1f46a6b (1f46a6bacbe24d970b7eb5155f9300f15c9f6177, parent: 4b57d8154a6a74d2514cd3a674c1f29a588f224a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1f46a6b): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

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
Regressions ❌
(secondary)
0.6% [0.5%, 0.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.7%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -0.8%)

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

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.3% [-4.3%, -4.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.8% [-4.3%, 2.7%] 2

Cycles

Results (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)
- - 0
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-4.4%, -2.2%] 7
All ❌✅ (primary) - - 0

Binary size

Results (secondary 0.0%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 473.051s -> 471.227s (-0.39%)
Artifact size: 388.38 MiB -> 388.40 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2025
@Kobzol
Copy link
Member Author

Kobzol commented Oct 9, 2025

Looks fine.

@jieyouxu
Copy link
Member

Cool.
@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Oct 10, 2025

📌 Commit da86710 has been approved by jieyouxu

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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants