[PATCH] D52903: [COFF] [X86] Don't use llvm_unreachable for unsupported relocation types

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 4 12:32:37 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, smeenai, craig.topper, zturner.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D52903

Files:
  lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
  test/MC/COFF/unsupported-relocations.s


Index: test/MC/COFF/unsupported-relocations.s
===================================================================
--- /dev/null
+++ 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
Index: lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
===================================================================
--- lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
+++ lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
@@ -79,7 +79,8 @@
     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 @@
     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.");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52903.168351.patch
Type: text/x-patch
Size: 1402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181004/7c5833cc/attachment.bin>


More information about the llvm-commits mailing list