<div dir="ltr">FYI this broke the WebAssembly build, fixed in r257709.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 13, 2016 at 2:56 PM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Wed Jan 13 16:56:57 2016<br>
New Revision: 257697<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=257697&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=257697&view=rev</a><br>
Log:<br>
Convert a few assert failures into proper errors.<br>
<br>
Fixes PR25944.<br>
<br>
Added:<br>
    llvm/trunk/test/MC/X86/error-reloc.s<br>
Modified:<br>
    llvm/trunk/include/llvm/MC/MCELFObjectWriter.h<br>
    llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp<br>
    llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp<br>
    llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCELFObjectWriter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCELFObjectWriter.h?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCELFObjectWriter.h?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCELFObjectWriter.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCELFObjectWriter.h Wed Jan 13 16:56:57 2016<br>
@@ -17,6 +17,7 @@<br>
<br>
 namespace llvm {<br>
 class MCAssembler;<br>
+class MCContext;<br>
 class MCFixup;<br>
 class MCFragment;<br>
 class MCObjectWriter;<br>
@@ -64,8 +65,8 @@ public:<br>
<br>
   virtual ~MCELFObjectTargetWriter() {}<br>
<br>
-  virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                                bool IsPCRel) const = 0;<br>
+  virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                                const MCFixup &Fixup, bool IsPCRel) const = 0;<br>
<br>
   virtual bool needsRelocateWithSymbol(const MCSymbol &Sym,<br>
                                        unsigned Type) const;<br>
<br>
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -129,9 +129,9 @@ class ELFObjectWriter : public MCObjectW<br>
     bool hasRelocationAddend() const {<br>
       return TargetObjectWriter->hasRelocationAddend();<br>
     }<br>
-    unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                          bool IsPCRel) const {<br>
-      return TargetObjectWriter->GetRelocType(Target, Fixup, IsPCRel);<br>
+    unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                          const MCFixup &Fixup, bool IsPCRel) const {<br>
+      return TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);<br>
     }<br>
<br>
     void align(unsigned Alignment);<br>
@@ -682,7 +682,7 @@ void ELFObjectWriter::recordRelocation(M<br>
     }<br>
   }<br>
<br>
-  unsigned Type = GetRelocType(Target, Fixup, IsPCRel);<br>
+  unsigned Type = getRelocType(Ctx, Target, Fixup, IsPCRel);<br>
   bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);<br>
   if (!RelocateWithSymbol && SymA && !SymA->isUndefined())<br>
     C += Layout.getSymbolOffset(*SymA);<br>
<br>
Modified: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -29,8 +29,8 @@ public:<br>
   ~AArch64ELFObjectWriter() override;<br>
<br>
 protected:<br>
-  unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                        bool IsPCRel) const override;<br>
+  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                        const MCFixup &Fixup, bool IsPCRel) const override;<br>
<br>
 private:<br>
 };<br>
@@ -43,9 +43,10 @@ AArch64ELFObjectWriter::AArch64ELFObject<br>
<br>
 AArch64ELFObjectWriter::~AArch64ELFObjectWriter() {}<br>
<br>
-unsigned AArch64ELFObjectWriter::GetRelocType(const MCValue &Target,<br>
-                                            const MCFixup &Fixup,<br>
-                                            bool IsPCRel) const {<br>
+unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,<br>
+                                              const MCValue &Target,<br>
+                                              const MCFixup &Fixup,<br>
+                                              bool IsPCRel) const {<br>
   AArch64MCExpr::VariantKind RefKind =<br>
       static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());<br>
   AArch64MCExpr::VariantKind SymLoc = AArch64MCExpr::getSymbolLoc(RefKind);<br>
<br>
Modified: llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -20,8 +20,8 @@ class AMDGPUELFObjectWriter : public MCE<br>
 public:<br>
   AMDGPUELFObjectWriter(bool Is64Bit);<br>
 protected:<br>
-  unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                        bool IsPCRel) const override {<br>
+  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                        const MCFixup &Fixup, bool IsPCRel) const override {<br>
     return Fixup.getKind();<br>
   }<br>
