LLVM Bitcode Linker: A self contained linker for nvptx and other targets#117458
LLVM Bitcode Linker: A self contained linker for nvptx and other targets#117458bors merged 6 commits intorust-lang:masterfrom
Conversation
|
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
|
@rustbot label +O-NVPTX |
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
Cc: @workingjubilee as I remember we talked about this in this issue denzp/rust-ptx-linker#34 (comment) |
|
Can we require fat LTO for nvptx? When rustc does fat LTO it already combines all crates into a single object file. |
|
I'm really excited to hear that PTX might gain a maintained linker again! Two years ago I was using Rust to write single-source kernels for NVIDIA GPUs, where LTO and inlining were crucial. I at some point had to fork the ptx-linker crate to keep LTO working with newer LLVM versions. It would be awesome if linking would "just work" instead again, so that the linker's is kept in sync and supports fat LTO. Thank you so much for working on this ❤️ |
It would certainly be possible, rust is capable of calling the right functions in llvm to make it work. But it doesn't work "out of the box" and I'm not certain it's the correct thing to do long term eiteher. If we decided to use only When it comes to compiler change we would still need to add When I tested it just now it seems like As an addition, there might be future benefits an approach as this embedded-linker can have to other targets than ptx as well. Maybe it can be used to bring thin lto to embedded targets where the native linker doesn't support it. It can also provide compilation without requiring to install an external target specific linker. Is this an approach we would like to explore further even with the known deficiencies listed above? Is the main advantage that we avoid yet another tool that needs to be maintained? Or that we get more control using libLLVM compared to calling the llvm tools? |
That will be fixed soon. There is an open PR for making compiler-builtins participate in LTO. |
5a9b1dc to
282b8d3
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
|
There are a few questions in my original post, but I think the one that stops me from moving forward is figuring out whether this is an approach that can be accepted. Are there any processes required to get something like this MR approved (MCP?) or is it just a matter of completing the implementation? Insight like "this is probably not going to be accepted, but bjorn3's alternative probably will be" would also be very helpful to help me avoid putting effort into something that is probably not going to go anywhere. |
|
I planned to review it in a couple of weeks. |
|
I think the general approach is fine, we can ship a small additional tool, especially if it's not enabled by default. |
This comment has been minimized.
This comment has been minimized.
36ef2b6 to
8b47f5a
Compare
|
This should be ready now. |
This comment was marked as resolved.
This comment was marked as resolved.
8b47f5a to
355e833
Compare
|
I did a manual rebase to fix the conflict now. It was only a minor conflict (in @rustbot label -S-waiting-on-author +S-waiting-on-review |
|
@bors r+ |
|
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands: The following commits are merge commits: |
|
@petrochenkov Yet another conflict in @rustbot label -S-waiting-on-author +S-waiting-on-review |
|
@bors r- |
|
@bors r+ |
This PR introduces a new linker named
llvm-bitcode-linker. It is aself-containedlinker that can be used to link programs inllbcbefore optimizing and compiling to native code. It will first be used internally in the Rust compiler to enable tests for thenvptx64-nvidia-cudatarget as the originalrust-ptx-linkeris deprecated. It will then be provided to users of thenvptx64-nvidia-cudatarget with the purpose of linking ptx. More targets than nvptx will also be supported eventually.The PR introduces a new unstable
LinkerFlavorfor the compiler. The compiler will also not be shipped with rustc but most likely instead be shipped in it's own unstable component (a follow up PR will be opened for this). This means that merging this PR should not add any stability guarantees.When more details of
self-containedis implemented it will only be possible to use the linker when-Clink-self-contained=+linkeris passed.Original Description
When this PR was created it was focused a bit differently. The original text is preserved here in case there's some interests in it
I have experimenting with approaches to replace the ptx-linker and enable the nvptx target tests again. I think it's time to get some feedback on the approach.
The problem
The only useful linker for the nvptx target is this crate. Since this linker performs linking on llvm bitcode it needs to track the llvm version of rustc and use the same format. It has not been maintained for 3+ years and must be considered abandoned. Over the years rust have upgraded LLVM while the linker has been left to bitrot. It is no longer in a usable state.
Due to the difficulty of keeping the ptx-linker up to date outside of tree the nvptx tests was disabled a long time ago. It was previously discussed if adding the ptx-linker to the rust repo would be a possibility. My efforts in doing this stopped at getting an answered if the license would prohibit it from inclusion in the Rust repo. I therefore concluded that a re-write would be necessary.
The possible solution presented here
The llvm tools know perfectly well how to link and optimize llvm bitcode. Each of them only perform a single task, and are therefore a bit cumbersome to call with the current linker approach rustc takes.
This PR adds a simple tool (current name
embedded-linker) which can link self contained (often embedded) programs in llvm bitcode before compiling to the target format. Optimization will also be performed if lto is enabled. The rust compiler will make a single invocation to this tool, while the tool will orchestrate the many calls to the llvm tools.The questions
llvm-linkto the llvm-tool component require any process?