summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjo <martin@martin.st>2018-10-04 20:43:38 +0000
committerMartin Storsjo <martin@martin.st>2018-10-04 20:43:38 +0000
commitfea7ddb36e42bbb07faae66b771b52eaf88bfd0d (patch)
tree0ecb772f973c61529eb6d2069e3a78120528c24f
parenta7fa70cb3e47668da003d5f1e5e9e64ceb4d5404 (diff)
[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
-rw-r--r--llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp6
-rw-r--r--llvm/test/MC/COFF/unsupported-relocations.s5
2 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
index a5e115e5ff4..2aec695b2db 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
+++ b/llvm/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/llvm/test/MC/COFF/unsupported-relocations.s b/llvm/test/MC/COFF/unsupported-relocations.s
new file mode 100644
index 00000000000..5c17b0d45ff
--- /dev/null
+++ b/llvm/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