<br>
<br>
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -34,8 +34,8 @@ namespace {<br>
<br>
     ~ARMELFObjectWriter() override;<br>
<br>
-    unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                          bool IsPCRel) const override;<br>
+    unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                          const MCFixup &Fixup, bool IsPCRel) const override;<br>
<br>
     bool needsRelocateWithSymbol(const MCSymbol &Sym,<br>
                                  unsigned Type) const override;<br>
@@ -67,7 +67,7 @@ bool ARMELFObjectWriter::needsRelocateWi<br>
 // Need to examine the Fixup when determining whether to<br>
 // emit the relocation as an explicit symbol or as a section relative<br>
 // offset<br>
-unsigned ARMELFObjectWriter::GetRelocType(const MCValue &Target,<br>
+unsigned ARMELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,<br>
                                           const MCFixup &Fixup,<br>
                                           bool IsPCRel) const {<br>
   return GetRelocTypeInner(Target, Fixup, IsPCRel);<br>
<br>
Modified: llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -22,8 +22,8 @@ public:<br>
   ~BPFELFObjectWriter() override;<br>
<br>
 protected:<br>
-  unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                        bool IsPCRel) const override;<br>
+  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                        const MCFixup &Fixup, bool IsPCRel) const override;<br>
 };<br>
 }<br>
<br>
@@ -33,7 +33,7 @@ BPFELFObjectWriter::BPFELFObjectWriter(u<br>
<br>
 BPFELFObjectWriter::~BPFELFObjectWriter() {}<br>
<br>
-unsigned BPFELFObjectWriter::GetRelocType(const MCValue &Target,<br>
+unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,<br>
                                           const MCFixup &Fixup,<br>
                                           bool IsPCRel) const {<br>
   // determine the type of the relocation<br>
<br>
Modified: llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -28,8 +28,8 @@ private:<br>
 public:<br>
   HexagonELFObjectWriter(uint8_t OSABI, StringRef C);<br>
<br>
-  unsigned GetRelocType(MCValue const &Target, MCFixup const &Fixup,<br>
-                        bool IsPCRel) const override;<br>
+  unsigned getRelocType(MCContext &Ctx, MCValue const &Target,<br>
+                        MCFixup const &Fixup, bool IsPCRel) const override;<br>
 };<br>
 }<br>
<br>
@@ -38,7 +38,8 @@ HexagonELFObjectWriter::HexagonELFObject<br>
                               /*HasRelocationAddend*/ true),<br>
       CPU(C) {}<br>
<br>
-unsigned HexagonELFObjectWriter::GetRelocType(MCValue const & /*Target*/,<br>
+unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,<br>
+                                              MCValue const & /*Target*/,<br>
                                               MCFixup const &Fixup,<br>
                                               bool IsPCRel) const {<br>
   switch ((unsigned)Fixup.getKind()) {<br>
<br>
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -44,8 +44,8 @@ struct MipsRelocationEntry {<br>
<br>
     ~MipsELFObjectWriter() override;<br>
<br>
-    unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                          bool IsPCRel) const override;<br>
+    unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                          const MCFixup &Fixup, bool IsPCRel) const override;<br>
     bool needsRelocateWithSymbol(const MCSymbol &Sym,<br>
                                  unsigned Type) const override;<br>
     virtual void sortRelocs(const MCAssembler &Asm,<br>
@@ -61,7 +61,8 @@ MipsELFObjectWriter::MipsELFObjectWriter<br>
<br>
 MipsELFObjectWriter::~MipsELFObjectWriter() {}<br>
<br>
-unsigned MipsELFObjectWriter::GetRelocType(const MCValue &Target,<br>
+unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,<br>
+                                           const MCValue &Target,<br>
                                            const MCFixup &Fixup,<br>
                                            bool IsPCRel) const {<br>
   // Determine the type of the relocation.<br>
<br>
Modified: llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -25,8 +25,8 @@ namespace {<br>
     PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI);<br>
<br>
   protected:<br>
-    unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                          bool IsPCRel) const override;<br>
+    unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                          const MCFixup &Fixup, bool IsPCRel) const override;<br>
<br>
     bool needsRelocateWithSymbol(const MCSymbol &Sym,<br>
                                  unsigned Type) const override;<br>
@@ -66,7 +66,7 @@ static MCSymbolRefExpr::VariantKind getA<br>
   llvm_unreachable("unknown PPCMCExpr kind");<br>
 }<br>
