diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp @@ -9,6 +9,7 @@ #include "MCTargetDesc/RISCVFixupKinds.h" #include "MCTargetDesc/RISCVMCExpr.h" #include "MCTargetDesc/RISCVMCTargetDesc.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCObjectWriter.h" @@ -54,7 +55,8 @@ if (IsPCRel) { switch (Kind) { default: - llvm_unreachable("invalid fixup kind!"); + Ctx.reportError(Fixup.getLoc(), "Unsupported relocation type"); + return ELF::R_RISCV_NONE; case FK_Data_4: case FK_PCRel_4: return ELF::R_RISCV_32_PCREL; @@ -87,7 +89,14 @@ switch (Kind) { default: - llvm_unreachable("invalid fixup kind!"); + Ctx.reportError(Fixup.getLoc(), "Unsupported relocation type"); + return ELF::R_RISCV_NONE; + case FK_Data_1: + Ctx.reportError(Fixup.getLoc(), "1-byte data relocations not supported"); + return ELF::R_RISCV_NONE; + case FK_Data_2: + Ctx.reportError(Fixup.getLoc(), "2-byte data relocations not supported"); + return ELF::R_RISCV_NONE; case FK_Data_4: if (Expr->getKind() == MCExpr::Target && cast(Expr)->getKind() == RISCVMCExpr::VK_RISCV_32_PCREL) diff --git a/llvm/test/MC/RISCV/fixups-invalid.s b/llvm/test/MC/RISCV/fixups-invalid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/fixups-invalid.s @@ -0,0 +1,10 @@ +# RUN: not llvm-mc -filetype=obj %s -triple=riscv32 -o /dev/null 2>&1 \ +# RUN: | FileCheck %s + +.byte foo +# CHECK: error: 1-byte data relocations not supported +# CHECK-NEXT: foo + +.2byte bar +# CHECK: error: 2-byte data relocations not supported +# CHECK-NEXT: bar