Skip to content

Commit

Permalink
[RISCV] Add RISC-V ELF defines
Browse files Browse the repository at this point in the history
Add the necessary definitions for RISC-V ELF files, including relocs. Also 
make necessary trivial change to ELFYaml, llvm-objdump, and llvm-readobj in 
order to work with RISC-V ELFs.

Differential Revision: https://reviews.llvm.org/D23557

llvm-svn: 285708
  • Loading branch information
asb committed Nov 1, 2016
1 parent b6e784a commit 1524f62
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions llvm/include/llvm/Object/ELFObjectFile.h
Expand Up @@ -865,6 +865,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
return "ELF32-mips";
case ELF::EM_PPC:
return "ELF32-ppc";
case ELF::EM_RISCV:
return "ELF32-riscv";
case ELF::EM_SPARC:
case ELF::EM_SPARC32PLUS:
return "ELF32-sparc";
Expand All @@ -885,6 +887,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
return (IsLittleEndian ? "ELF64-aarch64-little" : "ELF64-aarch64-big");
case ELF::EM_PPC64:
return "ELF64-ppc64";
case ELF::EM_RISCV:
return "ELF64-riscv";
case ELF::EM_S390:
return "ELF64-s390";
case ELF::EM_SPARCV9:
Expand Down Expand Up @@ -940,6 +944,15 @@ unsigned ELFObjectFile<ELFT>::getArch() const {
return Triple::ppc;
case ELF::EM_PPC64:
return IsLittleEndian ? Triple::ppc64le : Triple::ppc64;
case ELF::EM_RISCV:
switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
case ELF::ELFCLASS32:
return Triple::riscv32;
case ELF::ELFCLASS64:
return Triple::riscv64;
default:
report_fatal_error("Invalid ELFCLASS!");
}
case ELF::EM_S390:
return Triple::systemz;

Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/Support/ELF.h
Expand Up @@ -310,6 +310,7 @@ enum {
EM_NORC = 218, // Nanoradio Optimized RISC
EM_CSR_KALIMBA = 219, // CSR Kalimba architecture family
EM_AMDGPU = 224, // AMD GPU architecture
EM_RISCV = 243, // RISC-V
EM_LANAI = 244, // Lanai 32-bit processor
EM_BPF = 247, // Linux kernel bpf virtual machine

Expand Down Expand Up @@ -597,6 +598,11 @@ enum {
#include "ELFRelocs/Lanai.def"
};

// ELF Relocation types for RISC-V
enum {
#include "ELFRelocs/RISCV.def"
};

// ELF Relocation types for S390/zSeries
enum {
#include "ELFRelocs/SystemZ.def"
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Object/ELF.cpp
Expand Up @@ -89,6 +89,13 @@ StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) {
break;
}
break;
case ELF::EM_RISCV:
switch (Type) {
#include "llvm/Support/ELFRelocs/RISCV.def"
default:
break;
}
break;
case ELF::EM_S390:
switch (Type) {
#include "llvm/Support/ELFRelocs/SystemZ.def"
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/ObjectYAML/ELFYAML.cpp
Expand Up @@ -194,6 +194,7 @@ ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(IO &IO,
ECase(EM_78KOR)
ECase(EM_56800EX)
ECase(EM_AMDGPU)
ECase(EM_RISCV)
ECase(EM_LANAI)
ECase(EM_BPF)
#undef ECase
Expand Down Expand Up @@ -529,6 +530,9 @@ void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
case ELF::EM_ARM:
#include "llvm/Support/ELFRelocs/ARM.def"
break;
case ELF::EM_RISCV:
#include "llvm/Support/ELFRelocs/RISCV.def"
break;
case ELF::EM_LANAI:
#include "llvm/Support/ELFRelocs/Lanai.def"
break;
Expand Down
1 change: 1 addition & 0 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Expand Up @@ -704,6 +704,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
case ELF::EM_HEXAGON:
case ELF::EM_MIPS:
case ELF::EM_BPF:
case ELF::EM_RISCV:
res = Target;
break;
case ELF::EM_WEBASSEMBLY:
Expand Down
1 change: 1 addition & 0 deletions llvm/tools/llvm-readobj/ELFDumper.cpp
Expand Up @@ -945,6 +945,7 @@ static const EnumEntry<unsigned> ElfMachineType[] = {
ENUM_ENT(EM_78KOR, "EM_78KOR"),
ENUM_ENT(EM_56800EX, "EM_56800EX"),
ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"),
ENUM_ENT(EM_RISCV, "RISC-V"),
ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY"),
ENUM_ENT(EM_LANAI, "EM_LANAI"),
ENUM_ENT(EM_BPF, "EM_BPF"),
Expand Down

0 comments on commit 1524f62

Please sign in to comment.