<br>
-unsigned PPCELFObjectWriter::GetRelocType(const MCValue &Target,<br>
+unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,<br>
                                           const MCFixup &Fixup,<br>
                                           bool IsPCRel) const {<br>
   MCSymbolRefExpr::VariantKind Modifier = getAccessVariant(Target, Fixup);<br>
<br>
Modified: llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -29,8 +29,8 @@ namespace {<br>
     ~SparcELFObjectWriter() override {}<br>
<br>
   protected:<br>
-    unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                          bool IsPCRel) const override;<br>
+    unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                          const MCFixup &Fixup, bool IsPCRel) const override;<br>
<br>
     bool needsRelocateWithSymbol(const MCSymbol &Sym,<br>
                                  unsigned Type) const override;<br>
@@ -38,7 +38,8 @@ namespace {<br>
   };<br>
 }<br>
<br>
-unsigned SparcELFObjectWriter::GetRelocType(const MCValue &Target,<br>
+unsigned SparcELFObjectWriter::getRelocType(MCContext &Ctx,<br>
+                                            const MCValue &Target,<br>
                                             const MCFixup &Fixup,<br>
                                             bool IsPCRel) const {<br>
<br>
<br>
Modified: llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -24,8 +24,8 @@ public:<br>
<br>
 protected:<br>
   // Override MCELFObjectTargetWriter.<br>
-  unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                        bool IsPCRel) const override;<br>
+  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                        const MCFixup &Fixup, bool IsPCRel) const override;<br>
 };<br>
 } // end anonymous namespace<br>
<br>
@@ -106,7 +106,8 @@ static unsigned getPLTReloc(unsigned Kin<br>
   llvm_unreachable("Unsupported absolute address");<br>
 }<br>
<br>
-unsigned SystemZObjectWriter::GetRelocType(const MCValue &Target,<br>
+unsigned SystemZObjectWriter::getRelocType(MCContext &Ctx,<br>
+                                           const MCValue &Target,<br>
                                            const MCFixup &Fixup,<br>
                                            bool IsPCRel) const {<br>
   MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();<br>
<br>
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp?rev=257697&r1=257696&r2=257697&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp Wed Jan 13 16:56:57 2016<br>
@@ -9,6 +9,7 @@<br>
<br>
 #include "MCTargetDesc/X86FixupKinds.h"<br>
 #include "MCTargetDesc/X86MCTargetDesc.h"<br>
+#include "llvm/MC/MCContext.h"<br>
 #include "llvm/MC/MCELFObjectWriter.h"<br>
 #include "llvm/MC/MCExpr.h"<br>
 #include "llvm/MC/MCValue.h"<br>
@@ -25,8 +26,8 @@ namespace {<br>
     ~X86ELFObjectWriter() override;<br>
<br>
   protected:<br>
-    unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,<br>
-                          bool IsPCRel) const override;<br>
+    unsigned getRelocType(MCContext &Ctx, const MCValue &Target,<br>
+                          const MCFixup &Fixup, bool IsPCRel) const override;<br>
   };<br>
 }<br>
<br>
@@ -77,7 +78,14 @@ static X86_64RelType getType64(unsigned<br>
   }<br>
 }<br>
