Skip to content
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

Enable rust-lld on nightly x86_64-unknown-linux-gnu #124129

Merged
merged 6 commits into from
May 17, 2024
Merged

Conversation

lqd
Copy link
Member

@lqd lqd commented Apr 18, 2024

We believe we have done virtually all the internal work and tests we could to prepare for using lld as the default linker (at least on Linux). We're IMHO at a point where we'd need to expand testing and coverage in order to make progress on this effort.

Therefore, for further testing and gathering real-world feedback, unexpected issues and use-cases, this PR enables rust-lld as the default linker:

  • on nightly only (and dev channel)
  • on x86_64-unknown-linux-gnu only
  • when not using an external LLVM (except download-ci-llvm), so that distros are not impacted

as described in more detail in this zulip thread.

In case any issues happen to users, as e.g. lld is not bug-for-bug compatible with GNU ld, it's easy to disable with -Zlinker-features=-lld to revert to using the system's default linker.


I don't know who should review this kind of things, as it's somewhat of a crosscutting effort. Compiler contributor, compiler performance WG and infra member sounds perfect, so r? @Mark-Simulacrum.

The last crater run encountered a low number (44) of mainly avoidable issues, like small incompatibilities, user errors, and a difference between the two linkers about which default to use with --gc-sections. Here's the triage report, categorizing the issues, with some analyses and workarounds. I'd appreciate another set of eyes looking at these results.

The changes in this PR have been test-driven for CI changes, try builds with tests enabled, rustc-perf with bootstrapping, in PR #113382.

For infra, about the CI change: this PR forces rust.lld to false on vanilla LLVM builders, just to make sure we have coverage without rust-lld. Though to be clear, just using an external LLVM is already enough to keep rust.lld to false, in turn reverting everything to using the system's default linker.

cc @rust-lang/bootstrap for the bootstrap and config change
cc @petrochenkov for the small compiler change
cc @rust-lang/wg-compiler-performance

The blog post announcing the change, that we expect to merge around the same time as we merge this PR, is open on the blog repo.

Bootstrap change history: this PR changes the default of a config option on x86_64-unknown-linux-gnu. It's, however, not expected to cause issues, or require any changes to existing configurations. It's a big enough change that people should at least know about it, in case it causes unexpected problems. If that happens, set rust.lld = false in your config.toml (and open an issue).

@rustbot rustbot added 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 Apr 18, 2024
@lqd
Copy link
Member Author

lqd commented Apr 18, 2024

@bors try @rust-timer queue

@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 Apr 18, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2024
Enable `rust-lld` on nightly `x86_64-unknown-linux-gnu`

r? ghost

Draft until final preparations are done (making a bootstrap change entry requires a PR number)
@bors
Copy link
Contributor

bors commented Apr 18, 2024

⌛ Trying commit f63b7c5 with merge 5a8c051...

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2024
@lqd lqd marked this pull request as ready for review April 18, 2024 19:11
@rustbot
Copy link
Collaborator

rustbot commented Apr 18, 2024

Some changes occurred in run-make tests.

cc @jieyouxu

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

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

This PR modifies config.example.toml.

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.)

@lqd lqd added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 18, 2024
@bors
Copy link
Contributor

bors commented Apr 18, 2024

