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:
parent
dc52699bc2
commit
d722efa0b9
@ -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)
|
||||
|
7
test/MC/RISCV/fixups-invalid.s
Normal file
7
test/MC/RISCV/fixups-invalid.s
Normal 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
|
Loading…
x
Reference in New Issue
Block a user