<br>
-static unsigned getRelocType64(MCSymbolRefExpr::VariantKind Modifier,<br>
+static void checkIs32(MCContext &Ctx, SMLoc Loc, X86_64RelType Type) {<br>
+  if (Type != RT64_32)<br>
+    Ctx.reportError(Loc,<br>
+                    "32 bit reloc applied to a field with a different size");<br>
+}<br>
+<br>
+static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,<br>
+                               MCSymbolRefExpr::VariantKind Modifier,<br>
                                X86_64RelType Type, bool IsPCRel) {<br>
   switch (Modifier) {<br>
   default:<br>
@@ -147,19 +155,19 @@ static unsigned getRelocType64(MCSymbolR<br>
       llvm_unreachable("Unimplemented");<br>
     }<br>
   case MCSymbolRefExpr::VK_TLSGD:<br>
-    assert(Type == RT64_32);<br>
+    checkIs32(Ctx, Loc, Type);<br>
     return ELF::R_X86_64_TLSGD;<br>
   case MCSymbolRefExpr::VK_GOTTPOFF:<br>
-    assert(Type == RT64_32);<br>
+    checkIs32(Ctx, Loc, Type);<br>
     return ELF::R_X86_64_GOTTPOFF;<br>
   case MCSymbolRefExpr::VK_TLSLD:<br>
-    assert(Type == RT64_32);<br>
+    checkIs32(Ctx, Loc, Type);<br>
     return ELF::R_X86_64_TLSLD;<br>
   case MCSymbolRefExpr::VK_PLT:<br>
-    assert(Type == RT64_32);<br>
+    checkIs32(Ctx, Loc, Type);<br>
     return ELF::R_X86_64_PLT32;<br>
   case MCSymbolRefExpr::VK_GOTPCREL:<br>
-    assert(Type == RT64_32);<br>
+    checkIs32(Ctx, Loc, Type);<br>
     return ELF::R_X86_64_GOTPCREL;<br>
   }<br>
 }<br>
@@ -240,13 +248,13 @@ static unsigned getRelocType32(MCSymbolR<br>
   }<br>
 }<br>
<br>
-unsigned X86ELFObjectWriter::GetRelocType(const MCValue &Target,<br>
+unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,<br>
                                           const MCFixup &Fixup,<br>
                                           bool IsPCRel) const {<br>
   MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();<br>
   X86_64RelType Type = getType64(Fixup.getKind(), Modifier, IsPCRel);<br>
   if (getEMachine() == ELF::EM_X86_64)<br>
-    return getRelocType64(Modifier, Type, IsPCRel);<br>
+    return getRelocType64(Ctx, Fixup.getLoc(), Modifier, Type, IsPCRel);<br>
<br>
   assert((getEMachine() == ELF::EM_386 || getEMachine() == ELF::EM_IAMCU) &&<br>
          "Unsupported ELF machine type.");<br>
<br>
Added: llvm/trunk/test/MC/X86/error-reloc.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/error-reloc.s?rev=257697&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/error-reloc.s?rev=257697&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/X86/error-reloc.s (added)<br>
+++ llvm/trunk/test/MC/X86/error-reloc.s Wed Jan 13 16:56:57 2016<br>
@@ -0,0 +1,21 @@<br>
+// RUN: not llvm-mc %s -o %t.o -filetype=obj 2>&1 | FileCheck %s<br>
+<br>
+        .quad foo@gotpcrel<br>
+// CHECK:      32 bit reloc applied to a field with a different size<br>
+// CHECK-NEXT: .quad foo@gotpcrel<br>
+<br>
+        .quad foo@plt<br>
+// CHECK:      32 bit reloc applied to a field with a different size<br>
+// CHECK-NEXT: .quad foo@plt<br>
+<br>
+        .quad foo@tlsld<br>
+// CHECK:      32 bit reloc applied to a field with a different size<br>
+// CHECK-NEXT: .quad foo@tlsld<br>
+<br>
+        .quad foo@gottpoff<br>
+// CHECK:      32 bit reloc applied to a field with a different size<br>
+// CHECK-NEXT: .quad foo@gottpoff<br>
+<br>
+        .quad foo@tlsgd<br>
+// CHECK:      32 bit reloc applied to a field with a different size<br>
+// CHECK-NEXT: .quad foo@tlsgd<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>