Support RISC-V
authorRui Ueyama <ruiu@google.com>
Thu, 9 Aug 2018 17:59:56 +0000 (17:59 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 9 Aug 2018 17:59:56 +0000 (17:59 +0000)
commit5cd9c6bcd8a4307af588fd613c037281ee80761b
tree52ba5b9a3310c11d698206861bd8b426a9d38c30
parentbf9fe79397419a33d1bda13836b9218d0f3e4108
Support RISC-V

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

llvm-svn: 339364
19 files changed:
lld/ELF/Arch/RISCV.cpp [new file with mode: 0644]
lld/ELF/CMakeLists.txt
lld/ELF/Driver.cpp
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/ELF/Relocations.cpp
lld/ELF/Relocations.h
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/Target.cpp
lld/ELF/Target.h
lld/ELF/Writer.cpp
lld/test/ELF/riscv-branch.test [new file with mode: 0644]
lld/test/ELF/riscv-call.test [new file with mode: 0644]
lld/test/ELF/riscv-hi20-lo12.test [new file with mode: 0644]
lld/test/ELF/riscv-jal-error.test [new file with mode: 0644]
lld/test/ELF/riscv-jal.test [new file with mode: 0644]
lld/test/ELF/riscv-pcrel-hilo.test [new file with mode: 0644]
lld/test/lit.cfg.py