X86WinCOFFObjectWriter.cpp revision 234285
1234285Sdim//===-- X86WinCOFFObjectWriter.cpp - X86 Win COFF Writer ------------------===// 2234285Sdim// 3234285Sdim// The LLVM Compiler Infrastructure 4234285Sdim// 5234285Sdim// This file is distributed under the University of Illinois Open Source 6234285Sdim// License. See LICENSE.TXT for details. 7234285Sdim// 8234285Sdim//===----------------------------------------------------------------------===// 9234285Sdim 10234285Sdim#include "MCTargetDesc/X86FixupKinds.h" 11234285Sdim#include "MCTargetDesc/X86MCTargetDesc.h" 12234285Sdim#include "llvm/MC/MCWinCOFFObjectWriter.h" 13234285Sdim#include "llvm/Support/COFF.h" 14234285Sdim#include "llvm/Support/ErrorHandling.h" 15234285Sdim 16234285Sdimusing namespace llvm; 17234285Sdim 18234285Sdimnamespace llvm { 19234285Sdim class MCObjectWriter; 20234285Sdim} 21234285Sdim 22234285Sdimnamespace { 23234285Sdim class X86WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter { 24234285Sdim const bool Is64Bit; 25234285Sdim 26234285Sdim public: 27234285Sdim X86WinCOFFObjectWriter(bool Is64Bit_); 28234285Sdim ~X86WinCOFFObjectWriter(); 29234285Sdim 30234285Sdim virtual unsigned getRelocType(unsigned FixupKind) const; 31234285Sdim }; 32234285Sdim} 33234285Sdim 34234285SdimX86WinCOFFObjectWriter::X86WinCOFFObjectWriter(bool Is64Bit_) 35234285Sdim : MCWinCOFFObjectTargetWriter(Is64Bit_ ? COFF::IMAGE_FILE_MACHINE_AMD64 : 36234285Sdim COFF::IMAGE_FILE_MACHINE_I386), 37234285Sdim Is64Bit(Is64Bit_) {} 38234285Sdim 39234285SdimX86WinCOFFObjectWriter::~X86WinCOFFObjectWriter() {} 40234285Sdim 41234285Sdimunsigned X86WinCOFFObjectWriter::getRelocType(unsigned FixupKind) const { 42234285Sdim switch (FixupKind) { 43234285Sdim case FK_PCRel_4: 44234285Sdim case X86::reloc_riprel_4byte: 45234285Sdim case X86::reloc_riprel_4byte_movq_load: 46234285Sdim return Is64Bit ? COFF::IMAGE_REL_AMD64_REL32 : COFF::IMAGE_REL_I386_REL32; 47234285Sdim case FK_Data_4: 48234285Sdim case X86::reloc_signed_4byte: 49234285Sdim return Is64Bit ? COFF::IMAGE_REL_AMD64_ADDR32 : COFF::IMAGE_REL_I386_DIR32; 50234285Sdim case FK_Data_8: 51234285Sdim if (Is64Bit) 52234285Sdim return COFF::IMAGE_REL_AMD64_ADDR64; 53234285Sdim llvm_unreachable("unsupported relocation type"); 54234285Sdim case FK_SecRel_4: 55234285Sdim return Is64Bit ? COFF::IMAGE_REL_AMD64_SECREL : COFF::IMAGE_REL_I386_SECREL; 56234285Sdim default: 57234285Sdim llvm_unreachable("unsupported relocation type"); 58234285Sdim } 59234285Sdim} 60234285Sdim 61234285SdimMCObjectWriter *llvm::createX86WinCOFFObjectWriter(raw_ostream &OS, 62234285Sdim bool Is64Bit) { 63234285Sdim MCWinCOFFObjectTargetWriter *MOTW = new X86WinCOFFObjectWriter(Is64Bit); 64234285Sdim return createWinCOFFObjectWriter(MOTW, OS); 65234285Sdim} 66