X86WinCOFFObjectWriter.cpp revision 234285
1//===-- X86WinCOFFObjectWriter.cpp - X86 Win COFF Writer ------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#include "MCTargetDesc/X86FixupKinds.h" 11#include "MCTargetDesc/X86MCTargetDesc.h" 12#include "llvm/MC/MCWinCOFFObjectWriter.h" 13#include "llvm/Support/COFF.h" 14#include "llvm/Support/ErrorHandling.h" 15 16using namespace llvm; 17 18namespace llvm { 19 class MCObjectWriter; 20} 21 22namespace { 23 class X86WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter { 24 const bool Is64Bit; 25 26 public: 27 X86WinCOFFObjectWriter(bool Is64Bit_); 28 ~X86WinCOFFObjectWriter(); 29 30 virtual unsigned getRelocType(unsigned FixupKind) const; 31 }; 32} 33 34X86WinCOFFObjectWriter::X86WinCOFFObjectWriter(bool Is64Bit_) 35 : MCWinCOFFObjectTargetWriter(Is64Bit_ ? COFF::IMAGE_FILE_MACHINE_AMD64 : 36 COFF::IMAGE_FILE_MACHINE_I386), 37 Is64Bit(Is64Bit_) {} 38 39X86WinCOFFObjectWriter::~X86WinCOFFObjectWriter() {} 40 41unsigned X86WinCOFFObjectWriter::getRelocType(unsigned FixupKind) const { 42 switch (FixupKind) { 43 case FK_PCRel_4: 44 case X86::reloc_riprel_4byte: 45 case X86::reloc_riprel_4byte_movq_load: 46 return Is64Bit ? COFF::IMAGE_REL_AMD64_REL32 : COFF::IMAGE_REL_I386_REL32; 47 case FK_Data_4: 48 case X86::reloc_signed_4byte: 49 return Is64Bit ? COFF::IMAGE_REL_AMD64_ADDR32 : COFF::IMAGE_REL_I386_DIR32; 50 case FK_Data_8: 51 if (Is64Bit) 52 return COFF::IMAGE_REL_AMD64_ADDR64; 53 llvm_unreachable("unsupported relocation type"); 54 case FK_SecRel_4: 55 return Is64Bit ? COFF::IMAGE_REL_AMD64_SECREL : COFF::IMAGE_REL_I386_SECREL; 56 default: 57 llvm_unreachable("unsupported relocation type"); 58 } 59} 60 61MCObjectWriter *llvm::createX86WinCOFFObjectWriter(raw_ostream &OS, 62 bool Is64Bit) { 63 MCWinCOFFObjectTargetWriter *MOTW = new X86WinCOFFObjectWriter(Is64Bit); 64 return createWinCOFFObjectWriter(MOTW, OS); 65} 66