Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Support RISC-V #1

Merged
merged 1 commit into from
Aug 19, 2018
Merged

Conversation

danc86
Copy link

@danc86 danc86 commented Aug 18, 2018

Cherry-picked from lld master:
llvm-mirror@9e54d15

Originally reviewed here:
https://reviews.llvm.org/D39322

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)
@danc86
Copy link
Author

danc86 commented Aug 18, 2018

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.

@danc86
Copy link
Author

danc86 commented Aug 18, 2018

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.

@alexcrichton alexcrichton merged commit 813b3b9 into rust-lang:rust-llvm-release-7-0-0-v2 Aug 19, 2018
@alexcrichton
Copy link
Member

Sounds good to me, thanks!

Anything that backports an already-landed patch and doesn't regress our tests is good by our measure :)

@danc86
Copy link
Author

danc86 commented Aug 19, 2018

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.

danc86 added a commit to danc86/rust that referenced this pull request Aug 19, 2018
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
@danc86
Copy link
Author

danc86 commented Aug 19, 2018

rust-lang/rust#53492 is the corresponding PR to pull this commit into the submodule.

kennytm added a commit to kennytm/rust that referenced this pull request Aug 21, 2018
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants