-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Linking with LLD #39915
Comments
See also a PoC in #36120. |
LLD may be a very good candidate for MinGW targets, because we currently bundle a linker with them anyway and MinGW's linker has a variety of issues ranging from a lack of ASLR to no bigobj support. If we can somehow also bring along the necessary mingw libraries when cross compiling and not just native targeting (which rustup's mingw package is currently limited to), then that would enable rust cross compilation from linux out of the box, which would be a huge improvement over the existing situation where people get MinGW from their distro and then run into issues because distros almost always use an incompatible MinGW. LLD is not a good candidate for natively targeting MSVC targets, due to several reasons, the primary reason being the lack of debuginfo support. Cross compiling to MSVC targets requires libraries that can't be redistributed so we can't support that out of the box anyway. |
The tracking issue for upgrading to LLVM 4.0 is #37609 . |
For the record lld is definitely not ready for Solaris targets. But on Solaris, there's no reason that I'm aware of to use lld instead of the native ld instead. We've already been looking at what it would take to have rust use Solaris ld on Solaris instead of using gcc for linking. |
@binarycrusader One reason to use lld is when building for Solaris, not on Solaris. |
PR #40018 adds a @binarycrusader ^ that may help with your experiment of directly using Solaris' ld instead of gcc. |
We now appear to be running on LLVM 4.0. @japaric , does this mean that the linker-flavor flag can now be easily used to compare and contrast LLD with the system linker? |
@bstrie #40018 landed a few weeks ago. Since that landed one has been able to use What LLVM 4.0 helps with is merging LLD into rustc. With that change we wouldn't require an external linker in some scenarios like linking MUSL binaries or bare metal programs. I say some scenarios because most targets require linking to system libraries where you will run into the library search path problem I mentioned above. For those targets, LLD won't work out of the box. It's not clear how and where to solve that problem and without a solution for that we can't switch to LLD for the most important (tier 1) targets, which the reduces the appeal of embedding LLD into rustc in the first place. |
@japaric What are the arguments against embedding (sysroot-relative library) search paths, as well as things like The only drawback I can think of is the situation where the same triple would have different search paths on different flavors of systems (which will likely be exclusive to Linux/glibc triples, and especially bad on platforms with multilib). In that case, I believe clang snoops the OS name and hardcodes OS-specific conventions, which seems bad but probably unavoidable if one wants to distribute a single binary that runs on any Linux (and doesn't need the system linker). |
@retep998 I had a brief look at lld a few months ago. I wasn't able to cross compile (cross link?) an .exe from Linux. It seemed like lld only supports platform native formats. Hopefully I'm mistaken. |
Tagging this as a performance bug, since according to LLD's benchmarks it seems to outperform GNU ld by a factor of ten, and linking performance is a large component of compiler speed currently. |
Er, forgot to link the benchmarks: https://lld.llvm.org/#performance (Relevant today since LLVM 5.0 has just been released.) |
Linking with LLD is much faster than bfd or gold, but I doubt that using it will significantly improve overall performance. Still I think this issue is important and should be a priority. |
@tpimh I'm actually not entirely sure whether the I-slow tag is supposed to represent runtime performance bugs or compiletime performance bugs, I was intending it as the latter. And IME when I look at time-passes output linking is usually in the top three longest phases, significantly longer than most, so even cutting linking time in half would probably be a huge win (especially for big things like Servo and rustc). |
@bstrie I-slow is for bad runtime performance, I-compiletime is for compiler perf last time I checked |
Good news for anybody interested in the obscure topic of cross linking from Linux to Windows. I said earlier it wasn't possible with lld, but that's only true for lld's ld flavor. It's possible for lld's link.exe flavour (lld-link). Specifically for Rust we can do this today with a couple code changes.
Doing the above steps allows me to cross compile Rust code. I can even panic and catch panics using Rust's SEH-based unwinding. |
@iainnicol You're mixing the msvc target with MinGW bits, which is why you have to do all those weird modifications. If you just copy over the libraries from an existing VC++ installation then you can use lld-link normally without all those modifications or any MinGW bits. |
But I don't want to use an existing VC++ installation. There isn't even any way to get one without spending something like eight hours downloading and installing junk, much less to redistribute. |
The standalone build tools are much lighter-weight, unless that's already what you're referring to, in which case perhaps we ought to put some work into improving or recreating what MinGW did so it's actually compatible with MSVC. |
I haven't realized Microsoft distributes those. Could you link to them? Is there any reasonable way to extract the installation archive without actually running it i.e. is it an msi or something similar? |
Here they are: http://landinghub.visualstudio.com/visual-cpp-build-tools Both the 2015 and 2017 versions are exes, but you may be able to convince the 2017 exe to give you what you want via this: https://docs.microsoft.com/en-us/visualstudio/install/install-vs-inconsistent-quality-network |
If we really want to do this right for Windows, we'd first of all need #30027 to eliminate the need for the Windows SDK or MinGW's import libraries. Then all we'd have left is to replace the CRT bits with our own pure Rust versions (math/memory functions, entry point, a few other runtime bits Rust needs) and we'd have a fully self-contained Rust toolchain that can create Windows binaries! The downside of this is that you wouldn't be able to statically link C/C++ code because that relies very heavily on linking in the appropriate CRT from either MinGW or VC++. Of course the whole point of Rust is to rewrite everything in Rust, so this isn't really much of an issue. |
I will like to know if the goal of using lld as the default linker has been achieved ? |
It isn't the default yet. |
I believe LLD on macOS is now in a much better state (and specifically that whereas previously the macOS version of lld was a completely separate codebase from the windows/linux versions, macOS lld is now based on the same codebase as windows/linux lld). Certainly, linking with homebrew installed LLD seems to work well with stable Rust. Would it make sense to create an issue for making LLD the default linker on macOS? |
There are issues open for Linux and Windows already and none for Mac. So having one might be reasonable for parity, but I don't think it will make any difference one way or the other about when this will happen. AIUI there are still various things blocking shipping on any platform, e.g. this. @lqd and @petrochenkov will know more. |
I would like to know the current status of the |
This comment was marked as abuse.
This comment was marked as abuse.
It is actively unhelpful. |
It's mostly prepared, implementation-wise, but we're still deciding on how should the CLI flags work. See #119906 for the most recent discussion. |
status update: as of #124129, rustup-distributed rustc (not distros') on |
LLVM 4.0 is shipping with LLD enabled, though AFAIK it is not yet production-ready on all platforms. I believe we've got an LLVM upgrade planned soon to resolve AVR/emscripten problems anyway, so now's the time to start determining what we might need to do to support it, how it impacts compiler performance/binary size/runtime performance compared to our usual linkers, and what platforms on which we might want to enable it by default.
Current status (2020-04-24) summarized at #39915 (comment)
Possible problems:
The text was updated successfully, but these errors were encountered: