-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Use lld by default on x64 Ubuntu 20.04 LTS #71515
Comments
As a distro maintainer (Fedora and RHEL), I would definitely want this to use the system lld, at least when we're talking about the system rustc that I compile. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There is no such thing as a Ubuntu 20.04 LTS target platform (unlike wasm or the bare embedded targets you mention), but restricting it to |
yes, doing a good job with Ubuntu will likely get a lot of x86_64-unknown-linux-gnu working. but i'd rather get one specific (major) distro working first, since we're talking about integrating with system toolchains here. |
@Gankra I assumed you meant a target based check because the two other cases you mention (wasm and bare metal) are target based. Now I'm even more confused. What do you want to do? A host based check? As in: cargo or rustc trying to invoke |
I don't intend to explicitly check for the distro/release, but rather am willing to have toolchain checks which succeed on vanilla Ubuntu 20.04 but e.g. don't succeed on the latest Arch or older Ubuntus. So we don't need to worry about supporting using rust-lld with older versions of gcc/clang or whatever other tools, as long as our checks are solid enough to detect those things and fall back to using the native The starting point of this would be to not have this detection set up. We would instead blindly try to use rust-lld on x64 linux gnu targets if it's explicitly requested with the In all likelihood this will incidentally get most major modern distro releases working well, but I would regard that as a Happy Accident, and not a priority. It would however provide a tool for distro maintainers to check if rust-lld mode works for them, which is good and useful. After that we would add the detection or expand support until we could have the compiler try to automatically enable rust-lld without an explicit request on x64 linux gnu targets (possibly this step would be done by Cargo and not rustc). Once this is in good enough shape (everything working, not necessarily using rust-lld), we would enable this behaviour in production. From there we will have a solid foundation for folks to push forward rust-lld support on their platforms by either making our toolchain detection more sophisticated, or by updating their distros to meet our requirements. |
@Gankra thanks for the explainer. Have there been any "please test LLD" threads? Those were done e.g. for pipelined compilation and might be helpful in this instance as well. Also maybe one should think about adding an LLD label for issues so that they can be tracked. |
we should have an mvp of #71519 before we ask folks to try out linux lld support |
@1000teslas provided that C libraries have been fixed in #86740, what's the next thing to do to finally use |
@Logarithmus I have no idea to be honest. I was pretty much just following what @Gankra suggested. |
@1000teslas oh wow, great work! All that's left to do is advertise the new flag and provide some instructions for people to test out if it works correctly/and how it performs. I know there was some discussion about the final flag name, could you post instructions on how to use it here? Then someone more familiar with community rallying can encourage people to check it out. |
@Gankra It is used like this: Where should I post the instructions? |
I've prodded the compiler folks to do a writeup, we should be able to take care of the rest for you. I'll post a link the the internals/users thread when it's ready (hopefully very soon, sorry for the slow response on your initial ping). |
Unfortunately, it seems like my PR only works for a stage1 toolchain. I tried to dogfood my PR using a nightly toolchain from rustup on one of my pure-Rust projects and I get some weird errors. When I use ldd on the rust-lld from the nightly toolchain provided by rustup, I see: Then again, I'm using a "weird" distro (NixOS), so maybe it'll work on a more conventional Linux distro. |
|
@bjorn3 Are you saying that even if my system's Anyway, I get errors that look like
|
@1000teslas I'd like to help get the word out about testing this more broadly, would you be able to join us in the compiler team's Zulip so that we can hash out the details? https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Need.20users.2Finternals.20thread.20for.20gcc-lld/near/245177775 |
There does not appear to be blockers for this per rust-lang/rust#71515.
what about |
This comment was marked as resolved.
This comment was marked as resolved.
This issue is purely about a single target (and even a single distro within that target), any other targets would fall under the more general issue linked in the OP or their own tracking issues. |
**What's wrong with `ld`?** It's very slow and uses a lot of memory. **Why `lld`?** It's fast, mature, and well-supported. Meta and Google use it for all their linking workloads. We're already using it for macos and x86-64 Windows. There is [ongoing work to make it the default for rustc](rust-lang/rust#71515), and it already is default on a few platforms. **Why not `mold`?** Mold is generally faster, but the margin is slim enough for our workloads that it doesn't really matter. Mold only recently got support for LTO, doesn't support v0 rust symbol demanging, doesn't support BOLT (though we don't use that yet), etc. Mold is maturing quickly, but `lld` still seems like the "safer" choice.
status update: as of #124129, rustup-distributed rustc (not distros') on |
#8166) **What's wrong with `ld`?** It's very slow and uses a lot of memory. **Why `lld`?** It's fast, mature, and well-supported. Meta and Google use it for all their linking workloads. We're already using it for macos and x86-64 Windows. There is [ongoing work to make it the default for rustc](rust-lang/rust#71515), and it already is default on a few platforms. **Why not `mold`?** Mold is generally faster, but the margin is slim enough for our workloads that it doesn't really matter. Mold only recently got support for LTO, doesn't support v0 rust symbol demanging, doesn't support BOLT (though we don't use that yet), etc. Mold is maturing quickly, but `lld` still seems like the "safer" choice.
Upstream-shipped `rust-ld` is now used as default linker for some targets on nightly. It needs ld-wrapper for interopation with libraries from Nix. Currently `wrapBintools` interface is uneasy for hook use inside a derivation also containing non-bintools stuff. We hereby copy part of the implementation and wrap `rust-ld` in-place. See: rust-lang/rust#71515 (comment)
Upstream-shipped `rust-ld` is now used as default linker for some targets on nightly. It needs ld-wrapper for interopation with libraries from Nix. Currently `wrapBintools` interface is uneasy for hook use inside a derivation also containing non-bintools stuff. We hereby copy part of the implementation and wrap `rust-ld` in-place. See: rust-lang/rust#71515 (comment)
* mk-component-set: apply ld-wrapper for rust-ld Upstream-shipped `rust-ld` is now used as default linker for some targets on nightly. It needs ld-wrapper for interopation with libraries from Nix. Currently `wrapBintools` interface is uneasy for hook use inside a derivation also containing non-bintools stuff. We hereby copy part of the implementation and wrap `rust-ld` in-place. See: rust-lang/rust#71515 (comment) * Bump minimal supported stable nixpkgs to 23.05 We use `env` attrset in `mkDerivation`.
vercel#8166) **What's wrong with `ld`?** It's very slow and uses a lot of memory. **Why `lld`?** It's fast, mature, and well-supported. Meta and Google use it for all their linking workloads. We're already using it for macos and x86-64 Windows. There is [ongoing work to make it the default for rustc](rust-lang/rust#71515), and it already is default on a few platforms. **Why not `mold`?** Mold is generally faster, but the margin is slim enough for our workloads that it doesn't really matter. Mold only recently got support for LTO, doesn't support v0 rust symbol demanging, doesn't support BOLT (though we don't use that yet), etc. Mold is maturing quickly, but `lld` still seems like the "safer" choice.
#65898) Copies changes from vercel/turborepo#8166, and updates contributing documentation to include the installation of lld. > **What's wrong with `ld`?** It's very slow and uses a lot of memory. > > **Why `lld`?** It's fast, mature, and well-supported. Meta and Google use it for all their linking workloads. We're already using it for macos and x86-64 Windows. There is [ongoing work to make it the default for rustc](rust-lang/rust#71515), and it already is default on a few platforms. > > **Why not `mold`?** Mold is generally faster, but the margin is slim enough for our workloads that it doesn't really matter. Mold only recently got support for LTO, doesn't support v0 rust symbol demanging, doesn't support BOLT (though we don't use that yet), etc. Mold is maturing quickly, but `lld` still seems like the "safer" choice.
What's the next step here? Now that we have some experience with LLD on nightly, in order to proceed further we'd need to start identifying LLD-related bugs and determining which of them are blockers. I think the And even beyond blocking bugs, surely we can think about the steps after that and start pursuing them concurrently. For example, are all the rustc command line flags properly designed, bikeshedded, implemented, and stabilized? What about the Cargo-level config options? (Following the history of how the linker is intended to be configured seems to be surprisingly difficult!) And even once we have no more blocking bugs and we've solved the user interface question, have we determined if we're allowed to change the default? In other words, is changing the default linker a breaking change? (IME linker scripts are incompatible between LD and LLD, which is an example of something that's sure to break.) If so, then we'd need to wait until the next edition to change this over to be the default. |
Was this ever solved? |
Probably not, and we're likely not going to implement it in lld ourselves. You could maybe hack something via setting the number of threads lld can use according to the number of tokens rustc has. Though it may not be that big of a problem for us, since linking is usually at the latest stages of the process, where's less contention. We can at the very least document this and the issues it can cause, and if people absolutely need such support, they can switch back to bfd. |
People have filed issues about too much linker parallelism causing OOM kills, e.g. rust-lang/cargo#9157 |
I'm aware, and also don't think firefox/chromium builds are representative. Jobserver support will not make memory consumption lower by itself. If people want to add some finer-grained link job control to cargo and rustc that would be cool. Are you saying this is a blocker for landing lld on stable? |
I suspect that it wouldn't just affect big projects but also people on machines low on free ram. At least a few perf items in the PR that enabled it in nightly regressed MaxRSS, and those are fairly small jobs, it might be more for bigger applications. So we should at least make it part of the release announcement too if it's going to regress reliability for some users. |
Oh fully agreed; I had already mentioned that the added parallelism may cause issues on resource-constrained environments back in the nightly announcement. Mentioning this, as well as the other more obscure issues related to GC sections or |
The status of this is a bit unclear - the "blocking issues" are resolved, are any of the remaining issues blocking? |
@lqd Can we get this nominated for compiler team discussion? Do we need a stabilization PR first? |
There’s no need for the team to discuss this just yet, but we’re working on it: in the last few days, we’ve been checking all the issues that have been opened since the switch on nightly, doing crater runs, etc. There still are a few things to do before preparing a stabilization report. |
This is a metabug, constraining the unbound scope of #39915.
What is lld
A linker that's part of the llvm project, which is desirable for two reasons:
Rust currently ships its own copy of lld which it calls rust-lld. This is used by default to link bare-metal targets and wasm.
Goal
The goal of this metabug is to use rust-lld by default on a major x64 linux distro. I have arbitrarily chosen Ubuntu 20.04 LTS as our target. With all likelihood, this will incidentally get it working/enabled on many other linux distros, BSDs, and other similar platforms, but I am purposefully constraining the scope to one distro for the sake of focusing the effort.
My understanding is that the ELF backend is quite well maintained. Quoting lld's own landing page:
Hopefully this has continued to improve, and using lld will be a slam dunk. Although I specify that we should use rust-lld, it may be necessary/desirable to detect and use system copies of lld.
Blocking Issues
The text was updated successfully, but these errors were encountered: