diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 93b84a8d069..7d73b19b36d 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -865,6 +865,8 @@ StringRef ELFObjectFile::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"; @@ -885,6 +887,8 @@ StringRef ELFObjectFile::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: @@ -940,6 +944,15 @@ unsigned ELFObjectFile::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; diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h index 7e878a52800..b4ef84dfcda 100644 --- a/include/llvm/Support/ELF.h +++ b/include/llvm/Support/ELF.h @@ -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 @@ -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" diff --git a/lib/Object/ELF.cpp b/lib/Object/ELF.cpp index 4d37a298632..23682e1fabf 100644 --- a/lib/Object/ELF.cpp +++ b/lib/Object/ELF.cpp @@ -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" diff --git a/lib/ObjectYAML/ELFYAML.cpp b/lib/ObjectYAML/ELFYAML.cpp index 2137eee4752..0c42a1ad2fb 100644 --- a/lib/ObjectYAML/ELFYAML.cpp +++ b/lib/ObjectYAML/ELFYAML.cpp @@ -194,6 +194,7 @@ ScalarEnumerationTraits::enumeration(IO &IO, ECase(EM_78KOR) ECase(EM_56800EX) ECase(EM_AMDGPU) + ECase(EM_RISCV) ECase(EM_LANAI) ECase(EM_BPF) #undef ECase @@ -529,6 +530,9 @@ void ScalarEnumerationTraits::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; diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index f8bef75d53a..3f6ef52973f 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -704,6 +704,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, case ELF::EM_HEXAGON: case ELF::EM_MIPS: case ELF::EM_BPF: + case ELF::EM_RISCV: res = Target; break; case ELF::EM_WEBASSEMBLY: diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 9c594a0e339..41f06d42a25 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -945,6 +945,7 @@ static const EnumEntry 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"),