From e61ac366bfeccad6d56089db61e805f507ed8f31 Mon Sep 17 00:00:00 2001 From: Stefan Maksimovic Date: Thu, 11 Jan 2018 10:07:47 +0000 Subject: [PATCH] [Mips] Handle one byte unsupported relocations Fail gracefully instead of crashing upon encountering this type of relocation. Differential revision: https://reviews.llvm.org/D41857 llvm-svn: 322266 --- .../Mips/MCTargetDesc/MipsELFObjectWriter.cpp | 2 ++ test/MC/Mips/unsupported-relocation.s | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/MC/Mips/unsupported-relocation.s diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 6d2f098a6b3..3c67743947c 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -225,6 +225,8 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx, switch (Kind) { case Mips::fixup_Mips_NONE: return ELF::R_MIPS_NONE; + case FK_Data_1: + report_fatal_error("MIPS does not support one byte relocations"); case Mips::fixup_Mips_16: case FK_Data_2: return IsPCRel ? ELF::R_MIPS_PC16 : ELF::R_MIPS_16; diff --git a/test/MC/Mips/unsupported-relocation.s b/test/MC/Mips/unsupported-relocation.s new file mode 100644 index 00000000000..151a559671f --- /dev/null +++ b/test/MC/Mips/unsupported-relocation.s @@ -0,0 +1,13 @@ +# RUN: not llvm-mc -triple mips-unknown-linux -filetype=obj %s 2>%t +# RUN: FileCheck %s < %t + +# Check that we emit an error for unsupported relocations instead of crashing. + + .globl x + + .data +foo: + .byte x + .byte x+1 + +# CHECK: LLVM ERROR: MIPS does not support one byte relocations