summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
diff options
context:
space:
mode:
authorLuís Marques <luismarques@lowrisc.org>2019-12-19 17:20:02 +0000
committerLuís Marques <luismarques@lowrisc.org>2019-12-19 17:21:30 +0000
commitec4f06a77ded520747e119fdac1f70a010d6b6a8 (patch)
tree2742171dfede78b6ae8385b1bc8e0ed712e5f8e7 /llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
parent13d30bd54b8b4903255fdb6e09d9719aeceda4a3 (diff)
downloadbcm5719-llvm-ec4f06a77ded520747e119fdac1f70a010d6b6a8.tar.gz
bcm5719-llvm-ec4f06a77ded520747e119fdac1f70a010d6b6a8.zip
[RISCV] Don't crash on unsupported relocations
Summary: Instead of crashing due to the `llvm_unreachable`, provide a proper error when invalid fixups/relocations are encountered. Reviewers: asb, lenary Reviewed By: asb Tags: #llvm Differential Revision: https://reviews.llvm.org/D71536
Diffstat (limited to 'llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp')
-rw-r--r--llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
index cab2bbcb81b..08b75795ed4 100644
--- 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 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
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 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
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<RISCVMCExpr>(Expr)->getKind() == RISCVMCExpr::VK_RISCV_32_PCREL)
OpenPOWER on IntegriCloud