From 27aec8037f35219f95b5e49dd9e838450de05cbe Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Thu, 4 Oct 2018 20:43:38 +0000 Subject: [PATCH] [COFF] [X86] Don't use llvm_unreachable for unsupported relocation types This can happen if assembling a reference to _GLOBAL_OFFSET_TABLE_. While it doesn't make sense to try to assemble that for COFF, the fact that we previously used llvm_unreachable meant that the code had undefined behaviour if something tried to assemble that. The configure script of libgmp would try to assemble such a snippet (which should signal a failure). If llvm is built without assertions, the undefined behaviour meant a (near) infinite loop. Differential Revision: https://reviews.llvm.org/D52903 llvm-svn: 343811 --- lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp | 6 ++++-- test/MC/COFF/unsupported-relocations.s | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 test/MC/COFF/unsupported-relocations.s diff --git a/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp b/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp index a5e115e5ff4..2aec695b2db 100644 --- a/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp +++ b/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp @@ -79,7 +79,8 @@ unsigned X86WinCOFFObjectWriter::getRelocType(MCContext &Ctx, case FK_SecRel_4: return COFF::IMAGE_REL_AMD64_SECREL; default: - llvm_unreachable("unsupported relocation type"); + Ctx.reportError(Fixup.getLoc(), "unsupported relocation type"); + return COFF::IMAGE_REL_AMD64_ADDR32; } } else if (getMachine() == COFF::IMAGE_FILE_MACHINE_I386) { switch (FixupKind) { @@ -100,7 +101,8 @@ unsigned X86WinCOFFObjectWriter::getRelocType(MCContext &Ctx, case FK_SecRel_4: return COFF::IMAGE_REL_I386_SECREL; default: - llvm_unreachable("unsupported relocation type"); + Ctx.reportError(Fixup.getLoc(), "unsupported relocation type"); + return COFF::IMAGE_REL_I386_DIR32; } } else llvm_unreachable("Unsupported COFF machine type."); diff --git a/test/MC/COFF/unsupported-relocations.s b/test/MC/COFF/unsupported-relocations.s new file mode 100644 index 00000000000..5c17b0d45ff --- /dev/null +++ b/test/MC/COFF/unsupported-relocations.s @@ -0,0 +1,5 @@ +// RUN: not llvm-mc -filetype=obj -triple i386-pc-win32 %s 2>&1 | FileCheck %s +// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-win32 %s 2>&1 | FileCheck %s +// CHECK: unsupported relocation type + .text + mov $_GLOBAL_OFFSET_TABLE_, %eax