☀️ Try build successful - checks-actions
Build commit: 5a8c051 (5a8c051e2c9b7cb9c5bbbf9bc9cf44f12477e577)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5a8c051): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-30.9% [-72.0%, -0.5%] 31
Improvements ✅
(secondary)
-26.4% [-71.3%, -1.5%] 73
All ❌✅ (primary) -30.9% [-72.0%, -0.5%] 31

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
17.7% [12.3%, 23.1%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 17.7% [12.3%, 23.1%] 2

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.7% [6.1%, 9.2%] 4
Improvements ✅
(primary)
-30.7% [-63.0%, -1.0%] 27
Improvements ✅
(secondary)
-24.0% [-61.3%, -2.0%] 72
All ❌✅ (primary) -30.7% [-63.0%, -1.0%] 27

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.1% [0.6%, 4.3%] 28
Regressions ❌
(secondary)
2.0% [0.4%, 5.5%] 74
Improvements ✅
(primary)
-0.3% [-0.3%, -0.2%] 4
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 2
All ❌✅ (primary) 1.8% [-0.3%, 4.3%] 32

Bootstrap: 676.731s -> 669.514s (-1.07%)
Artifact size: 316.11 MiB -> 315.37 MiB (-0.23%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 19, 2024
@albertlarsan68
Copy link
Member

For the bootstrap change:
I would prefer another config, instead of overloading the already existing one.
Something like rust.allow_lld_default, which can only be true when rust.lld is true, seems better IMO.
Also, how does this interact with rust.use_lld?

@Kobzol
Copy link
Contributor

Kobzol commented Apr 19, 2024

The bootstrap change is "temporary", in the sense that once this change lands on beta, it will be enabled by default and bootstrap won't need to configure it, if I understand it correctly. So the bootstrap change doesn't really modify the meaning of rust.lld, it just enables the new default if LLD is built.

The annoying thing here is that we have many axes on what to configure - should LLD be built? (this should arguably be in the llvm section, not rust), should LLD be added to sysroot? should LLD be used when linking the toolchain? should it be used when linking Rust programs? should the self-contained or external LLD be used? And some of these are only relevant for rustc developers. We already have two LLD options that are quite inconsistent in their behavior, I'm not sure if adding a third option makes that situation better 😅 If we go this route, I would rather completely revamp the way we configure LLD (and linker usage in general), so that it makes more sense in bootstrap.

@Mark-Simulacrum
Copy link
Member

The annoying thing here is that we have many axes on what to configure - should LLD be built? (this should arguably be in the llvm section, not rust), should LLD be added to sysroot? should LLD be used when linking the toolchain? should it be used when linking Rust programs? should the self-contained or external LLD be used? And some of these are only relevant for rustc developers. We already have two LLD options that are quite inconsistent in their behavior, I'm not sure if adding a third option makes that situation better 😅 If we go this route, I would rather completely revamp the way we configure LLD (and linker usage in general), so that it makes more sense in bootstrap.

I think this makes sense to me as the right direction to go in, rather than trying to add another option in this PR.


Overall this PR looks good to me at a high level, though I can't review the correctness of the compiler change (@petrochenkov should probably sign off on that), it seems OK to me. I think we should proceed with it. One thing that surprises me though is that this had a positive effect on the binary sizes for what we ship. Were we not already using LLD during that build? Perhaps we were picking up an old LLD from somewhere?

I agree that we should have a blog post notifying users of this change (similar to the parallel frontend one). Once that's ready and a few nits here are fixed, I'm happy to r+

@lqd lqd force-pushed the enable-lld branch 2 times, most recently from 1978bc2 to ded5bfb Compare April 20, 2024 16:52
@lqd
Copy link
Member Author

lqd commented Apr 20, 2024

Were we not already using LLD during that build? Perhaps we were picking up an old LLD from somewhere?

The artifact size reduction is also somewhat surprising to me. I believe that we are indeed already using LLD for that build, via rust.use-lld and that this should find and use the system's LLD 18.1.0 rather than an old one.

@lqd
Copy link
Member Author

lqd commented Apr 22, 2024

I wonder if these size reductions may be some kind of noise, they were not present in the previous runs of #113382 (other than the regular small fluctuations; the only difference with this PR is more builders are enabled there) including this one from yesterday.

The artifacts in the dist build are not linked with the self-contained linker (rust-lld/lld 18.1.4), but via --use-lld (CI's lld 18.1.0), and this can be verified in the .comment section. That is, this PR only makes x86_64-unknown-linux-gnu use rust-lld by default. Dist on the contrary specifies clang as the linker. When that happens, rustc needs to infer a linker flavor: clang is inferred to a C/C++ compiler not using lld, and the self-contained linker is not enabled. That's what already happens today.

Let's maybe see if another run has different results.

edit: done below, no significant change

image

@rust-timer

This comment was marked as resolved.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 22, 2024
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 17, 2024
@lqd
Copy link
Member Author

lqd commented May 17, 2024

@bors retry The runner has received a shutdown signal

@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 May 17, 2024
@bors
Copy link
Contributor

bors commented May 17, 2024

⌛ Testing commit 3a90967 with merge 8af67ba...

@bors
Copy link
Contributor

bors commented May 17, 2024

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 8af67ba to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 17, 2024
@bors bors merged commit 8af67ba into rust-lang:master May 17, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 17, 2024
@lqd lqd deleted the enable-lld branch May 17, 2024 04:30
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8af67ba): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-30.8% [-71.8%, -0.5%] 31
Improvements ✅
(secondary)
-25.6% [-70.9%, -0.5%] 75
All ❌✅ (primary) -30.8% [-71.8%, -0.5%] 31

Max RSS (memory usage)

Results (primary 16.6%, secondary 3.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
16.6% [9.9%, 23.4%] 2
Regressions ❌
(secondary)
3.8% [2.4%, 5.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 16.6% [9.9%, 23.4%] 2

Cycles

Results (primary -30.6%, secondary -24.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-30.6% [-62.4%, -1.0%] 27
Improvements ✅
(secondary)
-24.2% [-61.6%, -2.3%] 71
All ❌✅ (primary) -30.6% [-62.4%, -1.0%] 27

Binary size

Results (primary 2.0%, secondary 1.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.2% [0.6%, 4.2%] 28
Regressions ❌
(secondary)
1.9% [0.5%, 5.5%] 74
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 3
Improvements ✅
(secondary)
-0.6% [-1.0%, -0.1%] 2
All ❌✅ (primary) 2.0% [-0.3%, 4.2%] 31

Bootstrap: 678.599s -> 669.726s (-1.31%)
Artifact size: 316.13 MiB -> 316.16 MiB (0.01%)

plusvic added a commit to VirusTotal/yara-x that referenced this pull request May 18, 2024
Link is currently failing with rust-lld (rust-lang/rust#124129).
nbdd0121 added a commit to Rust-for-Linux/klint that referenced this pull request May 20, 2024
With rust-lang/rust#124129, x64 linux switches
to use LLD by default, but this causes dependency issues on NixOS.
Disable LLD for now.

This is tracked by rust-lang/rust#125321.
kezhuw added a commit to kezhuw/zookeeper-client-rust that referenced this pull request May 21, 2024
kezhuw added a commit to kezhuw/spawns that referenced this pull request May 23, 2024
bherrera pushed a commit to misttech/integration that referenced this pull request Oct 16, 2024
Here are all the changes. I went through them one-by-one and confirmed
that they should not be affecting us. In paritcular, we explicitly set
rust.lld = false (because we want to use the lld that ships with clang),
so the change in default does not affect us.

There have been changes to x.py since you last updated:
  [INFO] New option `build.lldb` that will override the default lldb binary path used in debuginfo tests
    - PR Link rust-lang/rust#124501
  [INFO] The compiler profile now defaults to rust.debuginfo-level = "line-tables-only"
    - PR Link rust-lang/rust#123337
  [WARNING] `rust.lld` has a new default value of `true` on `x86_64-unknown-linux-gnu`. Starting at stage1, `rust-lld` will thus be this target's default linker. No config changes should be necessary.
    - PR Link rust-lang/rust#124129
  [WARNING] Removed `dist.missing-tools` configuration as it was deprecated long time ago.
    - PR Link rust-lang/rust#125535
  [WARNING] `llvm.lld` is enabled by default for the dist profile. If set to false, `lld` will not be included in the dist build.
    - PR Link rust-lang/rust#126701
  [WARNING] `debug-logging` option has been removed from the default `tools` profile.
    - PR Link rust-lang/rust#127913
  [INFO] the `wasm-component-ld` tool is now built as part of `build.extended` and can be a member of `build.tools`
    - PR Link rust-lang/rust#127866
  [INFO] Removed android-ndk r25b support in favor of android-ndk r26d.
    - PR Link rust-lang/rust#120593
  [WARNING] For tarball sources, default value for `rust.channel` will be taken from `src/ci/channel` file.
    - PR Link rust-lang/rust#125181
  [INFO] New option `llvm.libzstd` to control whether llvm is built with zstd support.
    - PR Link rust-lang/rust#125642
  [WARNING] ./x test --rustc-args was renamed to --compiletest-rustc-args as it only applies there. ./x miri --rustc-args was also removed.
    - PR Link rust-lang/rust#128841
  [INFO] The `build.profiler` option now tries to use source code from `download-ci-llvm` if possible, instead of checking out the `src/llvm-project` submodule.
    - PR Link rust-lang/rust#129295

Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/infra/recipes/+/1120078
Original-Revision: 27df37a30e50b14b9ffefc872b6997790f03d4ea
GitOrigin-RevId: 341e222f002e36886b9960645b21faeaed633f90
Change-Id: Id1eb54a677a6f538bf7666d65b85d5fdba17ea42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. 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.

10 participants