[llvm] r343811 - [COFF] [X86] Don't use llvm_unreachable for unsupported relocation types

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 4 13:43:38 PDT 2018


Author: mstorsjo
Date: Thu Oct  4 13:43:38 2018
New Revision: 343811

URL: http://llvm.org/viewvc/llvm-project?rev=343811&view=rev
Log:
[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

Added:
    llvm/trunk/test/MC/COFF/unsupported-relocations.s
Modified:
    llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp

Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp?rev=343811&r1=343810&r2=343811&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp Thu Oct  4 13:43:38 2018
@@ -79,7 +79,8 @@ unsigned X86WinCOFFObjectWriter::getRelo
     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::getRelo
     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.");

Added: llvm/trunk/test/MC/COFF/unsupported-relocations.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/unsupported-relocations.s?rev=343811&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/unsupported-relocations.s (added)
+++ llvm/trunk/test/MC/COFF/unsupported-relocations.s Thu Oct  4 13:43:38 2018
@@ -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




More information about the llvm-commits mailing list