LLVM  3.7.0
X86WinCOFFObjectWriter.cpp
Go to the documentation of this file.
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 
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/MC/MCValue.h"
15 #include "llvm/Support/COFF.h"
17 
18 using namespace llvm;
19 
20 namespace llvm {
21  class MCObjectWriter;
22 }
23 
24 namespace {
25  class X86WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
26  public:
27  X86WinCOFFObjectWriter(bool Is64Bit);
28  ~X86WinCOFFObjectWriter() override;
29 
30  unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
31  bool IsCrossSection,
32  const MCAsmBackend &MAB) const override;
33  };
34 }
35 
36 X86WinCOFFObjectWriter::X86WinCOFFObjectWriter(bool Is64Bit)
38  : COFF::IMAGE_FILE_MACHINE_I386) {}
39 
40 X86WinCOFFObjectWriter::~X86WinCOFFObjectWriter() {}
41 
43  const MCFixup &Fixup,
44  bool IsCrossSection,
45  const MCAsmBackend &MAB) const {
46  unsigned FixupKind = IsCrossSection ? FK_PCRel_4 : Fixup.getKind();
47 
48  MCSymbolRefExpr::VariantKind Modifier = Target.isAbsolute() ?
49  MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
50 
51  if (getMachine() == COFF::IMAGE_FILE_MACHINE_AMD64) {
52  switch (FixupKind) {
53  case FK_PCRel_4:
57  case FK_Data_4:
59  if (Modifier == MCSymbolRefExpr::VK_COFF_IMGREL32)
62  case FK_Data_8:
64  case FK_SecRel_2:
66  case FK_SecRel_4:
68  default:
69  llvm_unreachable("unsupported relocation type");
70  }
71  } else if (getMachine() == COFF::IMAGE_FILE_MACHINE_I386) {
72  switch (FixupKind) {
73  case FK_PCRel_4:
77  case FK_Data_4:
79  if (Modifier == MCSymbolRefExpr::VK_COFF_IMGREL32)
82  case FK_SecRel_2:
84  case FK_SecRel_4:
86  default:
87  llvm_unreachable("unsupported relocation type");
88  }
89  } else
90  llvm_unreachable("Unsupported COFF machine type.");
91 }
92 
94  bool Is64Bit) {
95  MCWinCOFFObjectTargetWriter *MOTW = new X86WinCOFFObjectWriter(Is64Bit);
96  return createWinCOFFObjectWriter(MOTW, OS);
97 }
This represents an "assembler immediate".
Definition: MCValue.h:44
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:62
MCObjectWriter * createX86WinCOFFObjectWriter(raw_pwrite_stream &OS, bool Is64Bit)
Construct an X86 Win COFF object writer.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
static unsigned getRelocType(const MCValue &Target, const MCFixupKind FixupKind, const bool IsPCRel)
Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
A four-byte section relative fixup.
Definition: MCFixup.h:38
A four-byte fixup.
Definition: MCFixup.h:26
A two-byte section relative fixup.
Definition: MCFixup.h:37
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:56
MCFixupKind getKind() const
Definition: MCFixup.h:89
PowerPC TLS Dynamic Call Fixup
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:51
A four-byte pc relative fixup.
Definition: MCFixup.h:30
Target - Wrapper for Target specific information.
A eight-byte fixup.
Definition: MCFixup.h:27
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321
VariantKind getKind() const
Definition: MCExpr.h:330
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
MCObjectWriter * createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, raw_pwrite_stream &OS)
Construct a new Win COFF writer instance.