1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[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
This commit is contained in:
Luís Marques 2019-12-19 17:20:02 +00:00
parent dc52699bc2
commit d722efa0b9
2 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -0,0 +1,7 @@
# RUN: not llvm-mc -filetype=obj %s -triple=riscv32 -o /dev/null 2>&1 \
# RUN: | FileCheck %s
# RUN: not llvm-mc -filetype=obj %s -triple=riscv64 -o /dev/null 2>&1 \
# RUN: | FileCheck %s
.byte foo # CHECK: [[@LINE]]:7: error: 1-byte data relocations not supported
.2byte foo # CHECK: [[@LINE]]:8: error: 2-byte data relocations not supported