feat: Add support for linker plugins#1411
Conversation
e478126 to
7aef71a
Compare
|
The test failures appear to be related to how I'm testing not due to the actual LTO implementation. On older versions of Ubuntu the problem is because we're trying to use linker-plugin LTO with LLVM bitcode produced by rustc, but the plugin is for an older version of LLVM than what Rustc uses. My plan there is to check rust's version of LLVM (with On OpenSUSE, it seems that LLVMgold.so - the linker plugin for LLVM/clang just isn't installed. I haven't found a way to install it as yet, so probably I'll run a command like There are some Ubuntu aarch64 failures that appear to be linker-diff not knowing how to interpret a relaxation that happened. On Alpine linux, the wild binary seems to be statically linked, so can't load the linker plugin shared object. Fixing this probably requires either switching our builds on alpine to use dynamic linking or detecting that we've been statically linked and skipping linker-plugin tests. |
lapla-cogito
left a comment
There was a problem hiding this comment.
nit: This line in BENCHMARKING.md also can be updated: https://github.com/davidlattimore/wild/blob/bb2339ac6615b8039468d6abc5e58e72f1f8ebc6/BENCHMARKING.md?plain=1#L11
|
@davidlattimore is it possible to split the work? I'd like to help. |
7aef71a to
7fdbe73
Compare
|
Thanks @karolzwolak. I'm doing some benchmarking work at the moment, then I'm going to do a release. After that, I intend to return to linker plugins. I've just pushed my latest changes. I think the main thing left to deal with is the aarch64 linker-diff failures, which look like this: You're welcome to have a look at the aarch64 failure if you want. I'm not sure how straightforward it will be. There are a few other failures besides those, but I haven't look at them yet. Another option is you could try compiling a few things, especially C and C++ projects, with linker-plugin LTO and see if it works. In addition to fixing failing tests, I should probably do a thorough review of the change myself to look for stuff that I meant to come back to, but forgot, stuff that shouldn't be in the commit etc. You're welcome to review the change yourself and ask questions if things aren't clear. I'll then try to add comments or make other changes accordingly. |
|
How much space would it take for rustc itself to ship a linker plugin matching the LLVM version it uses? If it is only a tiny bit, maybe we could just do that on the rustc side and then you could use it during testing? |
|
Interesting idea. On my system |
|
We don't dynamically link against LLVM on all targets, but on those where we do, 88kb wouldn't even need a separate component. Adding it to the rustc component would be just fine. That I think just leaves a policy question about if we want to provide a linker plugin (I think we should. It would make cross-lang LTO easier.) and what to do about the targets where we statically link LLVM. I don't know the exact reason we statically link on those targets. |
|
Rustc part discussion should probably move to another place....
When it comes to Windows, dynamic linking of libLLVM is supported only when building with Clang in MinGW mode: llvm/llvm-project@c5b3de6#diff-c32cf5f1ab46b94ceac7f7597aace44624436f439c8304c029feca005c000a4bR245-R247 |
9248b5b to
9629937
Compare
|
All tests now pass :) |
9629937 to
4469ea7
Compare
|
Would it be possible to have this behind a feature flag for targets that don't support dynamic linking? |
Good idea. Will do. The other blocker before I can merge this is that I've observed a 1.7% showdown when linking wild even without a linker plugin. I still need to figure out the cause. |
d7b35b9 to
f4d96cd
Compare
|
I've made plugin support be a cargo feature (on by default). I also hit some new test failures in CI which I've now fixed. It turned that that those failures were because the latest nightly builds of rustc are using LLVM 22, but the LLVM linker plugin on most of test systems is version 20. This wasn't being picked up by the LTO compatibility check, but is now. But it does raise an interesting point, which is that right now we're probably not actually testing rust linker plugin LTO, since we're using nightly for all our CI tests and I don't think any of our test systems have LLVM 22 yet. From the CI failure, It looks like Ubuntu 26.04 has LLVM 21. I'm still investigating performance changes. |
f4d96cd to
ab8c137
Compare
|
In order to get this large PR merged, I've decided to switch to having the I did observe a performance change even with the feature disabled. This however appears to be due to some code being deleted, causing slightly different codegen units, resulting in different optimisations being applied. Once I did a performance test with codegen-units=1, the effect went away. |
The plugin is disabled by default upstream. See-also: wild-linker/wild#1411 Signed-off-by: zyxhere💭 <zyx@envs.net> Part-of: https://codeberg.org/gentoo/gentoo/pulls/77 Merges: https://codeberg.org/gentoo/gentoo/pulls/77 Signed-off-by: Sam James <sam@gentoo.org>
Fixes #1