Enable DebugInfo support for COFF object files.
[oota-llvm.git] / lib / Target / X86 / X86AsmBackend.cpp
index 5e7ce0bd1fc29fe26ed63f6620c87d0df4451731..6a0b059ca5a8fb8091c440889588057f3088bb8f 100644 (file)
@@ -16,7 +16,6 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCFixupKindInfo.h"
 #include "llvm/MC/MCMachObjectWriter.h"
-#include "llvm/MC/MCObjectFormat.h"
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSectionCOFF.h"
 #include "llvm/MC/MCSectionELF.h"
@@ -41,19 +40,14 @@ static unsigned getFixupKindLog2Size(unsigned Kind) {
   case X86::reloc_riprel_4byte_movq_load:
   case X86::reloc_signed_4byte:
   case X86::reloc_global_offset_table:
+  case X86::reloc_coff_secrel32:
   case FK_Data_4: return 2;
+  case FK_PCRel_8:
   case FK_Data_8: return 3;
   }
 }
 
 namespace {
-class X86MachObjectWriter : public MCMachObjectTargetWriter {
-public:
-  X86MachObjectWriter(bool Is64Bit, uint32_t CPUType,
-                      uint32_t CPUSubtype)
-    : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype,
-                               /*UseAggressiveSymbolFolding=*/Is64Bit) {}
-};
 
 class X86ELFObjectWriter : public MCELFObjectTargetWriter {
 public:
@@ -76,7 +70,8 @@ public:
       { "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
       { "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel},
       { "reloc_signed_4byte", 0, 4 * 8, 0},
-      { "reloc_global_offset_table", 0, 4 * 8, 0}
+      { "reloc_global_offset_table", 0, 4 * 8, 0},
+      { "reloc_coff_secrel32", 0, 4 * 8, 0}
     };
 
     if (Kind < FirstTargetFixupKind)
@@ -295,8 +290,6 @@ bool X86AsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
 
 namespace {
 class ELFX86AsmBackend : public X86AsmBackend {
-  MCELFObjectFormat Format;
-
 public:
   Triple::OSType OSType;
   ELFX86AsmBackend(const Target &T, Triple::OSType _OSType)
@@ -304,13 +297,9 @@ public:
     HasReliableSymbolDifference = true;
   }
 
-  virtual const MCObjectFormat &getObjectFormat() const {
-    return Format;
-  }
-
   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
     const MCSectionELF &ES = static_cast<const MCSectionELF&>(Section);
-    return ES.getFlags() & MCSectionELF::SHF_MERGE;
+    return ES.getFlags() & ELF::SHF_MERGE;
   }
 };
 
@@ -340,7 +329,6 @@ public:
 
 class WindowsX86AsmBackend : public X86AsmBackend {
   bool Is64Bit;
-  MCCOFFObjectFormat Format;
 
 public:
   WindowsX86AsmBackend(const Target &T, bool is64Bit)
@@ -348,25 +336,15 @@ public:
     , Is64Bit(is64Bit) {
   }
 
-  virtual const MCObjectFormat &getObjectFormat() const {
-    return Format;
-  }
-
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
     return createWinCOFFObjectWriter(OS, Is64Bit);
   }
 };
 
 class DarwinX86AsmBackend : public X86AsmBackend {
-  MCMachOObjectFormat Format;
-
 public:
   DarwinX86AsmBackend(const Target &T)
     : X86AsmBackend(T) { }
-
-  virtual const MCObjectFormat &getObjectFormat() const {
-    return Format;
-  }
 };
 
 class DarwinX86_32AsmBackend : public DarwinX86AsmBackend {
@@ -375,11 +353,9 @@ public:
     : DarwinX86AsmBackend(T) {}
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return createMachObjectWriter(new X86MachObjectWriter(
-                                    /*Is64Bit=*/false,
-                                    object::mach::CTM_i386,
-                                    object::mach::CSX86_ALL),
-                                  OS, /*IsLittleEndian=*/true);
+    return createX86MachObjectWriter(OS, /*Is64Bit=*/false,
+                                     object::mach::CTM_i386,
+                                     object::mach::CSX86_ALL);
   }
 };
 
@@ -391,11 +367,9 @@ public:
   }
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return createMachObjectWriter(new X86MachObjectWriter(
-                                    /*Is64Bit=*/true,
-                                    object::mach::CTM_x86_64,
-                                    object::mach::CSX86_ALL),
-                                  OS, /*IsLittleEndian=*/true);
+    return createX86MachObjectWriter(OS, /*Is64Bit=*/true,
+                                     object::mach::CTM_x86_64,
+                                     object::mach::CSX86_ALL);
   }
 
   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
@@ -442,7 +416,10 @@ TargetAsmBackend *llvm::createX86_32AsmBackend(const Target &T,
   case Triple::MinGW32:
   case Triple::Cygwin:
   case Triple::Win32:
-    return new WindowsX86AsmBackend(T, false);
+    if (Triple(TT).getEnvironment() == Triple::MachO)
+      return new DarwinX86_32AsmBackend(T);
+    else
+      return new WindowsX86AsmBackend(T, false);
   default:
     return new ELFX86_32AsmBackend(T, Triple(TT).getOS());
   }
@@ -453,10 +430,13 @@ TargetAsmBackend *llvm::createX86_64AsmBackend(const Target &T,
   switch (Triple(TT).getOS()) {
   case Triple::Darwin:
     return new DarwinX86_64AsmBackend(T);
-  case Triple::MinGW64:
+  case Triple::MinGW32:
   case Triple::Cygwin:
   case Triple::Win32:
-    return new WindowsX86AsmBackend(T, true);
+    if (Triple(TT).getEnvironment() == Triple::MachO)
+      return new DarwinX86_64AsmBackend(T);
+    else
+      return new WindowsX86AsmBackend(T, true);
   default:
     return new ELFX86_64AsmBackend(T, Triple(TT).getOS());
   }