-
Notifications
You must be signed in to change notification settings - Fork 6
Support RISC-V #1
Support RISC-V #1
Conversation
Patch by PkmX. This patch makes lld recognize RISC-V target and implements basic relocation for RV32/RV64 (and RVC). This should be necessary for static linking ELF applications. The ABI documentation for RISC-V can be found at: https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md. Note that the documentation is far from complete so we had to figure out some details from bfd. The patch should be pretty straightforward. Some highlights: - A new relocation Expr R_RISCV_PC_INDIRECT is added. This is needed as the low part of a PC-relative relocation is linked to the corresponding high part (auipc), see: https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#pc-relative-symbol-addresses - LLVM's MC support for RISC-V is very incomplete (we are working on this), so tests are given in objectyaml format with the original assembly included in the comments. Once we have complete support for RISC-V in MC, we can switch to llvm-as/llvm-objdump. - We don't support linker relaxation for now as it requires greater changes to lld that is beyond the scope of this patch. Once this is accepted we can start to work on adding relaxation to lld. Differential Revision: https://reviews.llvm.org/D39322 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@339364 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 9e54d15)
Sorry I'm not sure if it makes sense to send PRs to this fork, but I thought I'd try... This commit is the initial support for the RISCV architecture in lld. It landed in lld master recently, unfortunately after lld 7.0 was branched off. LLVM itself supports RISCV in 7.0.0, and the first RISCV target landed in Rust itself not long ago, but work is still ongoing to fully support the architecture in lld. This initial patch is enough to link static binaries for the riscv32imac-unknown-none-elf embedded target, although it is still missing some features needed to link dynamic binaries for a Linux userland. We would like to land this patch in rust-lld if possible because it greatly improves the user experience for people who are building for the new riscv32imac-unknown-none-elf target. Currently, they have to obtain a GNU cross toolchain from elsewhere in order to link their Rust programs. With this patch we will be able to switch the target to use rust-lld by default. Corresponding changes to the linker script to support lld are in rust-embedded/riscv-rt#10. |
Also in case it matters, I just wanted to clarify that I am not the original author of this patch nor am I involved in lld development. I've just been helping out in the Rust Embedded WG RISCV team. |
Sounds good to me, thanks! Anything that backports an already-landed patch and doesn't regress our tests is good by our measure :) |
Thanks for merging this @alexcrichton ! I guess the next step is a PR for rust-lang/rust to update the lld submodule to this commit, right? I will file that now. |
This pulls in one new commit, to add support for linking static RISCV binaries, suitable for the new riscv32imac-unknown-none-elf target. See: rust-lang/lld#1
rust-lang/rust#53492 is the corresponding PR to pull this commit into the submodule. |
update lld submodule to include RISCV patch This pulls in one new commit, to add support for linking static RISCV binaries, suitable for the new riscv32imac-unknown-none-elf target. See: rust-lang/lld#1
Cherry-picked from lld master:
llvm-mirror@9e54d15
Originally reviewed here:
https://reviews.llvm.org/D39322